Repository navigation
fix(kernels): finish the view-free epilogues for wide bias and AWQ GEMM (#4974) - #5001
Merged
Merged
Conversation
Qubitium
force-pushed
the
root/adalora-view-4974
branch
from
November 17, 2026 21:53
c8f0141 to
03e9a76
Compare
…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
force-pushed
the
root/adalora-view-4974
branch
from
November 17, 2026 22:03
2ecd3d3 to
6633752
Compare
This was referenced Nov 17, 2026
8 of 10 tasks
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.
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
#5003 (merged) fixed the no-op
reshapein the FP32-reduction epilogue, soPEFT's AdaLoRA wrapper (
result += output) works for the plain 2-DTorchLinear/TritonV2Linearpaths. Three epilogues still hand autograd aview created inside a custom
autograd.Function, which autograd forbidsmodifying in place:
mainlinear_wide_biasQuantLinearFunctionunder autocast and on ROCmoutput.to(dtype).reshape(shape)→ view_fused_addmmlinear_fp32_reduce).reshape(shape)→ viewAwqGemmFn/AwqGemmTritonFnout.reshape(out_shape)→ view, 2-D and batchedWhat Changed
gptqmodel/nn_modules/qlinear/_numerics.pylinear_wide_biasand_fused_addmmreturn through a new_reshape_reduced_owned(): the allocation-free reshape is kept for eagercalls, and the view is materialized when the epilogue runs inside a
Functionforward (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 thekernel's own 2-D allocation as-is (a no-op
reshapewould 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): everySUPPORTS_TRAININGkernel this host can build —TorchLinear,TritonV2Linear(train and eval, which runsQuantLinearFunction),TorchFusedLinear,TorchAtenLinear,AwqTorchLinear,GGUFTorchLinear,TorchFP8Linear,AwqGemmFn,AwqGemmTritonFn— 2-D and 3-D, thewide-bias epilogue through the real
TritonV2LinearFunction underautocast, the storage-ownership invariant of the epilogue helpers
(CPU-runnable), and a real PEFT
SVDQuantLinearAdaLoRA step.tests/test_peft_adalora_training_4974.py(from fix(qlinear): never return a reshape view from the trainable kernels (#4974) #5003): PEFT'sis_gptqmodel_availableprobe resolves an installedgptqmodeldistribution and raises
PackageNotFoundErrorin a source checkout, so bothAdaLoRA nodes errored instead of running. The probe now sees the in-tree
version for the wrapper construction (and is
cache_cleared after), so thenodes run where PEFT is installed and still skip where it is not.
.github/workflows/awq_cpu.yml: run both guard files in the CPUunitsuite 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 pristineworktree), green on this branch:
Red nodes on
main:test_fp32_reduction_epilogue_owns_its_storage[linear-*](the
_fused_addmmview), bothtest_triton_v2_wide_bias_kernel_allows_inplace_accumulationshapes(
linear_wide_biasinside the Function under autocast), and all fourtest_awq_gemm*_function_allows_inplace_accumulationnodes.Neighbours (145 → 189 nodes, all green):
test_awq_fp32_output.py,kernels/test_awq_triton_bias_epilogue.py,kernels/test_awq_native_eval_autograd.pytest_train_mode_atomicity.py,kernels/test_linear_fp32_reduce.py,kernels/test_triton_fp32_reduce.py,kernels/test_torch_wide_bias_fallback.pyCUDA_VISIBLE_DEVICES="")Model Support / Module Plan
Not applicable: no
MODEL_MAP, definition, or fusion change.Fixes #4974