pub trait QuantWeights: Send + Sync {
// Required methods
fn out_features(&self) -> u32;
fn in_features(&self) -> u32;
fn gemv(
&self,
gpu: &dyn GpuBackend,
x: DevicePtr,
y: DevicePtr,
stream: u64,
) -> Result<()>;
// Provided methods
fn gemv_gate_up_with(
&self,
other: &Self,
gpu: &dyn GpuBackend,
x: DevicePtr,
gate_y: DevicePtr,
up_y: DevicePtr,
stream: u64,
) -> Result<()>
where Self: Sized { ... }
fn gemv_silu_gate(
&self,
_gpu: &dyn GpuBackend,
_gate: DevicePtr,
_up: DevicePtr,
_y: DevicePtr,
_stream: u64,
) -> Result<()> { ... }
fn gemv_silu_gate_resid(
&self,
_gpu: &dyn GpuBackend,
_gate: DevicePtr,
_up: DevicePtr,
_x_resid: DevicePtr,
_y: DevicePtr,
_stream: u64,
) -> Result<()> { ... }
}Expand description
2026-09-25: A quantised [N, K] weight that runs matvecs on a GpuBackend.
The one implementation, for MlxInt8Weight, is in this file.
Required Methods§
Sourcefn out_features(&self) -> u32
fn out_features(&self) -> u32
2026-09-25: Output dimension N of the [N, K] weight.
Sourcefn in_features(&self) -> u32
fn in_features(&self) -> u32
2026-09-25: Input dimension K of the [N, K] weight.
Provided Methods§
Sourcefn gemv_gate_up_with(
&self,
other: &Self,
gpu: &dyn GpuBackend,
x: DevicePtr,
gate_y: DevicePtr,
up_y: DevicePtr,
stream: u64,
) -> Result<()>where
Self: Sized,
fn gemv_gate_up_with(
&self,
other: &Self,
gpu: &dyn GpuBackend,
x: DevicePtr,
gate_y: DevicePtr,
up_y: DevicePtr,
stream: u64,
) -> Result<()>where
Self: Sized,
2026-09-25: Dual-output GEMV over one input: gate_y = self @ x and
up_y = other @ x. The default is two gemv calls. The
MlxInt8Weight impl overrides it with the single
mlx_int8_gemv_gate_up launch.
where Self: Sized keeps this method off the dyn QuantWeights
surface; the forward modules call it through a generic parameter.
Sourcefn gemv_silu_gate(
&self,
_gpu: &dyn GpuBackend,
_gate: DevicePtr,
_up: DevicePtr,
_y: DevicePtr,
_stream: u64,
) -> Result<()>
fn gemv_silu_gate( &self, _gpu: &dyn GpuBackend, _gate: DevicePtr, _up: DevicePtr, _y: DevicePtr, _stream: u64, ) -> Result<()>
2026-09-25: Fused FFN tail y = self @ (silu(gate) ⊙ up). The default
returns an error; an implementation overrides it with a fused kernel
or its own composition.
Sourcefn gemv_silu_gate_resid(
&self,
_gpu: &dyn GpuBackend,
_gate: DevicePtr,
_up: DevicePtr,
_x_resid: DevicePtr,
_y: DevicePtr,
_stream: u64,
) -> Result<()>
fn gemv_silu_gate_resid( &self, _gpu: &dyn GpuBackend, _gate: DevicePtr, _up: DevicePtr, _x_resid: DevicePtr, _y: DevicePtr, _stream: u64, ) -> Result<()>
2026-09-25: Self::gemv_silu_gate with the residual add folded in:
y[n] = x_resid[n] + sum_k self[n, k] * (silu(gate[k]) ⊙ up[k]).
The default returns an error.