pub enum QTensor {
F32 {
data: Vec<f32>,
rows: usize,
cols: usize,
},
Mapped {
model: Arc<CmfModel>,
idx: usize,
dtype: TensorDtype,
rows: usize,
cols: usize,
row_scale: Vec<f32>,
col_field: Vec<f32>,
},
}Variants§
Implementations§
Source§impl QTensor
impl QTensor
pub fn from_f32(data: Vec<f32>, rows: usize, cols: usize) -> Self
Sourcepub fn from_model(model: &Arc<CmfModel>, name: &str) -> Result<Self, String>
pub fn from_model(model: &Arc<CmfModel>, name: &str) -> Result<Self, String>
Wrap a directory tensor without dequantizing the payload. Falls back to dequantized f32 for dtypes without a fused kernel.
pub fn rows(&self) -> usize
pub fn cols(&self) -> usize
Sourcepub fn as_f32(&self) -> Option<&[f32]>
pub fn as_f32(&self) -> Option<&[f32]>
Dense f32 view — only for owned tensors. Masked/sparse execution paths require it; quantized weights don’t support masks yet.
Sourcepub fn row_f32(&self, r: usize, dst: &mut [f32])
pub fn row_f32(&self, r: usize, dst: &mut [f32])
Dequantize one row into dst (embedding lookup).
Sourcepub fn sparse_col_ok(&self) -> bool
pub fn sparse_col_ok(&self) -> bool
Can this tensor’s columns be read cheaply (for sparse down_proj)? True for F32/Q8Row/Q8_2f (per-row scale, direct strided access); false for group-packed q4/vbit (column access would unpack whole groups — sparse execution falls back to f32 for those).
Sourcepub fn add_col_scaled(&self, c: usize, w: f32, out: &mut [f32])
pub fn add_col_scaled(&self, c: usize, w: f32, out: &mut [f32])
down_proj [hidden, inter]: accumulate w · col(c) into out
[hidden] — reads ONLY column c (one neuron) from the mmap,
no full-matrix dequant. out[k] += w · down[k, c].
Sourcepub fn row_dot(&self, r: usize, x: &[f32], scratch: &mut [f32]) -> f32
pub fn row_dot(&self, r: usize, x: &[f32], scratch: &mut [f32]) -> f32
Dot of row r with x (gate/up active-neuron path). Reads only
row r from the mmap — no full dequant. q4/vbit dequant the row
into scratch first (rare for active-FFN weights).
Source§impl QTensor
impl QTensor
Sourcepub fn matmat(
&self,
xs_all: &[f32],
b: usize,
out: &mut [f32],
pool: Option<&Pool>,
)
pub fn matmat( &self, xs_all: &[f32], b: usize, out: &mut [f32], pool: Option<&Pool>, )
Batched matvec (prefill-GEMM): xs — row-major [b, cols], out — row-major [b, rows]. Element-wise semantics are IDENTICAL to b matvec calls (same dot kernels in the same order); the win — the weight row streams from DRAM once per batch, not b times.