Skip to content

[BUG] Adapters attach to every quantized module instead of the adapter's targets: a standard partial PEFT LoRA (q_proj/v_proj) crashes the load, and LoRA weights for dense modules (e.g. lm_head) are silently dropped #4210

Closed

Description

@Qubitium

Severity: medium–high. q_proj/v_proj is PEFT's default Llama target, so most third-party LoRAs can't be loaded at all.
Version: 7.11.0 @ 9dad249

Summary

Which modules get an adapter is decided by which modules are quantized, not by the adapter's target_modules or keys:

  • one global qcfg.adapter is passed to every quantized module (utils/model.py:~648/670/885);
  • post_init always calls adapter.post_init (nn_modules/qlinear/__init__.py:410-420);
  • adapter/adapter.py:318-321 logs a warn(... not found) and then asserts lora_A is not None and lora_B is not None.

This has two effects:

  • (a) Every quantized module the adapter does not cover raises AssertionError. That includes lm_head when it is quantized but absent from the adapter.
  • (b) Adapter tensors for a module that stays a dense nn.Linear (lm_head, or a -: dynamic exclusion) are never applied, and nothing is logged.

Reproduce

import json, torch, tempfile, safetensors.torch as st
from gptqmodel import GPTQModel, BACKEND
from gptqmodel.adapter.adapter import Lora, AdapterCache
BASE = "sliuau/Llama-3.2-3B_4bits_128group_size"
A = "<local snapshot of sliuau/llama-3.2-3b_4bits_128group_size_eora_rank64_mmlu_c4>"
W = st.load_file(A + "/adapter_model.safetensors"); cfg = json.load(open(A + "/adapter_config.json"))

# (a) partial adapter: q_proj / v_proj only
d = tempfile.mkdtemp()
st.save_file({k: v for k, v in W.items() if ".q_proj." in k or ".v_proj." in k}, d + "/adapter_model.safetensors")
json.dump({**cfg, "target_modules": ["q_proj", "v_proj"]}, open(d + "/adapter_config.json", "w"))
GPTQModel.load(BASE, adapter=Lora(path=d, rank=64), backend=BACKEND.GPTQ_TORCH, device="cuda:0")
# WARN Lora weights not found for model.layers.0.self_attn.k_proj
# AssertionError: Adapter: `lora_A` and `lora_B` must both be present ... None and None

# (b) adapter that also targets lm_head (lm_head not quantized)
AdapterCache.reset(); e = tempfile.mkdtemp()
W["base_model.model.lm_head.lora_A.weight"] = torch.randn(64, 3072, dtype=torch.float16) * .05
W["base_model.model.lm_head.lora_B.weight"] = torch.randn(128256, 64, dtype=torch.float16) * .05
st.save_file(W, e + "/adapter_model.safetensors")
json.dump({**cfg, "target_modules": cfg["target_modules"] + ["lm_head"]}, open(e + "/adapter_config.json", "w"))
m = GPTQModel.load(BASE, adapter=Lora(path=e, rank=64), backend=BACKEND.GPTQ_TORCH, device="cuda:0")
print(type(m.model.lm_head).__name__, getattr(m.model.lm_head, "adapter", None))   # Linear None -> delta silently skipped

Expected

Follow PEFT semantics:

  • modules outside target_modules, or with no keys, get no adapter;
  • adapter weights for dense targets are applied, or at least warned about or raised on.

Found during an AI-assisted review (Claude Code) of 9dad249; repros were run on RTX 4090/5090 (CUDA 13) and/or Radeon AI PRO R9700 (ROCm) unless marked static/suspected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions