#[non_exhaustive]pub enum FastOp {
Show 24 variants
RmsNorm {
eps: u32,
},
AddRmsNorm {
eps: u32,
},
ResidualRmsNorm {
eps: u32,
scaled: bool,
next: Option<u32>,
},
RmsNormVjp {
eps: u32,
},
LayerNorm {
eps: u32,
},
LayerNormVjp {
eps: u32,
},
Rope {
dims: usize,
traditional: bool,
base: u32,
scale: u32,
forward: bool,
},
NormRope {
eps: Option<u32>,
dims: usize,
traditional: bool,
base: u32,
scale: u32,
offset: usize,
cache: bool,
positions: bool,
paged: bool,
},
DepthwiseConv1d {
stride: usize,
padding: usize,
dilation: usize,
},
PagedAttention {
scale: u32,
window: u32,
sinks: bool,
},
PagedWrite,
MoeRoute {
k: usize,
normalize: bool,
},
WeightedSum,
ConvSlots {
silu: bool,
},
Softmax,
CausalSoftmax {
rows: u32,
},
LogSumExp,
CrossEntropy,
CrossEntropyVjp,
Attention {
scale: u32,
causal: bool,
mask: bool,
sinks: bool,
window: u32,
passes: u8,
blocks: u32,
gqa_kernel: bool,
tk1: bool,
},
GatedDelta {
steps: bool,
},
GatedDeltaSlots,
GatherMm,
GatherQmm {
quant: Quant,
transpose: bool,
global_scale: bool,
},
}Expand description
A fused operation (see crate::fast).
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
RmsNorm
(x, w): x / sqrt(mean(x²) + eps) · w over the last axis; w is 1-D or a scalar 1.
AddRmsNorm
(x, r, w): h = x + r and FastOp::RmsNorm of h (see
add_rms_norm).
ResidualRmsNorm
(h, x, w[, scale][, w2]): s = (h + RmsNorm(x, w)) · scale and, with next,
FastOp::RmsNorm of s with w2 (see
residual_rms_norm).
Fields
RmsNormVjp
(x, w, g): the gradients of FastOp::RmsNorm for x and w.
LayerNorm
(x, w, b): (x - mean) / sqrt(var + eps) · w + b over the last axis; w and b
are 1-D or the scalars 1 and 0.
LayerNormVjp
(x, w, b, g): the gradients of FastOp::LayerNorm for x, w and b.
Rope
(x, offset[, freqs]): rotary position embeddings of the first dims features.
Fields
NormRope
([cache | pool, slots,] x, w[, positions][, freqs]):
norm_rope and norm_rope_at:
each [b, h, l] row of x RMS-normalised (with eps) and rotated as
FastOp::Rope at position offset + l (positions[b] + l with positions);
written into cache at the same positions, into pool at slots[b, l], or
returned as a new [B, H, L, D] array.
Fields
DepthwiseConv1d
(x, w): conv1d with groups equal to the channels (depthwise).
Fields
PagedAttention
(q, k_cache, v_cache, block_tables, lengths[, sinks]):
paged_attention.
Fields
PagedWrite
(cache, new, slots): paged_write.
MoeRoute
(probs): moe_route: the indices (uint32) of the k
largest probabilities along the last axis in the stable ascending order (as
argpartition), and those probabilities, divided by their sum if normalize.
WeightedSum
(x, w): weighted_sum: x ([..., k, D]) times w
([..., k]), summed over k.
ConvSlots
(x, w, pool, slots): causal_conv1d_slots: each
sequence’s state pool[slots[b]] then its new inputs, convolved depthwise (and
silu); the outputs and the pool with each slot’s last K − 1 inputs.
Softmax
(x): softmax over the last axis, accumulated in float32.
CausalSoftmax
(x): FastOp::Softmax of causally masked scores: row r of the second-to-last
axis (a multiple of rows long) keeps columns up to r % rows + L − rows (L the
last axis), the others taken as the dtype’s lowest finite value (MLX’s blocked
attention mask) and so 0 in the result.
LogSumExp
(x): log(sum(exp(x))) over the last axis, which becomes size 1.
CrossEntropy
(logits, targets): logsumexp(logits) - logits[target] per row, in float32.
CrossEntropyVjp
(logits, targets, loss, g): the gradient of FastOp::CrossEntropy for the logits.
Attention
(q, k, v[, mask][, sinks]): scaled dot-product attention (see
scaled_dot_product_attention).
Fields
GatedDelta
(q, k, v, g, beta, state): the gated delta rule (see
gated_delta), with the outputs and the final state (or
every step’s, gated_delta_steps).
GatedDeltaSlots
(q, k, v, g, beta, pool, slots): gated_delta_slots,
with the outputs and the updated pool.
GatherMm
(a, b, lhs_indices, rhs_indices[, offsets]): matrix products of gathered batches
(see gather_mm), as FastOp::GatherQmm in full precision.
GatherQmm
(x, w, scales[, biases][, global_scale], lhs_indices, rhs_indices[, offsets]):
quantized matrix products of gathered batches (see
gather_qmm); biases for affine only, a global scale
(float32, one per weight batch) for nvfp4 only. The indices are uint32 and broadcast
to the output’s batch shape. offsets (int32, one per batch of w) marks where each
weight batch’s rows start when the rows are sorted by it.
Trait Implementations§
impl Eq for FastOp
impl StructuralPartialEq for FastOp
Auto Trait Implementations§
impl Freeze for FastOp
impl RefUnwindSafe for FastOp
impl Send for FastOp
impl Sync for FastOp
impl Unpin for FastOp
impl UnsafeUnpin for FastOp
impl UnwindSafe for FastOp
Blanket Implementations§
impl<T> AutoreleaseSafe for Twhere
T: ?Sized,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more