cli.utils.lora_merge
cli.utils.lora_merge
Functions
| Name | Description |
|---|---|
| adapter_has_trainable_token_deltas | Return whether a PEFT adapter carries selectively trainable token rows. |
| copy_non_model_files | Copy all non-model files to the output directory. |
| find_lora_weights | Find corresponding LoRA A and B weights for a given key. |
| get_model_shards | Find all model shards in the given path. |
| merge_lora_sharded_efficient | Memory-efficient LoRA merging that processes shards individually |
adapter_has_trainable_token_deltas
cli.utils.lora_merge.adapter_has_trainable_token_deltas(lora_adapter_path)Return whether a PEFT adapter carries selectively trainable token rows.
copy_non_model_files
cli.utils.lora_merge.copy_non_model_files(input_path, output_path, model_shards)Copy all non-model files to the output directory.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| input_path | Path | Source directory | required |
| output_path | Path | Destination directory | required |
| model_shards | list[Path] | List of model shard files to skip | required |
find_lora_weights
cli.utils.lora_merge.find_lora_weights(lora_state, key, weight_renamings=None)Find corresponding LoRA A and B weights for a given key.
Also tries keys after applying weight renamings (from transformers v5 conversion mappings) in case the checkpoint key names differ from the runtime model key names used by the LoRA adapter.
get_model_shards
cli.utils.lora_merge.get_model_shards(model_path)Find all model shards in the given path.
merge_lora_sharded_efficient
cli.utils.lora_merge.merge_lora_sharded_efficient(
base_model_path,
lora_adapter_path,
output_path,
device='cpu',
safe_tensors=True,
simulate_nf4=False,
simulate_nf4_experts=False,
nf4_blocksize=None,
nf4_double_quant=True,
nf4_backend='bitsandbytes',
nf4_skips=None,
nf4_dtype=None,
staged_nf4=False,
trust_remote_code=False,
dequant=False,
override_quantizer=False,
revision=None,
)Memory-efficient LoRA merging that processes shards individually without loading the full model into memory.
if True, dequantize every quantized weight and write a bf16 checkpoint (strips
quantization_config). Default False = FORMAT-PRESERVING: LoRA-targeted quantized weights are dequantized, the delta folded, then re-quantized back to the SAME format (fp8 stays fp8, nvfp4 stays nvfp4), so a large quantized base does not double in size.
override_quantizer: proceed despite a quantizer-identity mismatch on a merge-aware
adapter (encoder version drift); see _resolve_nvfp4_scale_mode.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| nf4_backend | str | NF4 implementation used for the training base. | 'bitsandbytes' |
| nf4_skips | Optional[set[str]] | Resolved module exclusions from nf4_skip_modules. When provided, weights are selected the way the staged loader selected them (Linear weights and fused experts outside the exclusions); when None, the pre-existing _should_nf4_roundtrip heuristic is kept unchanged. |
None |
| nf4_dtype | Optional[torch.dtype] | Training weight dtype used before quantization. | None |
| staged_nf4 | bool | Training used CPU-staged NF4, which has no legacy merge fallback. | False |
| simulate_nf4 | bool | Apply NF4 roundtrip to eligible base weight tensors (for QLoRA) | False |
| simulate_nf4_experts | bool | Apply NF4 roundtrip only to MoE expert tensors (for quantize_moe_experts). Expert tensors are identified by having “expert” in the key name and ndim >= 3. | False |
| trust_remote_code | bool | Whether to trust remote code when loading model config for layer-type introspection. Defaults to False for safety. | False |