TensorEncoding

sealed interface TensorEncoding(source)

Physical storage encoding — how tensor data is laid out in memory.

A TensorEncoding describes the byte-level format of a buffer, independent of the logical numeric type (LogicalDType). For example, a FLOAT32 tensor may be stored as Dense (4 bytes per element) or as Q4_K (packed 4-bit blocks with per-block scales).

Encodings are sealed so that pattern-matching in loaders and backends is exhaustive and compiler-checked.

Inheritors

Types

Link copied to clipboard
data class Dense(val bytesPerElement: Int) : TensorEncoding

Dense element-per-slot layout. One element occupies a fixed number of bytes.

Link copied to clipboard
data class Opaque(val name: String, val rawBytes: Long) : TensorEncoding

Opaque / unknown encoding. Used as a fallback for formats the runtime cannot yet interpret but still wants to carry through without error.

Link copied to clipboard
data object Q4_K : TensorEncoding

GGML Q4_K block quantization: 256 elements per 144-byte block.

Link copied to clipboard
data object Q8_0 : TensorEncoding

GGML Q8_0 block quantization: 32 elements per 34-byte block.

Link copied to clipboard

Ternary encoding: 2 bits per element, packed 4 elements per byte.

Link copied to clipboard
data class TurboQuantPolar(val bitsPerElement: Int = 4, val blockSize: Int = 128) : TensorEncoding

TurboQuant PolarOnly encoding: rotation + scalar quantization + bit-packing.

Link copied to clipboard
data class TurboQuantPolarQjl(val bitsPerElement: Int = 4, val residualBits: Int = 1, val blockSize: Int = 128) : TensorEncoding

TurboQuant PolarPlusQjl encoding: rotation + scalar quantization + QJL residual + bit-packing.

Properties

Link copied to clipboard
abstract val name: String

Human-readable name for diagnostics and memory reports.

Functions

Link copied to clipboard
abstract fun physicalBytes(elementCount: Long): Long?

Physical bytes required to store elementCount logical elements in this encoding, or null if the encoding is opaque/variable.