Adapter files#

The PEFT guide describes supported configurations and export rules.

Standard PEFT linear-LoRA files, with lazy tensor dependencies.

class AdapterExport(directory: 'Path', manifest: 'dict')[source]#
class AdapterModule(name: 'str', a: 'Tensor', b: 'Tensor', alpha: 'float', use_rslora: 'bool' = False)[source]#
class PeftAdapter(source: Path, config: dict, modules: tuple[AdapterModule, ...], source_sha256: dict[str, str])[source]#

CPU snapshot of a local adapter. Treat config and tensors as read-only.

compress_peft_adapter(source: str | Path, output: str | Path, keep: int | Mapping[str, int] | None = None, *, budget: int | None = None, device: str, output_dtype: OutputDtype = 'source', eigh_backend: EighBackend = 'auto', batch_size: int = 16) → AdapterExport[source]#

Load, compress through GPU FlashTSQR, and export a standard PEFT adapter.

Provide keep (a positive rank or exact module-name mapping), or budget (an integer total direction count). Budget mode reserves one rank per module then maximizes unscaled spectral energy. It measures spectra with FlashTSQR before a second compression pass; it does not optimize quality or bytes. device must explicitly select a CUDA/ROCm GPU. Same-shape, same-dtype modules with equal retained rank are batched up to batch_size to bound GPU memory.

load_peft_adapter(directory: str | Path) → PeftAdapter[source]#

Read a local, single-file safetensors PEFT adapter into CPU tensors.

Reject unsupported config/tensors rather than dropping weights. No model or PEFT installation is needed. Existing LoRAForge manifests are verified.

save_peft_adapter(adapter: PeftAdapter, output: str | Path, *, factors: Mapping[str, tuple[TypeAliasForwardRef('torch.Tensor'), TypeAliasForwardRef('torch.Tensor')]] | None = None, output_dtype: Literal['source', 'float32', 'float16', 'bfloat16'] = 'source') → AdapterExport[source]#

Export to a new directory, preserving each module’s effective scale.

Ordinary LoRA uses alpha/r; rsLoRA uses alpha/sqrt(r). Export preserves the source use_rslora flag and updates alpha for the retained rank accordingly.

Optional replacement factors must cover exactly all modules and use positive ranks no larger than the originals. This is a file export, not a compression claim; its manifest has no inferred execution backend. No source file changes.