Skip to main content

FastOp

Enum FastOp 

Source
#[non_exhaustive]
pub enum FastOp {
Show 20 variants RmsNorm { eps: u32, }, AddRmsNorm { eps: 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, }, DepthwiseConv1d { stride: usize, padding: usize, dilation: usize, }, PagedAttention { scale: u32, window: u32, sinks: bool, }, PagedWrite, 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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

RmsNorm

(x, w): x / sqrt(mean(x²) + eps) · w over the last axis; w is 1-D or a scalar 1.

Fields

§eps: u32

f32::to_bits of epsilon.

§

AddRmsNorm

(x, r, w): h = x + r and FastOp::RmsNorm of h (see add_rms_norm).

Fields

§eps: u32

f32::to_bits of epsilon.

§

RmsNormVjp

(x, w, g): the gradients of FastOp::RmsNorm for x and w.

Fields

§eps: u32

f32::to_bits of epsilon.

§

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.

Fields

§eps: u32

f32::to_bits of epsilon.

§

LayerNormVjp

(x, w, b, g): the gradients of FastOp::LayerNorm for x, w and b.

Fields

§eps: u32

f32::to_bits of epsilon.

§

Rope

(x, offset[, freqs]): rotary position embeddings of the first dims features.

Fields

§dims: usize

Rotated features (even).

§traditional: bool

Rotate interleaved pairs instead of the two halves.

§base: u32

f32::to_bits of the frequency base (unused with freqs).

§scale: u32

f32::to_bits of the position scale.

§forward: bool

Rotate forwards (false: the inverse rotation, the gradient).

§

NormRope

([cache,] x, w[, freqs]): norm_rope: each [b, h, l] row of x RMS-normalised (with eps) and rotated as FastOp::Rope at position offset + l; written into cache at the same positions, or returned as a new [B, H, L, D] array.

Fields

§eps: Option<u32>

f32::to_bits of epsilon, or no normalisation.

§dims: usize

Rotated features (even).

§traditional: bool

Rotate interleaved pairs instead of the two halves.

§base: u32

f32::to_bits of the frequency base (unused with freqs).

§scale: u32

f32::to_bits of the position scale.

§offset: usize

The position of the first row.

§cache: bool

Whether the first input is a cache written at the rows’ positions.

§

DepthwiseConv1d

(x, w): conv1d with groups equal to the channels (depthwise).

Fields

§stride: usize

Positions between outputs.

§padding: usize

Zeros before and after the input.

§dilation: usize

Positions between taps.

§

PagedAttention

(q, k_cache, v_cache, block_tables, lengths[, sinks]): paged_attention.

Fields

§scale: u32

f32::to_bits of the score scale.

§window: u32

A sliding window of this many keys (0: none).

§sinks: bool

Whether per-head attention sinks ([Hq]) are the last input.

§

PagedWrite

(cache, new, slots): paged_write.

§

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.

Fields

§rows: u32

Rows per block.

§

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

§scale: u32

f32::to_bits of the score scale.

§causal: bool

Causal masking (keys after the query’s position, aligned at the end, are hidden).

§mask: bool

Whether an array mask (bool or additive, [B, Hq, Lq, Lk]) is the fourth input.

§sinks: bool

Whether per-head attention sinks ([Hq]) are the last input.

§window: u32

A sliding window of this many keys (0: none; needs causal).

§passes: u8

The vector kernels’ passes over the keys (1 or 2; at most 8 queries), or 0 for the tiled kernel. Set by the attention plan.

§blocks: u32

Key partitions of the first of two vector passes.

§gqa_kernel: bool

The decode-only grouped-query two-pass kernel (one query, no mask or sinks).

§tk1: bool

The one-key-per-step variant of the two-pass kernel.

§

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).

Fields

§steps: bool

The state after every step ([B, T, Hv, Dv, Dk]) instead of the final one.

§

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.

Fields

§quant: Quant

The mode, group size and bits.

§transpose: bool

x · wᵀ (else x · w).

§global_scale: bool

Whether a global scale is given.

Trait Implementations§

Source§

impl Clone for FastOp

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FastOp

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for FastOp

Source§

impl Hash for FastOp

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for FastOp

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for FastOp

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AutoreleaseSafe for T
where T: ?Sized,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.