pub struct QuantizedWeight {
pub weight: DevicePtr,
pub weight_scale: DevicePtr,
pub weight_scale_2: f32,
pub input_scale: DevicePtr,
pub weight_scale_2_vec: DevicePtr,
pub act: Nvfp4Act,
}Expand description
2026-09-25: 4-bit quantized weight: packed E2M1 data, per-group scales and a host-side per-tensor scale.
Fields§
§weight: DevicePtr2026-09-25: Packed E2M1 weights, 2 per byte.
weight_scale: DevicePtr2026-09-25: Per-group scales: FP8 for NVFP4, E8M0 for native MXFP4.
weight_scale_2: f322026-09-25: Per-tensor scale, held on the host.
input_scale: DevicePtr2026-09-25: Input activation scale on the device, or NULL.
weight_scale_2_vec: DevicePtr2026-09-25: Per-row scale2 on the device, or NULL. The loaders in this module always set NULL; the transposes copy it through.
act: Nvfp4Act2026-09-28: The activation format the weight-quantization policy set for this weight
(metrale_config::WeightQuantPolicy::nvfp4_act). Unstamped unless a loader asks the
policy; derived copies (transposes, concatenations, TP shards) carry it through.
Implementations§
Source§impl QuantizedWeight
impl QuantizedWeight
Sourcepub fn transpose_for_gemm(
&self,
gpu: &dyn GpuBackend,
n: usize,
k: usize,
) -> Result<QuantizedWeight>
pub fn transpose_for_gemm( &self, gpu: &dyn GpuBackend, n: usize, k: usize, ) -> Result<QuantizedWeight>
2026-09-25: Transpose the packed weight [N, K/2] to [K/2, N] and the
scales [N, K/16] to [K/16, N], into new buffers.
Sourcepub fn transpose_for_gemm_gs(
&self,
gpu: &dyn GpuBackend,
n: usize,
k: usize,
group_size: usize,
) -> Result<QuantizedWeight>
pub fn transpose_for_gemm_gs( &self, gpu: &dyn GpuBackend, n: usize, k: usize, group_size: usize, ) -> Result<QuantizedWeight>
2026-09-25: transpose_for_gemm with an explicit scale block size. The scale
tensor is [N, K/group_size]; the packed-weight transpose does not depend on it.
Sourcepub fn transpose_concat_for_gemm(
gpu: &dyn GpuBackend,
parts: &[(&QuantizedWeight, usize)],
k: usize,
) -> Result<QuantizedWeight>
pub fn transpose_concat_for_gemm( gpu: &dyn GpuBackend, parts: &[(&QuantizedWeight, usize)], k: usize, ) -> Result<QuantizedWeight>
2026-09-25: Transpose several weights (weight, n) sharing one K and
concatenate them along N into one [K/2, N_total] twin, so one GEMM
replaces several.
The result carries the first part’s weight_scale_2, input_scale and
weight_scale_2_vec, so the caller must ensure every part shares them;
nothing here checks. An empty parts is an error.
Sourcepub fn transpose_concat_for_gemm_padded(
gpu: &dyn GpuBackend,
parts: &[(&QuantizedWeight, usize)],
k: usize,
group_size: usize,
align: usize,
) -> Result<(QuantizedWeight, usize)>
pub fn transpose_concat_for_gemm_padded( gpu: &dyn GpuBackend, parts: &[(&QuantizedWeight, usize)], k: usize, group_size: usize, align: usize, ) -> Result<(QuantizedWeight, usize)>
2026-09-25: transpose_concat_for_gemm_gs with the output row stride
padded to align_up(n_total, align) and the pad columns zeroed.
Row r of the result starts at byte r * stride, and the tile GEMM reads
B with 16-byte cp.async, which needs 16-byte aligned rows; an N such as
an odd vocab size is not. Returns (weight, stride); pass the stride to
w4a16_gemm_n128_ldb.
Sourcepub fn transpose_concat_for_gemm_gs(
gpu: &dyn GpuBackend,
parts: &[(&QuantizedWeight, usize)],
k: usize,
group_size: usize,
) -> Result<QuantizedWeight>
pub fn transpose_concat_for_gemm_gs( gpu: &dyn GpuBackend, parts: &[(&QuantizedWeight, usize)], k: usize, group_size: usize, ) -> Result<QuantizedWeight>
2026-09-25: transpose_concat_for_gemm with an explicit scale block size.
Source§impl QuantizedWeight
impl QuantizedWeight
Sourcepub fn has_per_row_scale2(&self) -> bool
pub fn has_per_row_scale2(&self) -> bool
2026-09-25: True when weight_scale_2_vec is not NULL.
Sourcepub fn concat_rows(
&self,
other: &QuantizedWeight,
n1: usize,
n2: usize,
k: usize,
gpu: &dyn GpuBackend,
) -> Result<QuantizedWeight>
pub fn concat_rows( &self, other: &QuantizedWeight, n1: usize, n2: usize, k: usize, gpu: &dyn GpuBackend, ) -> Result<QuantizedWeight>
2026-09-25: Concatenate two NVFP4 weights by rows into new buffers:
[N1, K/2] + [N2, K/2] → [N1+N2, K/2], with group size 16.
Both must have the same K, which the caller guarantees. Their
weight_scale_2 must be bit-identical, or it returns an error, because
the result carries self’s scale for every row. The result has NULL
input_scale and weight_scale_2_vec.
Sourcepub fn predequant_to_fp8(
&self,
gpu: &dyn GpuBackend,
predequant_kernel: KernelHandle,
n: usize,
k: usize,
stream: u64,
) -> Result<DevicePtr>
pub fn predequant_to_fp8( &self, gpu: &dyn GpuBackend, predequant_kernel: KernelHandle, n: usize, k: usize, stream: u64, ) -> Result<DevicePtr>
2026-09-25: Dequantize this NVFP4 weight [n, k] into a new FP8 E4M3
buffer [n, k] with weight_scale_2 applied, for prefill GEMMs that read
FP8. It synchronizes stream before returning.
Trait Implementations§
Source§impl Clone for QuantizedWeight
impl Clone for QuantizedWeight
Source§fn clone(&self) -> QuantizedWeight
fn clone(&self) -> QuantizedWeight
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more