Repository navigation
feat(nf12): add automatic source dtype casting - #3853
Conversation
|
Reviewed head
Minimal reproducer for both, using the CPU codec to isolate lifecycle semantics: import torch
from torch import nn
import gptqmodel.quantization.nf12 as codec
from gptqmodel.nn_modules.hooked_linear import HookedLinear
from gptqmodel.utils.auto_dtype_cast import (
AutoNF12HookedLinear, SourceModuleSpec, restore_source_module,
)
codec._native_encode_runtime = lambda *args: (None, None)
source = HookedLinear.from_linear(
nn.Linear(64, 16, bias=False, dtype=torch.bfloat16)
)
source.online_full_had = True
seen = []
source.forward_hook = lambda m, args, out: seen.append(args[0].clone())
packed = AutoNF12HookedLinear.from_linear(source)
x = torch.zeros(1, 64, dtype=torch.bfloat16)
x[0, 0] = 1
source(x)
packed(x)
print(seen[0][0, :8], seen[1][0, :8])
restored = restore_source_module(
packed, SourceModuleSpec("hooked_linear", torch.bfloat16, (16, 64)),
device="cpu",
)
print(getattr(restored, "online_full_had", None))
print((source(x) - restored(x)).abs().max())Validation: |
|
Fixed in The dense and packed hooked paths now share
Validation on this commit:
|
|
Re-reviewed head The two earlier P1 rotation findings are fixed. Re-running the original non-mocked Hadamard reproducer now captures One remaining finding: [P2] Preserve hook removal when transferring registered hooks. In Confirmed CPU reproduction: after removal, source/packed/restored pre-hook counts are 0 / 1 / 1 and their outputs are 0 / 32 / 32. The remaining hook, not NF12 arithmetic, produces the difference: import torch
from torch import nn
import gptqmodel.quantization.nf12 as codec
from gptqmodel.nn_modules.hooked_linear import HookedLinear
from gptqmodel.utils.auto_dtype_cast import (
AutoNF12HookedLinear, SourceModuleSpec, restore_source_module,
)
# Isolate lifecycle behavior using the CPU codec.
codec._native_encode_runtime = lambda *args: (None, None)
source = HookedLinear.from_linear(
nn.Linear(64, 16, bias=False, dtype=torch.bfloat16)
)
with torch.no_grad():
source.weight.fill_(0.5)
handle = source.register_forward_pre_hook(lambda m, args: (args[0] + 1,))
packed = AutoNF12HookedLinear.from_linear(source)
restored = restore_source_module(
packed, SourceModuleSpec("hooked_linear", torch.bfloat16, (16, 64)),
device="cpu",
)
handle.remove()
modules = (source, packed, restored)
x = torch.zeros(1, 64, dtype=torch.bfloat16)
print([len(m._forward_pre_hooks) for m in modules]) # [0, 1, 1]
print([m(x)[0, 0].item() for m in modules]) # [0, 32, 32]Preserve the registration/removal relationship across replacement, or explicitly transfer/rebind the handles owned by the hook lifecycle. Cover removal of both forward and pre-forward hooks after casting and restoration, including the companion kwargs/always-call metadata dictionaries. Validation on this head:
Runtime: Python 3.14t with GIL disabled, Torch 2.15.0.dev20260928+cu130, Transformers 5.20.2, NVIDIA SM80. No new ROCm, SM89/SM120, or full-model quality validation is claimed. |
|
Fixed in
Added
Validation on
|
|
Verification completed on
The removable-hook review issue is fixed and covered by Validation on the pushed branch:
|
|
Investigated the warm per-layer slowdown and fixed two encode-path bugs in Cause
Fix
Warm RTX 4090 production A/B
Warm encoding after the fix is 0.118522 s for all 112 modules, or 0.079967 s after excluding the first seven shape specializations. Resident allocation after module preparation is 18.88% lower, but end-to-end peak remains governed by GPTQ's inverse/damping workspace and cached calibration inputs. Validation: CUDA 165 passed / 8 skipped; ROCm 554 passed / 1 skipped; both GIL=0 probes pass; scoped Ruff and |
|
Updated in Four-4090 M=512 sweep
End-to-end
The 10-15% The production A/B checkpoint pair remains 482/482 tensors bit-identical. Transfer changes Validation
|
`NF12Linear.dequantize_weight(dtype=torch.float32)` decoded to BF16 and then widened the dense matrix, so FP32 consumers moved 9.5 bytes per element (1.5 read + 2 write + 2 read + 4 write) and held a BF16 copy that existed only to be cast. Add a widening store to both decoders: * CUDA `store_row_tile_fp32` writes the same elements as `store_row_tile` as two `float4` chunks, widening each BF16 pair with an exponent-preserving bit shift. `decode_rows`, `decode_kernel`, `launch_decode` and `decode_impl` are templated on the output type; `nf12_decode_fp32` and the `nf12::decode_fp32` torch op expose it. * HIP mirrors it with `store_row_tile_fp32`, a templated `decode_rows`, `decode_nf12_matrix` shared by `nf12_decode` and `nf12_decode_fp32`, and a `nf12_hip::decode_fp32` torch op. Widening is exact, so the result is bit-identical to decoding BF16 and casting, including signed zero, subnormals, infinities and NaN payloads. FP32 traffic drops from 9.5 to 5.5 bytes per element. Measured on an RTX 4090 (median of seven trials): 2048x2048 15.23 us -> 12.45 us 1.22x 512x2048 10.59 us -> 6.49 us 1.63x 8192x2048 175.31 us -> 109.21 us 1.61x 2048x8192 175.50 us -> 109.75 us 1.60x Across the 112 Llama 3.2 1B projections the FP32 conversion falls from 9.08 ms to 5.77 ms (1.57x, 3.30 ms saved). On an R9700 the same shapes measure 1.37x to 2.41x. The AUTO_NF12 GPTQ checkpoint pair remains 482/482 tensors bit-identical. The GPTQ path keeps its BF16 module weight: that tensor is what W4A replay and the saved checkpoint require, so decoding FP32 from NF12 in place of widening the resident BF16 copy would add a packed buffer beside both dense tensors rather than remove one. The fused store targets FP32-only consumers.
|
Added in What was there What changed
Widening is exact, so the output is bit-identical to Measured, RTX 4090, median of seven trials, resident inputs
Across the 112 Llama 3.2 1B projections: 9.08 ms to 5.77 ms, 1.57x, 3.30 ms saved. R9700: 1.37x to 2.41x. Scope Validation
|
EoRA needs w - wq in FP32. Decoding the packed source and subtracting wq in the same widening store avoids materializing an FP32 copy of the source: nf12::sub_fp32 / nf12_hip.sub_fp32: out = widen(decode(W)) - wq The fused store is bit-identical to decode_fp32 - wq and peaks at 4 B/element instead of 8 B/element. Across the 112 Llama 3.2 1B projections plus the vocabulary projection the diff drops from 21.98 ms to 13.02 ms (1.69x) and 4,714 MiB of FP32 source traffic is never materialized. GPTQ keeps the packed source alive only when EoRA will consume the diff, and releases it immediately after. The EoRA stage forwards the quantized layer in the model tree instead of re-packing the restored dense source, and the layer inventory keeps the NamedModule so EoRA state survives. End-to-end GPTQ + EoRA on Llama 3.2 1B is 482/482 bit-identical model tensors and 224/224 bit-identical adapter tensors between AUTO_NF12 and OFF.
Fused EoRA weight diff (
|
Shape (N, K) |
Dense diff | Fused diff | Speedup | Peak saved |
|---|---|---|---|---|
512x2048 |
15.97 us | 18.24 us | 0.88x | 4 MiB |
2048x2048 |
25.86 us | 27.65 us | 0.94x | 16 MiB |
8192x2048 |
325.58 us | 184.22 us | 1.77x | 64 MiB |
2048x8192 |
324.66 us | 184.22 us | 1.76x | 64 MiB |
128256x2048 |
5,027.84 us | 2,712.77 us | 1.85x | 1,002 MiB |
Across the 112 Llama 3.2 1B projections plus the vocabulary projection: 21.98 ms -> 13.02 ms (1.69x), 4,714 MiB of FP32 source traffic avoided.
End-to-end GPTQ + EoRA on Llama 3.2 1B (rank 4, 4,096 WikiText tokens):
- 482/482 model tensors bit-identical between
AUTO_NF12andOFF - 224/224 adapter tensors bit-identical
- Both policies peak at 4,042.4 MiB: the fused store removes the FP32 source copy, so it does not add to the workspace-dominated peak
The EoRA stage no longer re-packs the restored dense source: it forwards the quantized layer in the model tree, and the layer inventory keeps the NamedModule so EoRA's w_wq_diff/wq state survives.
Validation
- CUDA
test_auto_dtype_cast.py: 31 passed - CUDA codec + NF12 API + config + weight-only: 202 passed, 10 skipped
- ROCm AutoDtypeCast + embedding + review + contracts: 559 passed, 3 skipped
- ROCm codec: 53 passed, 2 skipped
- CUDA and ROCm
PYTHON_GIL=0probes: PASS ruff check,git diff --check, Mermaid fences: PASS
The gptqmodel_floatx ABI exposes only dequantize_fp8_cpu and dequantize_fp4_cpu with BF16/FP16 target codes; NF12 to FP32 stays in the nf12 / nf12_hip namespace.
|
Reviewed all 10 commits through
For finding 2, invoking the real Validation on this head:
Runtime: Python 3.14.7t with GIL disabled, Torch 2.15.0.dev20260928+cu130, Transformers 5.20.2, NVIDIA SM80. ROCm, SM89/SM120 tuning, and full-model quality/performance were not executed in this review. |
The processor defined _w_wq_diff but process() still built the diff with the dense expression, so the fused NF12 store was never used. Route process() through the helper and add a source-contract regression. With the fused path active, GPTQ + EoRA on Llama 3.2 1B is still 482/482 bit-identical model tensors and 224/224 bit-identical adapter tensors, and both policies now peak at 4,042.4 MiB instead of AUTO_NF12 adding the retained packed source on top of the dense FP32 temporary.
- move_module_to_cpu_pinned now moves XPU/MPS/NPU/XLA tensors to CPU instead of returning them unchanged, restoring layer offload for non-CUDA accelerators. Meta tensors stay in place because they have no storage. - _w_wq_diff converts GPTQ's BF16/FP16 reconstruction to FP32 before calling the fused NF12 subtraction. The original wq stays untouched for replay and packing. Previously the helper rejected the source dtype and silently fell back to the dense expression. - Add a real GPTQProcessor.process regression with a BF16 reconstruction and a packed NF12 source, plus a FakeTensor offload-routing regression. Verified: 112/112 EoRA diffs use the fused FP32 path; GPTQ + EoRA on Llama 3.2 1B is 482/482 model and 224/224 adapter tensors bit-identical, with both policies peaking at 4,042.4 MiB.
|
Both findings are fixed in P1 — non-CUDA offload. P2 — fused diff wiring and dtype. wq_fp32 = wq if wq.dtype == torch.float32 else wq.to(dtype=torch.float32)
fused = fused_w_minus_wq(packed_source, wq_fp32)The original Added Production check on Llama 3.2 1B with a call counter: End-to-end GPTQ + EoRA (4,096 WikiText tokens):
Validation on
|
|
Follow-up review of The two findings in my earlier review are addressed: non-CUDA offload again routes to CPU, and the real GPTQ processing path now invokes the fused residual helper with an FP32 reconstruction operand while preserving the BF16/FP16 reconstruction used for replay and packing. I found no additional blocking correctness issue in this focused pass. The lifecycle changes below are a concrete enhancement proposal, not functionality already implemented by this PR. Make the producer/consumer contract part of the lifecycleThe ordered processor stages already provide the right execution model. Keep GPTQ and EoRA serial, and make their per-module dependency explicit. Today that dependency spans model flags I recommend extending the existing A proposed typed, transient
The planner should reject an EoRA stage without a compatible producer. A missing or already-consumed module handoff should produce a descriptive lifecycle error. Preserve producer-specific residual arithmetic: GPTQ uses FP32 here, while some other producers intentionally subtract in FP16. This contract should also accommodate the dequantization → EoRA adapter-generation path. Give each tensor and forward a defined owner
The current GPTQ residual helper, EoRA consumer, and GPTQ finalizer already implement important pieces of this contract. The enhancement is to express and validate those pieces centrally, replacing scattered stage-specific flags. Handoff storage should remain temporary quantization state; it should not become a persistent dense inference cache. Enforce finalization dependencies per module
For the proposed contract, run one ordered finalization chain per module: EoRA adapter finalization → producer packing → cleanup/offload. Different modules can still finalize concurrently. This is a dependency requirement for the refactor, not a demonstrated corruption bug in today's finalizers. Proposed lifecycle; not implemented by this PR: flowchart TD
A["QuantizationRunPlan validates producer and consumer"] --> B["GPTQProcessor.process: exact source to reconstruction"]
B --> C["Publish EoraHandoff; release packed source"]
C --> D["EoraProcessor: capture using reconstructed weights"]
D --> E["Consume residual; compute adapter"]
E --> F["Replay corrected live weights"]
F --> G["EoRA finalizes adapter"]
G --> H["GPTQ packs uncorrected reconstruction"]
H --> I["Release snapshot and offload"]
B -. "failure" .-> X["Abort module and release transient ownership"]
C -. "missing or invalid handoff" .-> X
E -. "failure" .-> X
Implementation should include lifecycle tests for native/fallback residual paths and BF16/exact-FP16 sources; snapshot independence and original-checkpoint reload prevention; dynamic skips and failure cleanup; delayed consumer finalization proving that producer packing waits; and checkpoint continuation plus multi-device placement. Validation performed
Recommendation: the immediate fixes are validated; make the next lifecycle change a declared producer/consumer handoff with explicit forward roles and per-module finalization dependencies. |
Upstream added the NF12 embedding and row-major operators (#3853), which touch the same HIP binding as the stable-ABI migration. The resolution keeps every new op and re-applies the stable-ABI conversion on top: the host TU includes only torch_stable_compat.h, allocates with the stable empty() instead of at::native::empty_cuda, uses std::vector instead of c10::SmallVector, and registers through STABLE_TORCH_LIBRARY with TORCH_BOX. at::cumsum/select/zero_ were added to the compat layer for the row-major pack path. Verified on ROCm 10.1 (R9700): nf12 HIP suites 196 passed, 4 skipped; row-major pack and embedding match the dense oracle; the built object has no unstable torch C++ symbols.
TL;DR
Add
BaseQuantizeConfig.auto_dtype_cast, defaulting toAUTO_NF12, so eligible BF16-compatible source matrices use lossless NF12 storage during calibration forwards. Restore the exact original dtype and bits before GPTQ/AWQ/RTN consumes the source. The change also adds native row-major embedding storage and kernels on CUDA and ROCm, short-M linear dispatch tuning, and the corresponding flow documentation and tests.The net change is 5,022 insertions and 293 deletions across 61 files. The core consequence is that the source can be packed during calibration without changing the bytes seen by the quantizer or retaining a dense source beside the packed representation.
1. Problem and old flow
Previously, every quantizable source matrix stayed dense during calibration. For BF16 source models this left the original weight resident while calibration forwards ran, even though NF12 can represent every BF16 bit exactly.
The old lifecycle was:
flowchart TD A["dense source module"] --> B["calibration forward"] B --> C["quantizer process"] C --> D["packed output"]The feature must preserve the quantizer handoff while changing the storage used by calibration. The main risk is that a packed forward could leave GPTQ/AWQ with a decoded or altered source instead of the exact input matrix.
2. New flow
flowchart TD A["dense source module"] --> B{"auto_dtype_cast"} B -- "OFF" --> C["dense source"] B -- "AUTO_NF12" --> D{"native floatx path validated?"} D -- "yes" --> C D -- "no" --> E{"eligible matrix and device?"} E -- "no" --> C E -- "yes" --> F["cast_source_module"] F --> G["packed NF12 forward"] G --> H["quantization task metadata retained"] H --> I["restore_source_module"] I --> J["exact source dtype and bits"] J --> K["GPTQ / AWQ / RTN process"] C --> KThe source policy is selected by config, never by an environment variable. Native FP8/FP4/MXFP4/MXFP8 execution takes precedence. A decoded floatx view is eligible for NF12. BF16 is eligible when the matrix shape and device are supported. FP16 is eligible only when FP16 -> BF16 -> FP16 preserves every bit, including signed zero.
3. Storage and reduction contracts
nf12.decode_fp32andnf12_hip.decode_fp32widen to FP32 in the decode store, so FP32 consumers never materialize a BF16 matrix.HookedLinearandAutoNF12HookedLinearshareprepare_hooked_linear_input; W4A replay and online Hadamard run exactly once before the packed GEMM and calibration hook capture.restore_source_modulerebuilds hooked sources asHookedLinearand shares the registered-hook registries plus online-rotation and W4A replay state, soRemovableHandle.remove()affects source, packed, and restored modules consistently.The storage and fallback flow is documented in Automatic NF12 source storage. Row-major embedding is documented in NF12 row-major embedding storage, HIP embedding dispatch in NF12 HIP embedding dispatch, reduction behavior in NF12 linear reduction association, and the M sweep in NF12 short-M dispatch.
4. Measured results
Lossless storage and numerical scope
NF12 storage and decoding are bit exact for BF16. Matrix multiplication is not generally bitwise identical because the NF12 kernels can associate FP32 partial sums differently from dense BF16 GEMM.
On RTX 4090, all 113/113 aligned projection weights restored bit exactly across 1,235,746,816 elements. Representative projection results were:
model.layers.0.self_attn.q_projmodel.layers.0.mlp.down_projlm_headThe full model retained identical next-token IDs, with maximum logits difference
0.21875and mean absolute difference0.023402199131775.The Llama embedding table decoded bit exactly, and 512/512 sampled lookup rows matched dense BF16 exactly. Its row-major packed representation occupied
394,365,297bytes instead of525,336,576bytes, a 24.93% reduction.Quantization memory and warm timing
The model was
unsloth/Llama-3.2-1B-Instruct, loaded as BF16. GPTQ calibration cast 112 projection matrices. Their dense BF16 source occupied 1,856.0 MiB; the NF12 representation occupied 1,394.532 MiB.The current RTX 4090 comparison used GPTQ 4-bit, group size 128, 8 WikiText windows of 512 tokens (4,096 calibration tokens), the same BF16 source, and the same held-out 4,096-token evaluation split. Model load and checkpoint save were excluded from the quantization timer.
AUTO_NF12OFFResident allocation after preparation was 18.88% lower with
AUTO_NF12. The end-to-end peak was equal because the cached 4K activation inputs and GPTQ workspace dominate it. Allocation history attributes the peak to a 512 MiB inverse factor, two 256 MiB damping/inverse temporaries, 64 MiB permutation storage, and additional quantization/activation buffers. With one 512-token block, the calibration-forward peak was 444.420 MiB withAUTO_NF12and 681.783 MiB withOFF.The first implementation copied each GPU weight to CPU, copied it back for native encoding, then copied the packed result to CPU and back to the GPU. It also allocated full zero NF12 buffers before overwriting them. That made 112 warm encodes take about 1.8 seconds and made
AUTO_NF12slower.The encoder now consumes the accelerator-resident BF16 source and installs the native result on that device. Warm encoding took 0.118522 seconds for all 112 modules, or 0.079967 seconds after excluding the first seven shape specializations. Median warm encoding was 0.478 ms per module. Warm median end-to-end quantization was 5.318339 s with
AUTO_NF12versus 5.500630 s withOFF, 3.43% faster. Against the prior implementation, absolute warm quantization time fell 9.47% forAUTO_NF12and 10.22% forOFF. The 10–15%AUTO_NF12-versus-OFFtarget was not reached: remaining time is dominated by GPTQ processing and its dense Hessian/inverse workspace, while all 112 native NF12 encodes now total about 0.12 seconds.All six final checkpoints, three per policy, contained 482 state tensors, and every corresponding tensor was bit identical. Both policies scored NLL
3.1000067591667175and perplexity22.198101321602206on the held-out split.The quantization path now also offloads completed layers through pinned CPU storage on CUDA/HIP; other accelerators keep the ordinary CPU move. Large D2H copies are queued in 64 MiB chunks on the existing device stream and synchronized once at the module boundary; small tensors stay pageable. Direct checkpoint-to-device loading was measured slower for large Llama tensors, and CPU-parallel NF12 encoding was not adopted because native encoding is already only about 0.12 seconds total.
SM89 M=512 calibration sweep
The four RTX 4090 sweep used serial verification to avoid PCIe and allocator contention. All selected schedules are bit-identical to the previous arithmetic:
(N, K)2048x2048512x20482048x8192The
8192x2048gate/up and128256x2048vocabulary projections already used their fastest tested schedules.Full-model logits and short-M linear dispatch
Token IDs matched dense on all devices. RTX 5090 retains rank-order reduction because its pairwise experiment increased both maximum and mean drift.
The paired M=1/4/8/16 benchmark uses resident inputs, seven warmed trials of 200 calls, and one synchronization after each trial. Selected results:
8192x20482048x81928192x20482048x81922048x8192128256x2048The R9700 long-K M16 split improved
2048x8192from approximately45.29 usto23.17 usduring tuning. Remaining slower cases are explicit in the short-M reference page, including RTX 4090 narrow shapes and R97008192x2048M4 and4096x4096M4/M8.NF12 to FP32 conversion
FP32 consumers used to decode BF16 and widen the dense matrix: 9.5 bytes moved per element and a BF16 copy that existed only to be cast.
nf12.decode_fp32andnf12_hip.decode_fp32now widen in the decode store, so FP32 traffic is 5.5 bytes per element and no BF16 matrix is materialized. The widening is an exponent-preserving bit shift, so the output is bit-identical todecode().float(), including signed zero, subnormals, infinities and NaN payloads.Measured on an RTX 4090, median of seven trials with resident inputs:
(N, K)decode_fp322048x2048512x20488192x20482048x8192Across the 112 Llama 3.2 1B projections the FP32 conversion falls from 9.08 ms to 5.77 ms, a 1.57x improvement and 3.30 ms saved. On an R9700 the same shapes measure 1.37x to 2.41x. The AUTO_NF12 checkpoint pair remains 482/482 tensors bit-identical after the change.
The GPTQ path keeps its BF16 module weight, because W4A replay and the saved checkpoint need that tensor; decoding FP32 from NF12 instead of widening the resident BF16 copy would add a packed buffer beside both dense tensors rather than remove one. The fused store targets FP32-only consumers.
Fused EoRA weight diff
EoRA consumes the FP32 difference between the source weight and GPTQ's reconstructed weight. The diff used to be built as
module.weight.data.float() - wq, which materializes a second full FP32 source matrix besidewqand the result.nf12::sub_fp32andnf12_hip.sub_fp32decode each super-atom and subtractwqin the same widening store, so the FP32 source is never written.GPTQ returns its reconstruction in the source dtype, so
_w_wq_diffconverts a copy to FP32 before calling the fused op; the original BF16/FP16wqstays untouched for replay and packing. A realGPTQProcessor.processregression covers the BF16 reconstruction path.The packed source is retained only when GPTQ and EoRA both run, and is released immediately after the diff is built. The EoRA stage forwards the quantized layer already in the model tree instead of re-packing the restored dense source, and the layer inventory keeps the
NamedModuleso EoRA's per-module state survives.wqreadMeasured on an RTX 4090 with resident inputs, median of 30 trials:
(N, K)512x20482048x20488192x20482048x8192128256x2048Across the 112 Llama 3.2 1B projections plus the vocabulary projection the diff falls from 21.98 ms to 13.02 ms (1.69x), and 4,714 MiB of FP32 source traffic is never materialized.
End-to-end GPTQ + EoRA on Llama 3.2 1B produced 482/482 bit-identical model tensors and 224/224 bit-identical adapter tensors between
AUTO_NF12andOFF. Both policies peaked at 4,042.4 MiB: the packed source stays resident through GPTQ's Hessian/inverse workspace, but the fused store removes the FP32 source copy, so the diff step no longer adds to the workspace-dominated peak.The FP32 conversion ABI is the
nf12/nf12_hiptorch namespace. The separategptqmodel_floatxABI exposes onlydequantize_fp8_cpuanddequantize_fp4_cpu, and its target dtype codes cover BF16 and FP16 only, so NF12 to FP32 was not added there.Embedding performance
The production embedding storage uses 96 packed bytes per 64-column row block plus the BF16 output write. Dense BF16 reads 128 bytes and writes 128 bytes; row-major NF12 reads 96 and writes 128, giving an ideal ceiling of
256 / 224 = 1.143xbefore decode and launch overhead.[512,5120][512,5120][512,5120][128256,2048][128256,2048]One-ID lookup remains launch and binding limited and is slower than dense, approximately 0.85-0.91x depending on device and wrapper. Multi-token lookup meets the 1.0x gate; the 1.2x target is above the row-major traffic ceiling for a one-ID lookup.
5. Batched-request semantics
For four one-token requests represented as
input_ids=[4,1], embedding receives four IDs and the flattened projection seesM=4. Four prefill requests of lengthLproduceM=4L. Ragged requests without padding see the sum of their processed token lengths. Padding tokens count unless the caller removes them.6. Change inventory
gptqmodel/quantization/config.py,gptqmodel/models/base.py,gptqmodel/looper/module_looper.py,gptqmodel/looper/stage_subset.py,gptqmodel/utils/auto_dtype_cast.py,gptqmodel/nn_modules/hooked_linear.py,gptqmodel/nn_modules/qlinear/nf12.pygptqmodel_ext/nf12/csrc/codec/tile.cuh,codec/decode.cu,api.cu,gptqmodel_ext/nf12_hip/nf12_format_hip.cuh,nf12_decode.hip,nf12_torch.cpp,gptqmodel_nf12/api.pygptqmodel_ext/nf12/csrc/torch/rowmajor_embedding.cu,gptqmodel_ext/nf12/csrc/torch/ops.cpp,gptqmodel_nf12/api.pygptqmodel_ext/nf12_hip/nf12_embedding.hip,nf12_rowmajor_embedding.hip,nf12_torch.cpp,nf12_wmma.hip,gptqmodel/utils/nf12_hip.pytests/test_auto_dtype_cast.py,tests/test_nf12_hip_embedding.py, shared embedding cases, docs underdocs/7. Failure and ambiguity contract
[0,N)produce+0.0rows, matching the existing CUDA contract.8. Validation
sub_fp32regressions cover exact equality withdecode_fp32 - wq, the fused path without a source materialization, the dense fallback, packed-storage release, and the EoRA forward skipdecode().float(), and a check that FP32 dequantize never calls the BF16 decode.PYTHON_GIL=0probe: PASSPYTHON_GIL=0probe: PASSruff check,git diff --check, and Mermaid fence validation: passed9. Reviewer notes and remaining limits
nn.Linear, calibrationHookedLinear, andnn.Embedding; norm vectors and biases stay dense.The draft PR contains commits
01739ce88,f77e4104d,ac5463f0e, review-fix commits95040b7c6andc7321933d, measured-evidence documentation commit11fb0204f, memory/encode performance fix1e6af2d31, SM89 calibration/offload performance commitdc03172b5, the FP32 widening-store commitc68d71271, the fused EoRA diff commite0f318fea, the fused-diff wiring fix68c661fce, and the review fixes26b3efe7e.