Skip to main content

Module ops_fn

Module ops_fn 

Source
Expand description

Convenience functions for tensor operations

Functions§

add
attention
causal_mask
Create a causal attention mask (lower triangular)
causal_sliding_window_mask
Create a combined causal + sliding window mask This is the typical mask used in Mistral/Mixtral
clamp
Clamp values to a range
concat
conv1d
1D convolution
embedding
exp
flash_attention
Fused scaled dot-product attention (Flash Attention pattern) Computes: softmax(Q @ K^T / sqrt(d_k)) @ V Works for: LLaMA, Qwen, Gemma, Mistral, Phi, and all attention-based models
fused_residual_rms_norm
Fused residual add + RMS normalization Computes: rms_norm(residual + hidden, weight, eps) Used by: All transformer models with pre-normalization
fused_swiglu
Fused SwiGLU activation: silu(gate) * up Used by: LLaMA, Qwen, Mistral, and other modern transformer MLPs
gather
Gather elements along dimension
gelu
layer_norm
matmul
mul
normalize
randn
rms_norm
scale
scatter
Scatter elements along dimension
sigmoid
Sigmoid activation
silu
sliding_window_mask
Create a sliding window attention mask Returns a mask where 1.0 means “attend” and 0.0 means “don’t attend” Each position can only attend to positions within window_size positions before it
softmax
Softmax along specified dimension
sub
Element-wise subtraction
tanh
Tanh activation
topk
Top-k operation
transpose
Transpose tensor (swap last two dimensions)
transpose_dims
Transpose tensor with specific dimensions
zeros