ggml

package
v0.28.39 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ggml provides graph-level decomposed dequantization and row quantization for GGML block formats.

These functions express all 12 supported GGML formats (Q4_0, Q4_1, Q5_0, Q5_1, Q8_0, IQ4_NL, Q2_K, Q3_K, Q4_K, Q5_K, Q6_K, Q8_K) as standard graph primitives (Bitcast, BitwiseAnd, BitwiseShiftRightLogical, Slice, ConvertDType, etc.) so that any backend — including XLA for CPU/GPU — can execute them. The "go" backend uses faster fused SIMD implementations when available; these decomposed versions serve as the automatic fallback via InternalFusedOpCaller.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActivationQuantTypeFor added in v0.28.35

func ActivationQuantTypeFor(weightType compute.GGMLQuantType) (compute.GGMLQuantType, bool)

ActivationQuantTypeFor returns the paired GGML activation quantization format (GGMLQ8_0 for 32-value weight formats such as Q4_0/Q8_0/IQ4_NL; GGMLQ8_K for 256-value K-quant weight formats Q2_K..Q8_K) used for block-integer dot products.

func CanDecompose

func CanDecompose(t compute.GGMLQuantType) bool

CanDecompose returns true for GGML quantization types that have a graph-level decomposed implementation (all 12 supported GGML types: Q4_0, Q4_1, Q5_0, Q5_1, Q8_0, IQ4_NL, Q2_K, Q3_K, Q4_K, Q5_K, Q6_K, Q8_K).

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 (e.g. Q4_0, Q8_0, IQ4_NL, Q4_K, Q6_K).
  • 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 * bytesPerRow] 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 GatherDecomposed added in v0.28.37

func GatherDecomposed(table, indices *Node, ggmlType compute.GGMLQuantType) *Node

GatherDecomposed 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 static batch dimensions and last dimension = 1 (Gather convention).
  • ggmlType: the GGML block format (e.g. Q4_0, Q8_0, IQ4_NL, Q4_K, Q6_K).

Output: Float32 tensor with shape [batch..., K] where K is the logical embedding dimension.

func Quantize added in v0.28.35

func Quantize(x *Node, ggmlType compute.GGMLQuantType) *Node

Quantize quantizes floating-point activations x of shape [batch..., K] into packed Uint8 GGML blocks of shape [batch..., bytesPerRow] for GGMLQ8_0 (34 bytes per 32 values) or GGMLQ8_K (292 bytes per 256 values).

The returned node can be shared across multiple nn.QuantizedDense projections (e.g. Q, K, V or Gate, Up in a GGUF Transformer block) by setting:

XQuantization: &graph.Quantization{Scheme: compute.QuantGGML, GGMLType: ggmlType}

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL