Documentation
¶
Overview ¶
Package ggml provides graph-level decomposed dequantization for GGML block formats.
These functions express GGML dequantization (Q4_0, Q8_0, IQ4_NL) as standard graph primitives (Bitcast, BitwiseAnd, ShiftRightLogical, Slice, ConvertDType, etc.) so that any backend — including XLA for GPU — can execute them. The simplego backend uses faster fused SIMD implementations when available; these decomposed versions serve as the automatic fallback via InternalFusedOpCaller.
Index ¶
- func CanDecompose(t compute.GGMLQuantType) bool
- func DenseDecomposed(x, weights *Node, ggmlType compute.GGMLQuantType, bias *Node, ...) *Node
- func Dequantize(weights *Node, ggmlType compute.GGMLQuantType, N int) *Node
- func EmbeddingLookupDecomposed(table, indices *Node, ggmlType compute.GGMLQuantType) *Node
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CanDecompose ¶
func CanDecompose(t compute.GGMLQuantType) bool
CanDecompose returns true for GGML quantization types that have a graph-level decomposed implementation (Q4_0, Q8_0, IQ4_NL).
func DenseDecomposed ¶
func DenseDecomposed(x, weights *Node, ggmlType compute.GGMLQuantType, bias *Node, optionalActivation ...activation.Type) *Node
DenseDecomposed performs quantized dense (linear) transformation using graph-level dequantization of GGML block-format weights.
It computes y = activation(x @ dequant(weights) + bias).
Parameters:
- x: [batch..., K] Float32 input activations.
- weights: [N, bytesPerRow] Uint8 in native GGML block layout.
- ggmlType: the GGML block format (Q4_0, Q8_0, IQ4_NL).
- bias: [N] Float32 (nil for no bias).
- activation: optional activation function.
func Dequantize ¶
func Dequantize(weights *Node, ggmlType compute.GGMLQuantType, N int) *Node
Dequantize dequantizes GGML block-format weights to [N, K] Float32 using graph primitives.
weights is shaped [N, numBlocks * bytesPerBlock] Uint8 in native GGML block layout, where N is the number of output rows (output features for dense, vocab size for embedding lookup). K is the logical feature dimension: K = numBlocks * valuesPerBlock, and is fixed per quantization type (e.g. Q4_0 has 32 values per 18-byte block).
N is passed explicitly rather than inferred from weights.Shape() because the caller may have reshaped gathered rows into [totalRows, bytesPerRow] where totalRows differs from the original table's first dimension.
func EmbeddingLookupDecomposed ¶
func EmbeddingLookupDecomposed(table, indices *Node, ggmlType compute.GGMLQuantType) *Node
EmbeddingLookupDecomposed performs a quantized embedding lookup using graph-level dequantization.
It gathers raw Uint8 rows from the quantized table, then dequantizes only the selected rows to Float32.
Parameters:
- table: [vocabSize, bytesPerRow] Uint8 with native GGML block layout.
- indices: integer tensor with last dimension = 1 (Gather convention).
- ggmlType: the GGML block format (Q4_0, Q8_0, IQ4_NL).
Output: Float32 tensor with shape [batch..., K] where K is the logical embedding dimension.
Types ¶
This section is empty.