save-load-merge
Save, load, inspect, merge, hotswap, mix, and convert PEFT adapters and checkpoints for local or Hub workflows.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- save-load-merge
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Save, load, inspect, merge, hotswap, mix, and convert PEFT adapters and checkpoints for local or Hub workflows.
- disable-model-invocation
- true
02 资源文件 4
- 参考文档references/checkpoints.md5.5 KB
- 参考文档references/merge-and-conversion.md5.4 KB
- 参考文档references/troubleshooting.md5.1 KB
- 脚本scripts/inspect_adapter_checkpoint.py7.9 KB
03 SKILL.md 正文
Save, Load, and Merge
Use this sub-skill when the task is about PEFT checkpoint files, save_pretrained, from_pretrained, AutoPeftModel*, adapter state dicts, Hub loading, merge_and_unload, PeftMixedModel, hotswapping adapters, weighted adapter merging, conversion helpers, or deployment packaging.
Route Here For
- Inspecting or repairing adapter folders containing
adapter_config.jsonplusadapter_model.safetensorsoradapter_model.bin. - Loading adapters with
PeftModel.from_pretrained,PeftConfig.from_pretrained,AutoPeftModel*, orload_adapter. - Saving adapter-only checkpoints with
save_pretrained, including non-default adapter subdirectories and embedding-layer save decisions. - Loading multiple adapters, activating one or several adapters, using
PeftMixedModel, or hotswapping LoRA weights in place. - Merging adapters into base weights with
merge_and_unloador creating weighted LoRA/(IA)³ adapters withadd_weighted_adapter. - Converting compatible non-LoRA adapters or Transformers-loaded PEFT weights into LoRA-style artifacts.
- Diagnosing bad loaded outputs, missing base models, random new-token embeddings, version mismatches, slow loads, and merge limitations.
Route Elsewhere
- Initial adapter wrapping with
get_peft_model,PeftConfig, target module selection, and adapter lifecycle basics: use../adapter-core/SKILL.md. - LoRA variant choices, quantized-base setup, DoRA, rsLoRA, QLoRA, LoftQ, QALoRA, or trainable-token configuration: use
../lora-and-quantization/SKILL.md. - Method-specific limits for prompt tuning, IA³, OFT/BOFT, VeRA, LoHa/LoKr, Poly, FourierFT, or other tuners: use the relevant method sub-skill.
- Trainer, Accelerate, distributed, FSDP, DeepSpeed, or training launch mechanics: use
../training-and-integrations/SKILL.md.
Start Fast
- Run
python scripts/inspect_adapter_checkpoint.py <adapter-dir>from this sub-skill directory to check local adapter files without network access. - Read
references/checkpoints.mdfor checkpoint layout, save/load class selection, state dict helpers, Hub/local loading, and embedding save rules. - Read
references/merge-and-conversion.mdformerge_and_unload, weighted adapter merging, mixed adapters, hotswap, and conversion utilities. - Read
references/troubleshooting.mdwhen loaded results look wrong or errors mention base models, vocab/embeddings, unexpected config keys, slow adapter load, active adapters, or unsupported merges.
Core Save/Load Pattern
from peft import PeftConfig, PeftModel
from transformers import AutoModelForCausalLM
adapter_id = "org-or-path/my-adapter"
config = PeftConfig.from_pretrained(adapter_id)
base_model = AutoModelForCausalLM.from_pretrained(config.base_model_name_or_path)
model = PeftModel.from_pretrained(base_model, adapter_id)
Use AutoPeftModelForCausalLM.from_pretrained(adapter_id) when the adapter config contains enough base-model and task information and you want PEFT to infer the model class. Use the explicit PeftConfig + Transformers base model pattern when you need full control over dtype, quantization, device_map, local files, revisions, or base-model class.
Checkpoint Rules of Thumb
- PEFT adapter checkpoints are adapter-only by default; they do not contain the full base model.
- A loadable adapter directory needs
adapter_config.jsonand eitheradapter_model.safetensorsoradapter_model.bin. adapter_config.jsonshould identifypeft_type;task_typeandbase_model_name_or_pathstrongly improve automatic loading and handoff quality.adapter_model.safetensorsis preferred over.bin; both carry the adapterstate_dict.- Non-default adapters are saved in a subdirectory named after the adapter, while the adapter name is stripped from saved state-dict keys.
- If training added vocabulary tokens or trained task heads, ensure embeddings or heads were saved with
save_embedding_layers=True,modules_to_save, or method-specific trainable-token settings.
Merge and Deployment Decision Pattern
- Keep adapter checkpoints for continued PEFT operations: loading multiple adapters, disabling adapters, switching adapters, hotswapping, or sharing compact files.
- Use
merged_model = model.merge_and_unload()when deployment needs a plain Transformers model and the method/settings support merging. - Do not expect to unmerge after saving a merged full model; merging discards PEFT wrapper functionality in the returned model.
- Use
model.add_weighted_adapter(...)to create a new adapter from compatible loaded adapters before selecting it withset_adapter. - Use
PeftMixedModelonly for inference-time composition of compatible adapter types; mixed adapter models are not a portable saved mixed checkpoint. - Use hotswap for replacing compatible LoRA weights in place, especially to avoid recompilation after
torch.compile.
Bundled Materials
references/checkpoints.md: concrete file layout, save/load workflows, state dict helpers, Hub/local loading, AutoPeftModel choices, and embedding persistence.references/merge-and-conversion.md: merge/unload, weighted merges, mixed adapters, hotswap constraints, and conversion helpers.references/troubleshooting.md: focused diagnosis for bad outputs, missing bases, random embeddings, version drift, slow loading, adapter activation, and merge failures.scripts/inspect_adapter_checkpoint.py: no-network local adapter directory inspector with class hints and tiny fixture generation.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).