pub enum WeightQuantFormat {
Bf16,
Fp8PerRow,
Fp8BlockScaled,
Fp8SingleScale,
Nvfp4,
Mxfp4E8m0,
PackedQ2_0,
}Expand description
Runtime tag for the actual quantization format of a weight buffer in
GPU memory. Distinct from on-disk format (which Nvfp4Variant describes).
Used to assert at kernel-call sites that the weight matches what the
kernel expects — preventing silent leaks like FP8-block-scaled data
being passed through a NVFP4 GEMM, or single-scale FP8 being passed
through a kernel that expects per-row scales.
Phase 2c day-3 follow-up (2026-05-24): introduced after the audit at
bench/phase2c-kv-sweep/CAUSAL-PATHWAY-AUDIT.md found that block-scaled
FP8 weights from disk were being silently stuffed into the row_scale
field of Fp8Weight (which documents itself as per-row F32), causing
either crashes (when concat math read past the smaller block-scale
tensor) or — if the concat dimension happened to fit — silent precision
loss because downstream kernels (fp8_gemm_n128) take no scale arg
and assume single-scale FP8.
Variants§
Bf16
BF16 dense — no quantization. Kernel must consume BF16 inputs.
Fp8PerRow
FP8 E4M3 weight + per-row F32 dequant scale ([N] f32).
Produced by runtime quantization from BF16 (Fp8DenseWeight)
or by checkpoints that ship per-row scales.
Consumed by w8a16_gemv / w8a16_gemm.
Fp8BlockScaled
FP8 E4M3 weight + per-block BF16 dequant scale ([N/BS, K/BS] BF16).
Standard Qwen-team FP8 release format (BS=128). NO Atlas kernel
currently consumes this directly for SSM — kernels expect either
dequant-to-BF16-then-NVFP4 (current path) or single-scale FP8.
Block-scaled FP8 GEMV/GEMM is the missing kernel (open task).
Fp8SingleScale
FP8 E4M3 weight with a single global scale baked into the kernel
(or implicit). Produced by bf16_to_fp8 from a BF16 dense.
Consumed by fp8_gemm_n128 (takes no scale argument).
Nvfp4
NVFP4: packed E2M1 nibbles + per-group FP8 block scales + per-tensor
F32 scale. Consumed by w4a16_gemv, w4a16_gemm, and variants.
Mxfp4E8m0
Native MXFP4 (OCP micro-scaling): packed E2M1 nibbles + per-block
E8M0 power-of-2 scales (GROUP_SIZE=32), no per-tensor global.
This is DeepSeek-V4-Flash’s ORIGINAL on-disk routed-expert format. The
bytes are landed device-resident UNCHANGED (transcode-free) — the
scale byte is a biased exponent, effective scale 2^(byte-127).
Consumed by the E8M0 variants of the MoE grouped/decode GEMMs
(Phase-K lane); feeding these bytes through an Nvfp4 kernel (which
reads the scale as FP8-E4M3 per-16 and applies a global) = silent
garbage — assert with WeightQuantFormat::expect at the dispatch site.
PackedQ2_0
Keep-packed PrismML ternary Q2_0 (ggml id 42): raw block_q2_0 blocks
(fp16 inline scale + 2-bit codes per group), dequantized in-kernel by the
native q2_0_gemv decode GEMV. Consumed only by that kernel — feeding
these bytes through any other GEMV/GEMM is silent garbage.
Implementations§
Source§impl WeightQuantFormat
impl WeightQuantFormat
Sourcepub fn expect(self, expected: WeightQuantFormat, context: &str)
pub fn expect(self, expected: WeightQuantFormat, context: &str)
Assert that self matches expected; panic with a descriptive
message if not. Used at kernel-call sites to prevent silent leaks
of one quant format into a kernel that expects a different one.
Trait Implementations§
Source§impl Clone for WeightQuantFormat
impl Clone for WeightQuantFormat
Source§fn clone(&self) -> WeightQuantFormat
fn clone(&self) -> WeightQuantFormat
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for WeightQuantFormat
impl Debug for WeightQuantFormat
Source§impl PartialEq for WeightQuantFormat
impl PartialEq for WeightQuantFormat
impl Copy for WeightQuantFormat
impl Eq for WeightQuantFormat
impl StructuralPartialEq for WeightQuantFormat
Auto Trait Implementations§
impl Freeze for WeightQuantFormat
impl RefUnwindSafe for WeightQuantFormat
impl Send for WeightQuantFormat
impl Sync for WeightQuantFormat
impl Unpin for WeightQuantFormat
impl UnwindSafe for WeightQuantFormat
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.