Skip to content

[BUG] ParoQuant training on GPU silently drops input gradients: ParoLinear uses the fused gptqmodel_paro::rotate op without autograd (x.grad None; PEFT LoRA 48/144 grads on ROCm) #4958

Closed

Description

@Qubitium

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

  1. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim: agent-root-4958 is working on this issue now.

  2. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Agent release: agent-root-4958 finished this issue. Fix: #4992, squash-merged as d5dde13.

    ParoLinear cut the autograd graph twice in train mode, and both are now fixed:

    1. _rotate_inputs always called apply_paro_rotation, which dispatches to the fused gptqmodel_paro::rotate op with no autograd kernel. It now uses apply_paro_rotation_autograd whenever torch.is_grad_enabled() and the input, theta or channel_scales requires grad - the same condition the Paro optimizer already used in quantization/paro/optimization.py::_apply_rotation. The vectorized CPU branch is gated on the same condition (it also dropped a theta gradient in eval).
    2. The NVIDIA half of the check the issue asked for: gptqmodel_awq::gemm_forward and gemm_forward_fp32_reduce have no autograd kernel either, so a differentiable rotation alone would still have lost dL/dx. _forward_cuda_awq_kernel now returns None for a gradient-bearing operand and the dense reference serves the call. ParoTritonLinear needed no change: _select_plan already routes to _forward_triton_dense via _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, and no_grad forwards 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 None gradient was reproduced identically here):

    • new tests/test_paro_training_gradients_4958.py: 6 failed / 3 passed on unmodified origin/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 merged main.
    • gradients vs a dense FP32 reference (128x128, non-identity rotation): CPU FP32 exact; CUDA FP16 x.grad rel 2.2e-3, theta.grad 1.5e-3; CUDA BF16 8.9e-3 / 1.0e-2 - all inside the single output rounding.
    • ParoLinear upstream-parameter symptom: a Linear before a Paro layer now gets a finite nonzero gradient on CUDA (was None).
    • regression suites: test_paro* + kernels/test_paro* 307 passed / 4 skipped on both main and the fix; test_paro_rotation_lifecycle, test_paro_capture_order, test_paro_positional_replay, test_paro_branch_replay_masks, test_awq_rank_and_empty 80 passed; compile-policy/compile-level subset 28 passed / 5 skipped; test_docs_contract_refs 20 passed; ruff clean.

    docs/paro.md gained a "Module training path" subsection recording the dispatch contract and the tests. All 9 CI checks green before the squash merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions