Documentation
¶
Index ¶
- func Dense(x, weight, bias *Node, activation ...activations.Type) *Node
- func LayerNorm(x *Node, axes []int, epsilon float64, gamma, beta, mask *Node) *Node
- func QuantizedDense(x, weights *Node, quant *Quantization, bias *Node, ...) *Node
- func QuantizedGather(table, indices *Node, quant *Quantization) *Node
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dense ¶
func Dense(x, weight, bias *Node, activation ...activations.Type) *Node
Dense performs a dense (linear) transformation with optional activation:
y = activation(x @ weight + bias)
weight has shape [in_features, out_features...]. bias is optional (nil means no bias). x's last axis contracts with weight's first axis.
activation is optional; if omitted or activations.TypeNone, no activation is applied.
If the backend supports fused Dense, the optimized native implementation is used; otherwise the operation is decomposed into primitives. Fallback is handled automatically via InternalFusedOpCaller.
func LayerNorm ¶
LayerNorm performs layer normalization on x over the given axes with the specified epsilon. gamma and beta are optional (nil means skip scale/shift). mask is optional (nil means no masking). When a mask is provided, the decomposed path is always used (fused ops don't support masking).
If the backend supports fused LayerNorm, the optimized native implementation is used; otherwise the operation is decomposed into primitives. Fallback is handled automatically via InternalFusedOpCaller.
func QuantizedDense ¶
func QuantizedDense(x, weights *Node, quant *Quantization, bias *Node, activation ...activations.Type) *Node
QuantizedDense performs a quantized dense (linear) transformation with optional activation:
y = activation(x @ dequant(weights, quant) + bias)
The weights are dequantized on the fly using the quantization metadata, then multiplied with x.
Parameters:
- x: [batch..., K] float32 input activations.
- weights: [K, N] with dtype reflecting storage type (e.g. Int4, Int8). For sub-byte types, Bitcast packed uint8 data to the correct dtype first.
- quant: quantization metadata (scheme, scale, zeroPoint, blockAxis, blockSize).
- bias: [N] float32 (nil means no bias).
- activation: optional; if omitted or activations.TypeNone, no activation is applied.
If the backend supports fused QuantizedDense, the optimized native implementation is used; otherwise the operation is decomposed into primitives. Fallback is handled automatically via InternalFusedOpCaller.
func QuantizedGather ¶ added in v0.27.3
func QuantizedGather(table, indices *Node, quant *Quantization) *Node
QuantizedGather performs a quantized embedding lookup: gathers rows from a quantized embedding table and dequantizes only the selected rows on-the-fly.
This is the quantized analogue of graph.Gather for embedding lookups, similar to llama.cpp's ggml_get_rows. The full embedding table stays in native quantized format and only the rows selected by indices are dequantized to float32.
Types with a decomposed graph-level fallback (Q4_0, Q8_0, IQ4_NL) work on any backend (including XLA). K-quant types (Q4_K, Q6_K, etc.) require a backend with a fused executor (e.g. simplego); other backends will panic.
Parameters:
- table: [vocabSize, bytesPerRow] Uint8 with native GGML block layout.
- indices: integer tensor with last dimension = 1 (same as Gather convention). For embeddings: [batch, seqLen, 1].
- quant: quantization metadata. Only QuantGGML scheme is supported.
Output: float32 tensor with shape [batch..., K] where K is the logical embedding dimension derived from the block format: K = (bytesPerRow / bytesPerBlock) * valuesPerBlock.
Types ¶
This section is empty.