Documentation
¶
Index ¶
- func FusedAttentionQKVProjection(f *gobackend.Function, x, wQKV, biasQ, biasK, biasV compute.Value, ...) (queryOut, keyOut, valueOut compute.Value, err error)
- func FusedDense(f *gobackend.Function, x, weight, bias compute.Value, ...) (compute.Value, error)
- func FusedGelu(f *gobackend.Function, x compute.Value, exact bool) (compute.Value, error)
- func FusedLayerNorm(f *gobackend.Function, x compute.Value, axes []int, epsilon float64, ...) (compute.Value, error)
- func FusedQuantizedDense(f *gobackend.Function, x, weights, bias compute.Value, ...) (compute.Value, error)
- func FusedQuantizedDenseGGML(f *gobackend.Function, x, weights, bias compute.Value, ...) (compute.Value, error)
- func FusedScaledDotProductAttention(f *gobackend.Function, query, key, value compute.Value, ...) (output compute.Value, statesForVJP []compute.Value, err error)
- func FusedSoftmax(f *gobackend.Function, x compute.Value, axis int) (compute.Value, error)
- func QuantizedEmbeddingLookup(f *gobackend.Function, data, indices compute.Value, wq *compute.Quantization) (compute.Value, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FusedAttentionQKVProjection ¶
func FusedAttentionQKVProjection(f *gobackend.Function, x, wQKV, biasQ, biasK, biasV compute.Value, queryDim, keyValueDim int) (queryOut, keyOut, valueOut compute.Value, err error)
FusedAttentionQKVProjection performs fused Query-Key-Value projection.
The matmul (x @ wQKV) is delegated to DotGeneral, which selects the optimal execution path by a combination of build and runtime. The fused executor then splits the result into Q/K/V and adds biases.
func FusedDense ¶
func FusedDense(f *gobackend.Function, x, weight, bias compute.Value, options compute.DenseConfig) (compute.Value, error)
FusedDense performs fused matmul + optional bias + optional activation:
y = activation(x @ W + bias) (for DenseLayoutInputOutputs) y = activation(x @ W^T + bias) (for DenseLayoutOutputsInput)
The matmul is delegated to DotGeneral (which selects the optimal execution path at build time). FusedDense then adds bias and applies activation on top of the DotGeneral result.
func FusedGelu ¶
FusedGelu computes Gaussian Error Linear Unit activation. If exact is true, uses the exact GELU (erf); otherwise uses the tanh approximation.
func FusedLayerNorm ¶
func FusedLayerNorm(f *gobackend.Function, x compute.Value, axes []int, epsilon float64, gamma, beta compute.Value) (compute.Value, error)
FusedLayerNorm applies layer normalization.
func FusedQuantizedDense ¶
func FusedQuantizedDense( f *gobackend.Function, x, weights, bias compute.Value, weightsQuantization *compute.Quantization, activation compute.ActivationType) (compute.Value, error)
FusedQuantizedDense performs fused dequantization + matmul + optional bias + optional activation.
Unlike FusedDense, this does not create a DotGeneral sub-node — the quantized matmul is fundamentally different (mixed-dtype with per-group scales). The inputs to the executor are [x, weights, scales, zeroPoints?, bias?] directly.
Weights should have their dtype set to reflect the actual storage type (e.g. Int4, Int8). For sub-byte types, the caller should Bitcast packed byte data to the correct dtype.
func FusedQuantizedDenseGGML ¶
func FusedQuantizedDenseGGML(f *gobackend.Function, x, weights, bias compute.Value, wq *compute.Quantization, activation compute.ActivationType) (compute.Value, error)
FusedQuantizedDenseGGML handles the GGML path for FusedQuantizedDense. GGML weights are [N, bytesPerRow] Uint8 with native block layout. Scales and zero points are embedded in the blocks.
func FusedScaledDotProductAttention ¶
func FusedScaledDotProductAttention( f *gobackend.Function, query, key, value compute.Value, axesLayout compute.AttentionAxesLayout, options *compute.ScaledDotProductAttentionConfig) (output compute.Value, statesForVJP []compute.Value, err error)
FusedScaledDotProductAttention computes multi-head scaled dot-product attention.
output = softmax(query @ key^T * scale + mask) @ value, computed per-head with GQA support.
Inputs:
- query, key, value: 4D tensors whose axis ordering is determined by axesLayout. For AttentionAxesLayoutBHSD: query [batch, numHeads, seqLen, headDim], key/value [batch, numKVHeads, kvLen, headDim]. For AttentionAxesLayoutBSHD: query [batch, seqLen, numHeads, headDim], key/value [batch, kvLen, numKVHeads, headDim].
- mask: [seqLen, kvLen] (seqLen is the query sequence length): optional (can be nil) mask that can be either boolean or additive (any dtype other than Bool). See also causal below. Boolean mask: true = attend, false = ignore. Float/additive mask: added to scores before softmax. Must be broadcastable to the score tensor shape.
Parameters:
- numHeads: number of query attention heads
- numKVHeads: number of key/value attention heads (for GQA; numHeads must be divisible by numKVHeads)
- axesLayout: determines the axis ordering of query/key/value tensors
- scale: scaling factor applied to query @ key^T (typically 1/sqrt(headDim))
- causal: if true, apply causal (lower-triangular) mask. Callers (e.g. attention.Core) treat causal and mask as mutually exclusive, folding causal into the mask before calling this method when both are needed. Backends may assume they won't both be set.
- options: optional optimization hints (nil uses defaults). See ScaledDotProductAttentionConfig.
Output: same shape as query.
func FusedSoftmax ¶
FusedSoftmax computes softmax along the specified axis. The axis must be non-negative (the caller normalizes negative indices).
func QuantizedEmbeddingLookup ¶
func QuantizedEmbeddingLookup(f *gobackend.Function, data, indices compute.Value, wq *compute.Quantization) (compute.Value, error)
QuantizedEmbeddingLookup performs a quantized embedding lookup (row gather) with on-the-fly dequantization. data: [vocabSize, bytesPerRow] Uint8 with native GGML block layout. indices: integer tensor with last dim = 1 (same as Gather convention). Output: [batch..., K] Float32 where K is derived from the block format.
Types ¶
This section is empty.