Skip to content

fix(adapter): honour PEFT target modules and apply dense targets (#4210) - #4283

Merged
Qubitium merged 3 commits into
mainfrom
fix/issue-4210-adapter-targets
Nov 16, 2026
Merged

Qubitium merged 3 commits into
mainfrom
fix/issue-4210-adapter-targets

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #4210

Problem

One global qcfg.adapter was passed to every quantized module (utils/model.py), so:

  1. a standard partial PEFT LoRA (target_modules=["q_proj","v_proj"]) was attached to k_proj/o_proj/gate_proj/... too, and Lora.post_init asserted on the first module with no A/B tensors;
  2. adapter tensors for modules that stay dense (an unquantized lm_head, a dynamic exclusion) were never applied and nothing was logged.

Fix

  • New gptqmodel/adapter/targeting.py resolves target_modules/exclude_modules with PEFT rules: string = re.fullmatch, list entries = exact or dotted-suffix match, re:-prefixed entries = regex, all-linear, and exclude_modules wins.
  • create_quant_module now attaches the adapter only to modules the adapter targets and that have A/B tensors in the export. Modules outside the target list, or targeted modules absent from a partial export (layers_to_transform-style), get no adapter; the latter is logged. Merged/EoRA adapters (path None or not-yet-saved output dir) keep the historical attach-all behavior.
  • gptqmodel_post_init now calls apply_dense_module_adapters: targeted non-quantized nn.Linear/Conv1D modules get their adapter applied through a forward hook, so dense lm_head adapters are no longer dropped.
  • Lora gained targets_module() / has_weights() and a shared _load_adapter() used by both target resolution and post_init (config+weights still cached once).

Files touched (for #4211 sequencing)

  • gptqmodel/adapter/targeting.py (new)
  • gptqmodel/adapter/adapter.py (target resolution + shared adapter load)
  • gptqmodel/utils/model.py (per-module attach filter + dense-module application)
  • tests/test_adapter_targets.py (new)

#4211 (DoRA / PEFT field validation) touches the same adapter config area; please sequence it after this PR. This PR does not change DoRA or PEFT field validation.

Evidence (fail before on origin/main c45c1b018, pass after)

Independent repro with a partial adapter (target_modules=["q_proj","v_proj"]) and an adapter that targets dense lm_head:

Before:

adapter attached: {'q_proj': True, 'k_proj': True, 'v_proj': True}
post_init crash: ('k_proj', 'Adapter: `lora_A` and `lora_B` must both be present in the weights: actual = `None` and `None`')
dense adapter attached: False
dense output changed: False

After:

adapter attached: {'q_proj': True, 'k_proj': False, 'v_proj': True}
post_init crash: None
dense adapter attached: True
dense output changed: True

End-to-end tiny-Llama quantization + reload (CPU):

Before:

partial load: FAILED -> AssertionError Adapter: `lora_A` and `lora_B` must both be present in the weights: actual = `None` and `None`

After:

partial load: OK
model.layers.0.self_attn.q_proj adapter True
model.layers.0.self_attn.k_proj adapter False
model.layers.0.self_attn.v_proj adapter True
model.layers.0.self_attn.o_proj adapter False
lm_head type: Linear
dense adapter attached: True
logits changed: True

tests/test_adapter_targets.py: 12 passed (includes the end-to-end partial-LoRA load and dense lm_head logits check).
Adapter/quant-module regression set (test_adapter_config, test_adapter_cache_lifecycle, test_adapter_scaling, test_adapter_case_sensitive, test_adapter_remote_security, test_quant_module_device, test_checkpoint_processor_adapter, kernels/test_awq_cpu_fused_post_init): 102 passed, 1 skipped.
ruff check gptqmodel docs/eora tests setup.py: All checks passed.

Residual risk

  • all-linear currently means "every linear module offered to the matcher"; PEFT additionally excludes the output layer. Not exercised by the reported partial-LoRA case.
  • layers_to_transform/layers_pattern are not used for target matching; modules covered by the target list but missing from the export are skipped with a warning instead of asserting.
  • Dense adapters are runtime forward hooks: they are not serialized into the checkpoint (the adapter path is re-applied on load), and the fused-projection executor already rejects modules with hooks/adapters, so fused quantized modules are unaffected.
  • Adapters merged into the checkpoint (EoRA, path=None / not-yet-saved output directory) deliberately keep the previous attach-to-every-module behavior because they carry no target list.

stagedev and others added 3 commits November 16, 2026 07:08
- resolve target_modules/exclude_modules with PEFT exact/suffix/re: rules
- attach the adapter only to targeted modules that actually have A/B tensors
- apply adapters to targeted dense modules such as an unquantized lm_head
Resolve adapter/adapter.py: keep #4211's unsupported-tensor rejection in
_load_adapter alongside #4210's target-module helpers.
@Qubitium
Qubitium merged commit d2a0508 into main Nov 16, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/issue-4210-adapter-targets branch November 16, 2026 07:25
Qubitium added a commit that referenced this pull request Nov 17, 2026
Fix the test-side fallout of #4716, #4657, #4627 and #4508. Only entries
that fail on this sm_80 host (PG506) and whose stated reasoning reproduces
were changed; the rest are recorded with their outcome.

1. 8587f0b (#4716, native FP8 GEMM for a wide bias)
   - tests/kernels/test_fp8_kernel.py::test_fp8_default_forward_is_w8a16
     REPRODUCED on sm_80: 6 bf16 cases failed with 1-ulp (0.0078125) diffs
     against rtol/atol 2e-3. The oracle now narrows the decoded weight to
     the activation dtype, matching the native path; the bound is the
     half-ulp at unity (2^-9 ~= 2e-3). FIXED.
   - tests/test_fp8_bias_range.py::test_fp8_gpu_dequant_fallback_keeps_bias_wide
     REPRODUCED on sm_80 (fp16: actual 0.0 vs oracle 0.0078125). Renamed to
     test_fp8_gpu_native_gemm_keeps_bias_wide and rewritten for the #3737
     intent: finite output, FP32 bias, residual bounded by one activation-
     dtype ulp of |x.w|. FIXED.

2. bf5adeb (#4657, Marlin bias kept in checkpoint order)
   - tests/test_marlin_scratch_cuda.py 288/200 cases REPRODUCED on sm_80:
     8 failed with "b_bias.size(0) != size_n". scripts/marlin_scratch_fixture.py
     now passes layer._kernel_bias(a) (padded, tile-ordered FP32) instead of
     the checkpoint-order layer.bias. FIXED (8 failed -> 68 passed, 2 skipped).

3. 60376e9 (#4714, default placement in one capability group)
   - tests/test_tenstorrent_support.py already passes on current main: the
     monkeypatched _record accepts **kwargs (fixed upstream by 50f1752).
     ALREADY PASSES on sm_80.

4. 34672a7 (#4585, modules snapshot the kernel policy)
   - tests/kernels/test_bitsandbytes_rocm_triton.py triton cases SKIP on
     sm_80 (no tuned bitsandbytes tile for this family). DEFERRED: the
     stated failure cannot be reproduced here.

5. dfa180d (#4627, GGUF path chosen from static gates)
   - both tests REPRODUCED on sm_80 with AttributeError
     _benchmark_forward_runner. The removed timing hook is no longer patched;
     each test asserts the hook stays absent. FIXED.

6. fd8d524 (#4599, AwqGEMVTorchLinear CPU reader)
   - both kernel-registry contract tests already pass on current main
     (AwqGEMVTorchLinear is in EXCLUDED and the ROCm audit table; fixed
     upstream by ab151fe). ALREADY PASSES on sm_80.

7. d2a0508 (#4283, dense-module adapters)
   - tests/kernels/test_gptq.py::TestKernelOutput errors on sm_80 before the
     adapter path: this host's flash_attn_2_cuda has an undefined symbol, so
     the stated Lora assertion is never reached. DEFERRED: blocked by the
     pre-existing host flash_attn failure; the fix cannot be verified here.

8. f201837 (#4508, activation-quantization wording)
   - both tests REPRODUCED on sm_80. The refusal still fires; the regex now
     matches "activation quantized|activation scales". FIXED.

9. b225a43 (#4727, static-cache compile test)
   - ROCm-only failure. On sm_80 the CUDA leg runs and fails earlier on the
     host flash_attn symbol, so the ROCm gate cannot be reproduced.
     DEFERRED.

Test run (GPU 4):
  tests/kernels/test_fp8_kernel.py tests/test_fp8_bias_range.py
  tests/test_marlin_scratch_cuda.py tests/test_marlin_scratch_benchmark.py
  tests/kernels/test_gguf_cpp_activation_quantization.py
  tests/kernels/test_gguf_cpp_path_selection.py tests/test_auto_module_decoder.py
  => 254 passed, 35 skipped, 1 failed.
The single failure is the pre-existing sm_80
test_fp8_w8a8_forward_is_batch_invariant (native torch._scaled_mm needs
sm_89+); it fails identically on origin/main.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant