Skip to content

fix(kernels): finish the view-free epilogues for wide bias and AWQ GEMM (#4974) - #5001

Merged
Qubitium merged 1 commit into
mainfrom
root/adalora-view-4974
Nov 17, 2026
Merged

Qubitium merged 1 commit into
mainfrom
root/adalora-view-4974

Conversation

@Qubitium

@Qubitium Qubitium commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

#5003 (merged) fixed the no-op reshape in the FP32-reduction epilogue, so
PEFT's AdaLoRA wrapper (result += output) works for the plain 2-D
TorchLinear/TritonV2Linear paths. Three epilogues still hand autograd a
view created inside a custom autograd.Function, which autograd forbids
modifying in place:

path when it is reached state on main
linear_wide_bias a checkpoint bias stored wider than the activations (FP32 bias + FP16/BF16 activations), inside QuantLinearFunction under autocast and on ROCm output.to(dtype).reshape(shape) → view
_fused_addmm the CPU/HIP fused bias epilogue (linear_fp32_reduce) .reshape(shape) → view
AwqGemmFn / AwqGemmTritonFn the two trainable AWQ GEMM kernels out.reshape(out_shape) → view, 2-D and batched

What Changed

  • gptqmodel/nn_modules/qlinear/_numerics.py
    • linear_wide_bias and _fused_addmm return through a new
      _reshape_reduced_owned(): the allocation-free reshape is kept for eager
      calls, and the view is materialized when the epilogue runs inside a
      Function forward (grad mode is off there while the output is tracked).
      Only a batched, autograd-tracked result pays for the copy.
  • gptqmodel/nn_modules/qlinear/gemm_awq.py, gemm_awq_triton.py: return the
    kernel's own 2-D allocation as-is (a no-op reshape would still be a view)
    and materialize the batched result. The Triton plan-warming bookkeeping is
    untouched.
  • tests/test_training_kernel_inplace_4974.py (new, 40 nodes): every
    SUPPORTS_TRAINING kernel this host can build — TorchLinear,
    TritonV2Linear (train and eval, which runs QuantLinearFunction),
    TorchFusedLinear, TorchAtenLinear, AwqTorchLinear, GGUFTorchLinear,
    TorchFP8Linear, AwqGemmFn, AwqGemmTritonFn — 2-D and 3-D, the
    wide-bias epilogue through the real TritonV2Linear Function under
    autocast, the storage-ownership invariant of the epilogue helpers
    (CPU-runnable), and a real PEFT SVDQuantLinear AdaLoRA step.
  • tests/test_peft_adalora_training_4974.py (from fix(qlinear): never return a reshape view from the trainable kernels (#4974) #5003): PEFT's
    is_gptqmodel_available probe resolves an installed gptqmodel
    distribution and raises PackageNotFoundError in a source checkout, so both
    AdaLoRA nodes errored instead of running. The probe now sees the in-tree
    version for the wrapper construction (and is cache_cleared after), so the
    nodes run where PEFT is installed and still skip where it is not.
  • .github/workflows/awq_cpu.yml: run both guard files in the CPU unit
    suite and trigger on _numerics.py / gemm_awq*.py.

No numerics change: outputs, dtypes and shapes are identical, and the eager
inference path keeps its allocation-free reshape.

Tests

Red on unmodified origin/main @ 8ab5fefd6 (tests copied into a pristine
worktree), green on this branch:

CUDA_VISIBLE_DEVICES=2 PYTHONPATH=<wt>:/tmp/peft021 python /tmp/root-rt.py \
  tests/test_training_kernel_inplace_4974.py tests/test_peft_adalora_training_4974.py \
  -q -o addopts= -o log_cli=false -p no:cacheprovider
# branch:  51 passed
# main:     7 failed, 44 passed

Red nodes on main: test_fp32_reduction_epilogue_owns_its_storage[linear-*]
(the _fused_addmm view), both
test_triton_v2_wide_bias_kernel_allows_inplace_accumulation shapes
(linear_wide_bias inside the Function under autocast), and all four
test_awq_gemm*_function_allows_inplace_accumulation nodes.

Neighbours (145 → 189 nodes, all green):

suite result
test_awq_fp32_output.py, kernels/test_awq_triton_bias_epilogue.py, kernels/test_awq_native_eval_autograd.py 24 passed
test_train_mode_atomicity.py, kernels/test_linear_fp32_reduce.py, kernels/test_triton_fp32_reduce.py, kernels/test_torch_wide_bias_fallback.py 165 passed
CPU-only run of both guard files (CUDA_VISIBLE_DEVICES="") 17 passed, 34 skipped
  • Unit tests have been executed and passed, or the reason they are not applicable is documented.
  • I added a new simple/fast unit test for this change, or documented why that is not applicable.

Model Support / Module Plan

Not applicable: no MODEL_MAP, definition, or fusion change.

Fixes #4974

…MM (#4974)

#5003 fixed the no-op reshape in the FP32-reduction epilogue. Three paths
still hand autograd a view created inside a custom `autograd.Function`, so
PEFT's AdaLoRA wrapper (`result += output`) still failed on them:

- `linear_wide_bias` (a checkpoint bias stored wider than the activations,
  reached inside `QuantLinearFunction` under autocast and on ROCm) ended in
  `output.to(dtype).reshape(shape)`;
- `_fused_addmm` (the CPU/HIP fused epilogue) reshaped its 2-D product;
- `AwqGemmFn` and `AwqGemmTritonFn` reshaped their batched result.

New `_reshape_reduced_owned()` keeps the allocation-free reshape for eager
calls and materializes it when it runs inside a Function forward (grad mode is
off there while the output is tracked), so only a batched, autograd-tracked
result pays for a copy.

`tests/test_training_kernel_inplace_4974.py` covers every `SUPPORTS_TRAINING`
kernel this host can build (TorchLinear, TritonV2Linear train+eval,
TorchFusedLinear, TorchAtenLinear, AwqTorchLinear, GGUFTorchLinear,
TorchFP8Linear, both AWQ GEMM Functions), the wide-bias epilogue through the
real `TritonV2Linear` Function, the storage-ownership invariant for the
epilogue helpers, and a real PEFT AdaLoRA step.

`tests/test_peft_adalora_training_4974.py` (from #5003) now tolerates a source
checkout: PEFT's `is_gptqmodel_available` probe resolves an installed
`gptqmodel` distribution and raises `PackageNotFoundError` without one, which
made both AdaLoRA nodes error instead of run.

Fixes #4974
@Qubitium
Qubitium force-pushed the root/adalora-view-4974 branch from 2ecd3d3 to 6633752 Compare November 17, 2026 22:03
@Qubitium Qubitium changed the title fix(kernels): return owned storage from trainable kernel epilogues (#4974) fix(kernels): finish the view-free epilogues for wide bias and AWQ GEMM (#4974) Nov 17, 2026
@Qubitium
Qubitium merged commit 24a46e3 into main Nov 17, 2026
9 checks passed
@Qubitium
Qubitium deleted the root/adalora-view-4974 branch November 17, 2026 22:11
Qubitium pushed a commit that referenced this pull request Nov 18, 2026
#5130)

#5001 materialized the leading-dimension reshape in AwqGemmFn and
AwqGemmTritonFn unconditionally, so every batched AWQ GEMM forward paid
for a full-output copy even under inference_mode. Materialize the reshape
only when an input needs grad, which is the condition that makes the
Function output autograd-tracked. Untracked results can keep the
Function's reshape view and accept in-place updates, so the #4974
guarantee is preserved without the inference-time copy.

Add regression coverage for both backends and both modules: a batched
inference forward allocates no clone, while a tracked batched output is
still an owned tensor that supports in-place accumulation and backward.
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