Skip to content

test(kernels): load through a fresh Lora so the dense lm_head is not targeted (#4764) - #4886

Merged
Qubitium merged 1 commit into
mainfrom
test/gptq-lora-fresh-adapter
Nov 17, 2026
Merged

Qubitium merged 1 commit into
mainfrom
test/gptq-lora-fresh-adapter

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes item 7 of #4764. Test-only; no library behaviour changed.

What was wrong

tests/kernels/test_gptq.py::TestKernelOutput.setUpClass built one Lora
instance, materialized A/B on it with post_init(target, ...) to learn k, and
then passed that same instance to every GPTQModel.load(adapter=...) call.

Once A/B are materialized, Lora.targets_module() short-circuits to True for
every module (adapter.py:355-357). apply_dense_module_adapters therefore
tries to attach the adapter to the dense lm_head, has_weights("lm_head")
returns True for the same reason, and post_init(weight_key="lm_head") finds
no tensors and asserts:

gptqmodel/adapter/adapter.py:448: AssertionError
AssertionError: Adapter: `lora_A` and `lora_B` must both be present in the
weights: actual = `None` and `None`

All 24 TestKernelOutput cases ERROR in setUpClass.

Fix

  • TestKernelOutput._fresh_adapter() returns an unmaterialized Lora with
    the same remote pin (allow_remote, revision, sha256). Every load gets
    its own instance, so targets_module() falls through to the PEFT
    target_modules list and lm_head is correctly not targeted.
  • setUpClass still materializes one instance to read k; it is no longer
    passed to load.
  • test_kernel_*_with_lora call _fresh_adapter() instead of data.adapter.

Also fixed: TRITON bf16 atol was below bf16 resolution

Unblocking setUpClass exposed the next layer. BACKEND.TRITON bf16 was
declared with atol=1e-5, which is below bf16 resolution, so it failed on
every sample — with and without a LoRA, and also on the pre-existing
non-LoRA test_kernel_bfloat16_1_triton, which never used the adapter at all:

case MaxAbsDiff old atol result
test_kernel_bfloat16_1_triton (no LoRA) 0.007812 1e-5 FAIL 111/112
test_kernel_bfloat16_with_lora_1_triton 0.015625 1e-5 FAIL 112/112

Both values are exactly one bf16 ulp (2^-7 at |y|~2, 2^-6 at |y|~4). The
bound is now 0.015625 for the TRITON bf16 entry in both tables, matching the
0.008-0.016 bounds already used for EXLLAMA_V2/MACHETE/SWORDFISH/MARLIN.
The f16 entry is untouched.

Red / green

Red, on origin/main @ 4f287eb with the original file:

$ CUDA_VISIBLE_DEVICES=4 GPTQMODEL_FAST_TESTS=1 pytest kernels/test_gptq.py \
      -k test_kernel_float16_with_lora -x
ERROR kernels/test_gptq.py::TestKernelOutput::test_kernel_float16_with_lora_0_torch
E   AssertionError: Adapter: `lora_A` and `lora_B` must both be present in the
    weights: actual = `None` and `None`
E   ../gptqmodel/adapter/adapter.py:448: AssertionError
WARN Adapter: Lora weights not found for `lm_head`
=> 1 error in 15.35s

Green, same host, patched file, whole module:

$ CUDA_VISIBLE_DEVICES=5 GPTQMODEL_FAST_TESTS=1 pytest kernels/test_gptq.py -q
18 passed, 8 skipped in 124.85s

All 16 executed cases pass; the 8 skips are MACHETE and SWORDFISH, which
declare no support for this host's sm_80.

dtype backend MaxAbsDiff (no LoRA) MaxAbsDiff (LoRA)
bf16 TORCH 0.000000 0.000000
bf16 TRITON 0.007812 0.015625
bf16 EXLLAMA_V2 0.007812 0.015625
bf16 MARLIN 0.007812 0.015625
f16 TORCH 0.000000 0.000000
f16 TRITON 0.000000 0.000000
f16 EXLLAMA_V2 0.000977 0.001953
f16 MARLIN 0.000977 0.000977

The reference is the TORCH backend with the same adapter, so a non-zero
MaxAbsDiff is the kernel's own dequant rounding, not adapter error.

Adapter-path regression tests

$ pytest test_adapter_targets.py test_adapter_cache_lifecycle.py -q
17 passed in 35.73s

Environment note

This host's flash_attn_2_cuda has an undefined symbol, so the runs above
loaded transformers with is_flash_attn_2_available -> False (a local
pytest plugin, not part of the diff). That failure is pre-existing and
unrelated to this change.

Claim: agent-11788dff99fd, workload 0df020bcd412.

…targeted (#4764)

TestKernelOutput.setUpClass materialized A/B on one Lora to learn `k`, then
passed that same instance to every GPTQModel.load(adapter=...). Once A/B are
materialized, Lora.targets_module() answers True for every module, so
apply_dense_module_adapters targeted the dense lm_head, post_init("lm_head")
found no tensors, and the A/B assertion aborted all 24 cases in setUpClass.

Loads now go through _fresh_adapter(), an unmaterialized Lora with the same
remote pin; setUpClass keeps its materialized instance only for `k`.

Unblocking setUpClass exposed the next stale bound: TRITON bf16 declared
atol=1e-5, below bf16 resolution, so it failed on every sample with and
without a LoRA (and on the pre-existing non-LoRA case, which never used the
adapter). Both measured values are exactly one bf16 ulp; the bound is now
0.015625, matching the other bf16 entries. No library behaviour changed.

tests/kernels/test_gptq.py: 18 passed, 8 skipped (MACHETE/SWORDFISH are not
supported on this sm_80 host).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant