Skip to content

fix(fp8): expose the packed weight as qweight so PEFT LoRA can wrap it (#4948) - #4987

Merged
Qubitium merged 1 commit into
mainfrom
root/fp8-peft-4948
Nov 17, 2026
Merged

Qubitium merged 1 commit into
mainfrom
root/fp8-peft-4948

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

TorchFP8Linear declares SUPPORTS_TRAINING = True, AUTO_TRAINABLE selects it, and its backward is correct (input gradients flow). But PEFT LoRA cannot wrap it. PEFT routes every GPT-QModel BaseQuantLinear through peft/tuners/lora/gptq.py::dispatch_gptq, which runs

target.qweight = target_base_layer.qweight

TorchFP8Linear keeps its codes in weight (the name the FP8 checkpoint and WeightOnlyQuantLinear use) and has no qweight, so get_peft_model raised

AttributeError: 'TorchFP8Linear' object has no attribute 'qweight'

before any training started. Every other trainable kernel (GPTQ Torch/TorchFused/AVX512/Aten, AWQ Torch/AVX512, GGUF Torch, Paro) already keeps its codes in qweight; FP8 is the only advertised trainable kernel the standard fine-tuning path could not use.

What Changed

  • gptqmodel/nn_modules/qlinear/fp8.py: TorchFP8Linear.qweight is a property over weight.
    • The getter is what dispatch_gptq reads.
    • The setter exists because the dispatcher then writes that same tensor back to the module it read it from (target is the FP8 module when it is not already a BaseTunerLayer) — verified by the first version of this fix, which used a read-only property and failed at target.qweight = .... The setter rebinds weight and keeps the slot's kind (parameter stays a parameter), so a rebind cannot silently turn a parameter into a plain tensor.
    • weight stays canonical for the forward, the packer and the checkpoint; nothing else is renamed.

Tests

tests/test_fp8_peft_lora_4948.py (new):

node needs peft what it pins
test_fp8_module_exposes_the_packed_weight_as_qweight no qweight is weight; a rebind keeps both names in sync
test_peft_lora_wraps_the_fp8_kernel_and_trains yes get_peft_model wraps every FP8 q_proj/v_proj in GPTQLoraLinear; forward+backward gives finite lora_A/lora_B grads; the frozen FP8 codes are bitwise unchanged
test_peft_lora_forward_matches_the_unadapted_fp8_forward yes a zero-init adapter leaves the output unchanged

peft is not a declared dependency of this repository, so the two PEFT nodes importorskip and the alias node always runs; the fix is therefore still covered in a bare environment. The PEFT nodes pin is_gptqmodel_available() to True (PEFT reads it from package metadata, which a source checkout on PYTHONPATH does not have) so the dispatch branch under test is actually taken.

Red → green, peft 0.21.2 on PYTHONPATH:

# unmodified origin/main @ 56f87e9f5 (test copied in, fix absent)
E   AttributeError: 'TorchFP8Linear' object has no attribute 'qweight'. Did you mean: 'weight'?
3 failed

# with the fix
3 passed in 6.32s

# without peft installed (bare venv)
1 passed, 2 skipped in 5.87s

Regression neighbours, CPU-only, same interpreter:

python -m pytest tests/test_fp8.py tests/test_fp8_bias_dtype_4575.py tests/test_fp8_bias_range.py \
  tests/test_fp8_dequant_inplace.py tests/test_checkpoint_modules.py \
  tests/test_checkpoint_quant_buffer_dtypes_4458.py tests/kernels/test_qlinear_hierarchy.py \
  tests/test_fp8_peft_lora_4948.py -q
# 132 passed, 19 skipped, 1 failed

The one failure is test_checkpoint_modules.py::test_qqq_optional_group_scales_schema, which fails identically on unmodified origin/main (QQQ, unrelated).

ruff check on both changed files: All checks passed.

  • Unit tests executed and passed (red on unmodified main, green here).
  • New targeted regression test added.

Model Support / Module Plan

Not applicable: no registry, definition or module-plan change.

Logic Flow Documentation

Not applicable: no control flow changed. The alias's reason (and why the setter must exist) is documented in its docstring and in the test header.

Review Requirements

  • Reviewed this PR.
  • Matches existing project structure: an attribute alias on the kernel, no new API, no monkeypatching in product code.
  • Minimal surface: fp8.py +24, one new test file.
  • Regression considered: weight remains the single source of truth; hasattr(module, "qweight") is only consulted in class-specific code (PackableQuantLinear._wf_device, BitBLAS), neither of which FP8 is; the FP8 forward, packer and checkpoint paths are untouched.

Kernel Accuracy Requirements

  • No kernel changed and no numerics: the alias returns the same tensor object the forward already uses; the PEFT node asserts the FP8 codes are bitwise unchanged after training and that a zero-init adapter reproduces the unadapted logits.

Closes #4948.

… it (#4948)

`TorchFP8Linear` advertises `SUPPORTS_TRAINING = True` and its backward is
correct, but PEFT routes every `BaseQuantLinear` through
`peft.tuners.lora.gptq.dispatch_gptq`, which runs

    target.qweight = target_base_layer.qweight

FP8 keeps its codes in `weight`, so that raised

    AttributeError: 'TorchFP8Linear' object has no attribute 'qweight'

before any LoRA training could start, and `AUTO_TRAINABLE` therefore promised a
kernel that could not be fine-tuned with the standard PEFT path. Every other
trainable kernel already keeps its codes in `qweight`.

`TorchFP8Linear.qweight` is now a property over `weight`, with a setter because
`dispatch_gptq` writes the same tensor back to the module it read it from. The
setter rebinds `weight` and preserves the slot's kind, so a rebind cannot turn a
parameter into a plain tensor. `weight` stays canonical for the forward, the
packer and the checkpoint.

Tests: `tests/test_fp8_peft_lora_4948.py`.

  - The alias node needs no extra dependency and always runs: `qweight is
    weight`, and a rebind keeps both names in sync.
  - Two PEFT nodes (skipped when `peft` is not installed, which is why the fix
    is also covered without it): `get_peft_model` wraps the FP8 modules in
    `GPTQLoraLinear`, a forward+backward gives finite `lora_A`/`lora_B`
    gradients, the frozen FP8 codes are bitwise unchanged, and a zero-init
    adapter leaves the output unchanged.

On unmodified main all three fail with the reported AttributeError; with the fix
they pass (3 passed with peft 0.21.2, 1 passed + 2 skipped without it).

Closes #4948.
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