Repository navigation
fix(fp8): expose the packed weight as qweight so PEFT LoRA can wrap it (#4948) - #4987
Merged
Merged
Conversation
… 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TorchFP8LineardeclaresSUPPORTS_TRAINING = True,AUTO_TRAINABLEselects it, and its backward is correct (input gradients flow). But PEFT LoRA cannot wrap it. PEFT routes every GPT-QModelBaseQuantLinearthroughpeft/tuners/lora/gptq.py::dispatch_gptq, which runsTorchFP8Linearkeeps its codes inweight(the name the FP8 checkpoint andWeightOnlyQuantLinearuse) and has noqweight, soget_peft_modelraisedbefore 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.qweightis a property overweight.dispatch_gptqreads.targetis the FP8 module when it is not already aBaseTunerLayer) — verified by the first version of this fix, which used a read-only property and failed attarget.qweight = .... The setter rebindsweightand keeps the slot's kind (parameter stays a parameter), so a rebind cannot silently turn a parameter into a plain tensor.weightstays canonical for the forward, the packer and the checkpoint; nothing else is renamed.Tests
tests/test_fp8_peft_lora_4948.py(new):test_fp8_module_exposes_the_packed_weight_as_qweightqweight is weight; a rebind keeps both names in synctest_peft_lora_wraps_the_fp8_kernel_and_trainsget_peft_modelwraps every FP8q_proj/v_projinGPTQLoraLinear; forward+backward gives finitelora_A/lora_Bgrads; the frozen FP8 codes are bitwise unchangedtest_peft_lora_forward_matches_the_unadapted_fp8_forwardpeftis not a declared dependency of this repository, so the two PEFT nodesimportorskipand the alias node always runs; the fix is therefore still covered in a bare environment. The PEFT nodes pinis_gptqmodel_available()toTrue(PEFT reads it from package metadata, which a source checkout onPYTHONPATHdoes not have) so the dispatch branch under test is actually taken.Red → green,
peft 0.21.2onPYTHONPATH: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 failedThe one failure is
test_checkpoint_modules.py::test_qqq_optional_group_scales_schema, which fails identically on unmodifiedorigin/main(QQQ, unrelated).ruff checkon both changed files: All checks passed.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
fp8.py+24, one new test file.weightremains 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
Closes #4948.