Repository navigation
Description
Found on main @ 3867c82, AMD R9700 (gfx1201, ROCm), Qwen2.5-0.5B-Instruct ParoConfig() checkpoint made on this commit, bf16, peft 0.21.2.
What is wrong
ParoLinear (and ParoTritonLinear) declare SUPPORTS_TRAINING = True and are what AUTO/AUTO_TRAINABLE load. On an accelerator, though, their forward cuts the autograd graph at the input. ParoLinear._rotate_inputs (gptqmodel/nn_modules/qlinear/paro.py:570-603) always calls apply_paro_rotation (gptqmodel/utils/paro.py:995). On CUDA/ROCm that dispatches to the fused gptqmodel_paro::rotate op through _apply_fused_rotation, which has no autograd kernel. The autograd-capable wrapper exists, apply_paro_rotation_autograd / _ParoRotateTensorFunc (utils/paro.py:1008-1185), but only the Paro optimizer uses it.
PyTorch warns once (gptqmodel_paro::rotate: an autograd kernel was not registered ... This may lead to silently incorrect behavior) and then returns None as the input gradient. The loss still backpropagates, but:
- every parameter upstream of a Paro module gets no gradient at all;
- every gradient that reaches a parameter through the residual stream misses all contributions that pass through quantized projections.
On CPU the extension is not used (requires_cuda=True), so the reference rotation runs and gradients are correct. That is why CPU tests pass.
Repro
Module level (o_proj of layer 0, train mode; the reference uses the effective weight recovered from the module's own forward on an identity input):
m = GPTQModel.load("Qwen2.5-0.5B-Instruct_paro", device="cuda:0", dtype=torch.bfloat16, backend=bk)
mod = m.model.model.layers[0].self_attn.o_proj; m.model.train()
x = torch.randn(3, 7, mod.in_features, device="cuda:0", dtype=torch.bfloat16, requires_grad=True)
y = mod(x); (y.float() * torch.randn_like(y).float()).sum().backward()
print(bk, type(mod).__name__, y.requires_grad, x.grad)ROCm AUTO ParoLinear y.requires_grad True x.grad None
ROCm AUTO_TRAINABLE ParoLinear y.requires_grad True x.grad None
ROCm PARO_TRITON ParoTritonLinear y.requires_grad True x.grad None
ROCm PARO_CUDA ParoLinear y.requires_grad True x.grad None
CPU AUTO ParoLinear dx relative error vs dense reference 0.0036 (correct)
End to end with PEFT LoRA (r=8 on q_proj/v_proj/down_proj, same seed and inputs, compared with a dense model built from the same effective weights):
CPU ParoLinear: LoRA grads 144/144, max relative diff 0.235 (bf16 noise floor ~0.2 on this model)
ROCm ParoLinear: LoRA grads 48/144 (every q_proj/v_proj LoRA grad is None),
down_proj LoRA grads off by up to 134%, loss 0.517 vs 0.535
Other trainable kernels on the same ROCm card pass this check: GPTQ Torch 0.022 (fp16), AWQ Torch 0.032, AWQ GEMM Triton 0.026-0.047, GGUF Torch.
Suggested fix
In ParoLinear._rotate_inputs, use apply_paro_rotation_autograd whenever grad mode is on and x_flat.requires_grad or the rotation parameters require grad, or always (_ParoRotateTensorFunc costs nothing extra in inference). Alternatively, register an autograd kernel for gptqmodel_paro::rotate. Also check that the CUDA AWQ GEMM path that _forward_cuda_awq_kernel takes on NVIDIA is differentiable with respect to its input; I could not test NVIDIA in this round.
Test that should have caught it
No GPU test backpropagates through ParoLinear. Add a CUDA/ROCm test: x.requires_grad_(), forward in train mode, backward, and assert that x.grad matches grad_out @ W_eff (as the CPU kernel-gradient tests already do for GPTQ/AWQ).
Severity
High for anyone fine-tuning a ParoQuant model on a GPU. Training runs and the loss goes down, but most adapter parameters never receive a gradient and the rest receive wrong ones. The only signal is a one-time PyTorch UserWarning.
🤖 Generated with Claude Code
Activity
Qubitium commentedon Nov 17, 2026
Agent claim:
agent-root-4958is working on this issue now.Qubitium commentedon Nov 17, 2026
Agent release:
agent-root-4958finished this issue. Fix: #4992, squash-merged as d5dde13.ParoLinearcut the autograd graph twice in train mode, and both are now fixed:_rotate_inputsalways calledapply_paro_rotation, which dispatches to the fusedgptqmodel_paro::rotateop with no autograd kernel. It now usesapply_paro_rotation_autogradwhenevertorch.is_grad_enabled()and the input,thetaorchannel_scalesrequires grad - the same condition the Paro optimizer already used inquantization/paro/optimization.py::_apply_rotation. The vectorized CPU branch is gated on the same condition (it also dropped athetagradient in eval).gptqmodel_awq::gemm_forwardandgemm_forward_fp32_reducehave no autograd kernel either, so a differentiable rotation alone would still have lostdL/dx._forward_cuda_awq_kernelnow returnsNonefor a gradient-bearing operand and the dense reference serves the call.ParoTritonLinearneeded no change:_select_planalready routes to_forward_triton_densevia_needs_dense_autograd.Inference is unchanged: the autograd wrapper's forward runs the same fused kernel and is asserted bitwise identical to
apply_paro_rotation, andno_gradforwards keep the plain/vectorized rotation and the native AWQ GEMM.Verification (this host: NVIDIA PG506 sm_80, torch 2.15.0.dev, Triton 3.8; the issue was filed on ROCm and the
Nonegradient was reproduced identically here):tests/test_paro_training_gradients_4958.py: 6 failed / 3 passed on unmodifiedorigin/main(the 3 passing are the CPU nodes, matching "on CPU ... gradients are correct") -> 9 passed on the fix, and 9 passed again on the mergedmain.x.gradrel 2.2e-3,theta.grad1.5e-3; CUDA BF16 8.9e-3 / 1.0e-2 - all inside the single output rounding.ParoLinearupstream-parameter symptom: aLinearbefore a Paro layer now gets a finite nonzero gradient on CUDA (wasNone).test_paro*+kernels/test_paro*307 passed / 4 skipped on bothmainand the fix;test_paro_rotation_lifecycle,test_paro_capture_order,test_paro_positional_replay,test_paro_branch_replay_masks,test_awq_rank_and_empty80 passed; compile-policy/compile-level subset 28 passed / 5 skipped;test_docs_contract_refs20 passed; ruff clean.docs/paro.mdgained a "Module training path" subsection recording the dispatch contract and the tests. All 9 CI checks green before the squash merge.fix(paro): keep training gradients in the module forward (ModelCloud#…