You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] PEFT AdaLoRA cannot train any GPTQ model: TritonV2Linear/TorchLinear return a view created inside QuantLinearFunction, so AdaLoRA's in-place 'result += output' raises (test_olora_finetuning_xpu red since 12c1273c2) #4974
Found on main @ 3867c82, RTX 4090 (torch 2.15, peft 0.21.2, transformers 5.22). Also red at b225a43 (same error) and at 12c1273: this is an old bug, not a regression from this round.
What is wrong
The trainable GPTQ kernels return a tensor that is a view created inside a custom autograd.Function. Autograd forbids in-place ops on such a tensor. PEFT's AdaLoRA wrapper for GPTQ does exactly such an op (peft/tuners/adalora/gptq.py:66, result += output), so AdaLoRA fine-tuning of any GPTQ model fails on the first forward. Plain LoRA works because GPTQLoraLinear uses an out-of-place add.
Where the view comes from: TritonV2Linear.forward calls QuantLinearFunction.apply(...) (gptqmodel/nn_modules/triton_utils/dequant.py:360). Its forward returns quant_matmul(...), which ends in matmul_fp32_reduce() (gptqmodel/nn_modules/qlinear/_numerics.py:166, return output.to(x.dtype).reshape(shape)). reshape on a contiguous tensor returns a view even when the shape does not change, so the Function's output is a view of an internal tensor. TorchLinear (BACKEND.TORCH) gives the same result. The .reshape has been there since #3520.
tests/test_olora_finetuning_xpu.py::Test::test_peft (AdaLoRA on a GPTQ Llama-3.1-8B, BACKEND.AUTO_TRAINABLE) fails on CUDA with exactly this error. It has been red in every suite triage since at least 12c1273, but it was never filed:
peft/tuners/adalora/gptq.py:66: RuntimeError: Output 0 of View is a view and is being modified inplace. This view was created inside a custom Function ...
LoRA: wrapper=GPTQLoraLinear kernel=TritonV2Linear loss=12.259 backward OK
AdaLoRA: wrapper=SVDQuantLinear kernel=TritonV2Linear FAILED: Output 0 of View is a view and is being modified inplace. This view was created inside a custom Function ...
Directly on the kernel (GPTQModel.load(..., backend=AUTO_TRAINABLE or TORCH), q_proj, input with requires_grad): y = mod(x) gives y._is_view() == True, and y += 1.0 raises the same error for TritonV2Linear and TorchLinear, for both 2-D and 3-D inputs.
Suggested fix
Do not return a view from inside the Function:
in matmul_fp32_reduce, return output.to(x.dtype) when output.shape == shape, and reshape outside the autograd Function; or
reshape in TritonV2Linear.forward/TorchLinearafterQuantLinearFunction.apply, and have the Function return the 2-D tensor it computed.
A view taken outside the Function (QuantLinearFunction.apply(...).reshape(...)) is fine for autograd.
Test that should have caught it
tests/test_olora_finetuning_xpu.py does catch it, but it needs a pre-quantized 8B checkpoint and the Hub, so it never runs in CI. A small unit test would cover the contract: for every SUPPORTS_TRAINING kernel, check that out = module(x.requires_grad_()) allows out += 1; out.sum().backward().
Severity
Medium: AdaLoRA (a documented PEFT method that GPT-QModel's AUTO_TRAINABLE path is supposed to serve) cannot train any GPTQ model, and any user code that adds in-place to the output hits the same error.
Fix the PEFT AdaLoRA training failure: TritonV2Linear/TorchLinear return a view created inside QuantLinearFunction (autograd error); make the training forward return a tensor that does not alias the Function's saved output, with a CPU AdaLoRA smoke test.
#5003 landed the first half (_CudaWideMatmul returns the 2-D product, no-op
reshape skipped in matmul_fp32_reduce). This PR finishes the paths that still
returned a reshape view created inside a custom autograd.Function:
path
reached when
linear_wide_bias
checkpoint bias stored wider than the activations (FP32 bias + FP16/BF16 activations), inside QuantLinearFunction under autocast and on ROCm
_fused_addmm
the CPU/HIP fused bias epilogue in linear_fp32_reduce
AwqGemmFn, AwqGemmTritonFn
the two trainable AWQ GEMM kernels, 2-D and batched
_reshape_reduced_owned() keeps the allocation-free reshape for eager calls and
materializes the view only when it runs inside a Function forward (grad mode off
there while the output is tracked), so only a batched autograd-tracked result
pays for a copy. Numerics are unchanged (174 forward/gradient tensors bitwise
equal to unmodified main).
tests/test_training_kernel_inplace_4974.py guards every SUPPORTS_TRAINING
kernel this host can build — TorchLinear, TritonV2Linear (train and
eval), TorchFusedLinear, TorchAtenLinear, AwqTorchLinear, GGUFTorchLinear, TorchFP8Linear, AwqGemmFn, AwqGemmTritonFn — 2-D and
3-D, plus a real PEFT SVDQuantLinear AdaLoRA step. Red on unmodified 8ab5fefd6: 7 failed / 44 passed; green here: 51 passed (189 with the
neighbouring AWQ/triton/torch epilogue suites; 17 passed / 34 skipped on CPU).
Both guard files now run in the AWQ CPU unit CI lane.
tests/test_peft_adalora_training_4974.py (from #5003) no longer errors in a
source checkout: PEFT's is_gptqmodel_available probe resolves an installed gptqmodel distribution and raises PackageNotFoundError without one, which
made both AdaLoRA nodes fail before reaching the assertion.
Activity
Qubitium commentedon Nov 17, 2026
Agent claim:
agent-root-4974is working on this issue now.Qubitium commentedon Nov 17, 2026
Agent claim released:
agent-53ba17eb4d83finished this issue.Pull request: #5003
Fix the PEFT AdaLoRA training failure: TritonV2Linear/TorchLinear return a view created inside QuantLinearFunction (autograd error); make the training forward return a tensor that does not alias the Function's saved output, with a CPU AdaLoRA smoke test.
fix(qlinear): never return a reshape view from the trainable kernels (#…
Qubitium commentedon Nov 17, 2026
Agent claim released:
agent-root-4974finished this issue.Pull request: #5001 (squash-merged as
24a46e337).#5003landed the first half (_CudaWideMatmulreturns the 2-D product, no-opreshape skipped in
matmul_fp32_reduce). This PR finishes the paths that stillreturned a reshape view created inside a custom
autograd.Function:linear_wide_biasQuantLinearFunctionunder autocast and on ROCm_fused_addmmlinear_fp32_reduceAwqGemmFn,AwqGemmTritonFn_reshape_reduced_owned()keeps the allocation-free reshape for eager calls andmaterializes the view only when it runs inside a Function forward (grad mode off
there while the output is tracked), so only a batched autograd-tracked result
pays for a copy. Numerics are unchanged (174 forward/gradient tensors bitwise
equal to unmodified main).
tests/test_training_kernel_inplace_4974.pyguards everySUPPORTS_TRAININGkernel this host can build —
TorchLinear,TritonV2Linear(train andeval),
TorchFusedLinear,TorchAtenLinear,AwqTorchLinear,GGUFTorchLinear,TorchFP8Linear,AwqGemmFn,AwqGemmTritonFn— 2-D and3-D, plus a real PEFT
SVDQuantLinearAdaLoRA step. Red on unmodified8ab5fefd6: 7 failed / 44 passed; green here: 51 passed (189 with theneighbouring AWQ/triton/torch epilogue suites; 17 passed / 34 skipped on CPU).
Both guard files now run in the AWQ CPU
unitCI lane.tests/test_peft_adalora_training_4974.py(from #5003) no longer errors in asource checkout: PEFT's
is_gptqmodel_availableprobe resolves an installedgptqmodeldistribution and raisesPackageNotFoundErrorwithout one, whichmade both AdaLoRA nodes fail before reaching the assertion.
fix(awq): skip the batched output copy for untracked inference (#5086) (
fix(kernels): finish the view-free epilogues for wide bias and AWQ GE…