hiyouga/LlamaFactory · error · ValueError

Currently merge and export model function is only supported

Error message

Currently merge and export model function is only supported for lora.

What it means

The v1 merge-and-export path only implements adapter merging for LoRA: it parses the peft_config with LoraParams and calls PEFT LoRA merge APIs. Setting peft_config.name to anything else (freeze, vera, etc.) is rejected because no merge implementation exists for those methods. Freeze tuning has no separate adapter weights to merge anyway.

Source

Thrown at src/llamafactory/v1/plugins/model_plugins/peft.py:308

    # Count trainable params for verification
    trainable_params = sum(p.numel() for p in model.parameters() if p.requires_grad)
    all_params = sum(p.numel() for p in model.parameters())
    logger.info_rank0(
        f"trainable params: {trainable_params} || all params: {all_params} || trainable%: {100 * trainable_params / all_params:.4f}"
    )

    return model


def merge_and_export_model(args: InputArgument = None):
    model_args, _, _, _ = get_args(args)

    raw_config = model_args.peft_config
    if raw_config is None:
        raise ValueError("Please specify peft_config to merge and export model.")
    if raw_config.name != "lora":
        raise ValueError("Currently merge and export model function is only supported for lora.")

    export_peft_config = PeftPlugin.parse_params(raw_config, LoraParams)
    if export_peft_config.export_dir is None:
        raise ValueError("Please specify export_dir.")
    if export_peft_config.adapter_name_or_path is None:
        raise ValueError("Please set adapter_name_or_path to merge adapters into base model.")

    logger.info_rank0("Loading model for export...")
    model_engine = ModelEngine(model_args, is_train=False)
    model = model_engine.model
    tokenizer = model_engine.processor

    if export_peft_config.infer_dtype == "auto":
        if model.config.torch_dtype == torch.float32 and torch.cuda.is_bf16_supported():
            model = model.to(torch.bfloat16)
            logger.info_rank0("Converted model to bfloat16.")
    else:
        target_dtype = getattr(torch, export_peft_config.infer_dtype)

View on GitHub (pinned to f28afaf635)

Solutions

  1. Set peft_config.name to lora for the export run
  2. If you trained with freeze, no merge is needed: freeze-trained weights are already in the full model, save/export the checkpoint directly
  3. Check spelling/case of the name field (must be exactly 'lora')

Example fix

# before
peft_config:
  name: freeze

# after
peft_config:
  name: lora
Defensive patterns

Strategy: validation

Validate before calling

name = raw.get("peft_config", {}).get("name")
assert name == "lora", f"merge_and_export only supports lora, got {name!r}"

Prevention

When it happens

Trigger: peft_config present with name != 'lora' (e.g. 'freeze', 'llamaplus') while running merge_and_export_model / the export command.

Common situations: User trains with freeze or another method and then tries to export a merged model from the same YAML; or the name field was left from a previous experiment.

Related errors


AI-assisted analysis of hiyouga/LlamaFactory@f28afaf635 (2026-08-14). Data as JSON: /api/errors/49b223f8a1a3efc2. Report an issue: GitHub.