slicktune.merge¶
PEFT multi-adapter loading and TIES / DARE-style merges.
Attributes¶
Classes¶
Reference to a PEFT adapter directory used in a multi-adapter load or merge. |
|
Artifacts written by |
Functions¶
|
Merge a single PEFT adapter into base weights for serving. |
|
Load a base model with one or more PEFT adapters attached. |
|
Combine PEFT adapters with a PEFT weighted-merge method and save the result. |
|
Parse a CLI-style adapter spec |
Package Contents¶
- class slicktune.merge.AdapterRef[source]¶
Reference to a PEFT adapter directory used in a multi-adapter load or merge.
- Parameters:
path (str or Path) – Directory containing
adapter_config.jsonand adapter weights.name (str) – PEFT adapter name used when loading / combining.
weight (float, optional) – Merge weight for this adapter, by default 1.0.
- path: str | pathlib.Path¶
- slicktune.merge.MergeMethod¶
- class slicktune.merge.MergeResult[source]¶
Artifacts written by
merge_adapters()orbake_adapter().- Parameters:
output_dir (Path) – Directory containing the merged adapter or baked full model.
adapter_name (str or None) – Name of the combined PEFT adapter when
bakedis False.baked (bool) – Whether adapters were merged into base weights via
merge_and_unload.
- output_dir: pathlib.Path¶
- slicktune.merge.bake_adapter(*, adapter_dir: str | pathlib.Path, output_dir: str | pathlib.Path, model_id: str | None = None) MergeResult[source]¶
Merge a single PEFT adapter into base weights for serving.
- Parameters:
adapter_dir (str or Path) – Directory from
Tuner.fit()containing adapter weights.output_dir (str or Path) – Destination for the full merged Hugging Face checkpoint.
model_id (str or None, optional) – Base model id. When omitted, read from
adapter_config.json.
- Returns:
MergeResult – Baked checkpoint metadata.
- Raises:
ValueError – If the adapter directory is invalid or
base_model_name_or_pathis missing whenmodel_idis not provided.FileNotFoundError – If
adapter_config.jsonis missing.
- slicktune.merge.load_multi_adapters(*, model_id: str, adapters: list[AdapterRef], active: str | None = None) tuple[Any, transformers.PreTrainedTokenizerBase][source]¶
Load a base model with one or more PEFT adapters attached.
- Parameters:
model_id (str) – Hugging Face id or local path of the base causal LM.
adapters (list of AdapterRef) – Adapters to attach (at least one). Names must be unique.
active (str or None, optional) – Adapter name to activate after load. Defaults to the first adapter.
- Returns:
tuple[Any, PreTrainedTokenizerBase] –
(peft_model, tokenizer).- Raises:
ValueError – If
adaptersis empty, names collide, or an adapter dir is invalid.
- slicktune.merge.merge_adapters(*, model_id: str, adapters: list[AdapterRef], output_dir: str | pathlib.Path, method: MergeMethod | str = 'ties', density: float | None = 0.5, bake: bool = False, combined_name: str = 'merged') MergeResult[source]¶
Combine PEFT adapters with a PEFT weighted-merge method and save the result.
- Parameters:
model_id (str) – Base model id used when the adapters were trained.
adapters (list of AdapterRef) – Adapters to combine (at least two for a true merge; one is allowed and simply selects / optionally bakes that adapter).
output_dir (str or Path) – Destination directory for the combined adapter or baked model.
method (str, optional) – PEFT
combination_type(e.g.ties,dare_ties,linear), by defaultties.density (float or None, optional) – Prune density in
[0, 1]for TIES / DARE / magnitude methods. Ignored for methods that do not use density. Default 0.5.bake (bool, optional) – If True, call
merge_and_unloadand save a full HF checkpoint.combined_name (str, optional) – Name of the new weighted adapter, by default
merged.
- Returns:
MergeResult – Paths and bake flag for the written artifacts.
- Raises:
ValueError – If inputs are invalid,
methodis unknown, or adapters have incompatible LoRA ranks formethod.
- slicktune.merge.parse_adapter_ref(spec: str) AdapterRef[source]¶
Parse a CLI-style adapter spec
pathorpath:weight.- Parameters:
spec (str) – Adapter directory path, optionally followed by
:weight.- Returns:
AdapterRef – Parsed reference with a name derived from the path stem.
- Raises:
ValueError – If
specis empty.