sgl-project/sglang · error · ValueError

adapter_config.json lora_alpha conflicts with safetensors me

Error message

adapter_config.json lora_alpha conflicts with safetensors metadata: {config_alpha} != {metadata_alpha}

What it means

load_peft_config cross-checks the LoRA alpha declared in adapter_config.json against the alpha found in the safetensors metadata. If both exist and differ, it raises this conflict error listing both values, refusing to guess which scale to apply (a wrong alpha silently ruins adapter quality).

Source

Thrown at python/sglang/multimodal_gen/runtime/pipelines_core/lora/peft_adapter.py:91

    return declared[0][1] if declared else None


def load_peft_config(weight_path: str) -> dict[str, Any]:
    path = Path(weight_path).with_name("adapter_config.json")
    config = {}
    if path.is_file():
        with path.open(encoding="utf-8") as file:
            config = json.load(file)
    if not isinstance(config, dict):
        raise ValueError("PEFT adapter_config.json must contain a JSON object")
    metadata_alpha = _load_safetensors_lora_alpha(weight_path)
    config_alpha = get_peft_lora_alpha(config)
    if (
        metadata_alpha is not None
        and config_alpha is not None
        and metadata_alpha != config_alpha
    ):
        raise ValueError(
            "adapter_config.json lora_alpha conflicts with safetensors metadata: "
            f"{config_alpha} != {metadata_alpha}"
        )
    if metadata_alpha is not None:
        config.setdefault("lora_alpha", metadata_alpha)
    return config


def get_peft_lora_alpha(config: Mapping[str, Any]) -> int | None:
    alpha = config.get("lora_alpha")
    if alpha is None:
        return None
    if (
        isinstance(alpha, bool)
        or not isinstance(alpha, (int, float))
        or alpha <= 0
        or isinstance(alpha, float)
        and not alpha.is_integer()

View on GitHub (pinned to 0132848349)

Solutions

  1. Decide the true alpha (usually from the training run) and make both sources agree
  2. Either edit lora_alpha in adapter_config.json to match metadata, or re-save the safetensors metadata to match the config
  3. If metadata is spurious, strip the alpha keys from safetensors metadata and keep only adapter_config.json

Example fix

# before: config lora_alpha=8, safetensors metadata lora_alpha='16'
# after: both set to 16 (edit adapter_config.json or re-save metadata)
Defensive patterns

Strategy: validation

Validate before calling

cfg_alpha = json.load(open(p/"adapter_config.json")).get("lora_alpha")
with safe_open(str(p/"adapter_model.safetensors"), framework="pt") as f:
    md_alpha = (f.metadata() or {}).get("lora_alpha")
if cfg_alpha is not None and md_alpha is not None:
    assert int(cfg_alpha) == int(float(md_alpha)), "alpha mismatch across config and metadata"

Prevention

When it happens

Trigger: An adapter directory where adapter_config.json says lora_alpha=8 but the .safetensors header metadata says 16 (or another alpha-like key disagrees), loaded via load_lora_adapter.

Common situations: Manually editing adapter_config.json to retune alpha without re-saving the safetensors metadata; converting adapters between kohya and PEFT formats where alpha conventions differ; merging adapters.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/6eace21f095de5d5. Report an issue: GitHub.