Built-in codecs

A codec turns one chunk of one tensor into bytes and back. Its id has the form <name>/<version>, and an archive records the id and the full parameters of the codec of every tensor. The table and the sections below are generated from the codec registry. The dtypes column lists the dtypes that a codec encodes, and any other dtype raises UnsupportedDtypeError.

  • With no assigner, Jabara uses DefaultAssigner: bytegroup-zstd/1 for float16, bfloat16, float32, and float64, and zstd/1 for every other dtype.

  • A lossless codec decodes every chunk to the exact bytes it encoded.

  • An archive can use a lossy codec only when the caller passes allow_lossy=True. Otherwise write_archive raises LossyNotAllowedError. The archive records the largest absolute error of each lossy tensor in max_abs_err.

  • A codec that needs a base codes a tensor as its difference from the tensor with the same name, dtype, and shape in an earlier archive, the base. When the base has no such tensor, the writer uses the fallback of the CodecChoice, or raises MissingBaseError if there is none. Reading a delta tensor without its base raises MissingBaseError.

  • get_codec(codec_id, params) checks params against the codec's Params model and raises pydantic.ValidationError for an unknown or invalid parameter. A delta codec also builds its inner codec, so an unknown inner raises UnknownCodecError, and an inner codec that is lossy or needs a base raises ValueError.

Each codec section names the works the codec builds on, and how it relates to each. "wraps" means that the codec calls this library. "describes" means that the work describes the method or the format of a library that the codec wraps. "related" means that the work has the same idea, and the codec is this project's own and does not reproduce the work's method.

jabara codecs prints the codec ids. jabara codecs --long adds what this page gives for each codec and whether its extra is installed, jabara codecs ID shows one codec, and --json prints the same as JSON:

$ jabara codecs raw/1
raw/1: Stores the bytes unchanged.

type: lossless; needs no base; dtypes: every dtype; parameters: none

Codec

Type

Needs a base

Dtypes

Parameters and defaults

bytegroup-zstd/1

lossless

no

all

level = 3

quant8-linear/1

lossy

no

float16, bfloat16, float32, float64

level = 3

quant8-log/1

lossy

no

float16, bfloat16, float32, float64

level = 3

raw/1

lossless

no

all

none

sub-delta/1

lossless

yes

all except complex128

inner = "bytegroup-zstd/1", inner_params = {}

xor-delta/1

lossless

yes

all

inner = "bytegroup-zstd/1", inner_params = {}

zipnn/1

lossless

no

float16, bfloat16, float32

none

zstd/1

lossless

no

all

level = 3

Dtype names: bool, uint8, int8, uint16, int16, float16, bfloat16, uint32, int32, float32, uint64, int64, float64, complex64, complex128.

bytegroup-zstd/1

Class: jabara.codecs.builtin.ByteGroupZstdCodec.

Splits the chunk into one byte plane per item byte and compresses each plane with Zstandard. For one-byte items it is the same as zstd/1.

Parameters: level is the Zstandard compression level of every plane.

References:

quant8-linear/1

Class: jabara.codecs.quant.Quant8LinearCodec.

8-bit codes for 255 equal steps from the chunk minimum to its maximum.

Code c stands for lo + c * scale.

Per chunk, scale = (max - min) / 255 (the exact quotient). With tiny the smallest positive subnormal of the dtype, abs(x - x_hat) <= m * scale / 2 + 2**-48 * max(abs(x)) + tiny, where m is 1 for float64 and 2 for float16, bfloat16, and float32. No decoded value leaves [min, max]. A chunk whose items all have the same bits decodes exactly, -0.0 included.

Zeros keep no sign of their own. Entry 0 is lo, the chunk minimum, and no other entry is -0.0. When the minimum is zero, every zero gets code 0 and decodes to -0.0 if the chunk holds a -0.0, else to +0.0, so a chunk that mixes 0.0 and -0.0 decodes all its zeros to -0.0. When the minimum is negative, a zero decodes to +0.0 or to a nonzero value within the bound, so no zero decodes to -0.0.

Payload: the table size in bytes (uint16), the table (entry c is lo + c * scale kept inside [min, max] and rounded to the dtype, for c up to the largest code used), then the Zstandard-compressed codes.

Parameters: level is the Zstandard compression level of the 8-bit codes.

References:

quant8-log/1

Class: jabara.codecs.quant.Quant8LogCodec.

Logarithmic steps on the magnitude; the sign of every item is a separate packed bit plane.

Code 0 is the zero code: the item decodes to a signed zero. Codes 1 to 255 are 255 levels of ln(abs(x)) from the chunk's smallest to its largest nonzero magnitude, with step = (ln(max) - ln(min)) / 254; code c stands for exp(ln_min + (c - 1) * step). With step the exact quotient and m and tiny as for the linear codec, abs(x - x_hat) <= m * abs(x) * (exp(step / 2) - 1) + 2**-40 * abs(x) + tiny. No decoded magnitude leaves [min, max] of the nonzero magnitudes. Exact zeros, including -0.0, and every sign are kept exactly. Payload: the table size in bytes (uint16), the table of magnitudes in the dtype (entry 0 is zero), the packed sign plane (ceil(n / 8) bytes), then the Zstandard-compressed codes.

Parameters: level is the Zstandard compression level of the 8-bit codes.

References:

raw/1

Class: jabara.codecs.builtin.RawCodec.

Stores the bytes unchanged.

sub-delta/1

Class: jabara.codecs.delta.SubDeltaCodec.

Codes the wrap-around difference of the chunk and the base chunk, read as unsigned integers of the item size, with the inner codec. complex128 raises UnsupportedDtypeError.

Parameters: inner is the id of the lossless codec that codes the difference, and inner_params are its parameters. The inner codec must not need a base.

References:

xor-delta/1

Class: jabara.codecs.delta.XorDeltaCodec.

Codes the bitwise XOR of the chunk and the same chunk of the base, with the inner codec. Accepts every dtype.

Parameters: inner is the id of the lossless codec that codes the difference, and inner_params are its parameters. The inner codec must not need a base.

References:

zipnn/1

Class: jabara.codecs.zipnn.ZipNNCodec.

The zipnn package, with Zstandard as its entropy coder.

Lossless. Handles float16, bfloat16, and float32. Any other dtype raises UnsupportedDtypeError.

The third-party zipnn package is imported on first use. It imports torch, so the first call loads torch into the process. This import hides the FutureWarning about torch.jit.script that torch issues.

zipnn holds the GIL for a whole call and runs the call on threads of its own, so the container's thread pool cannot run two chunks at once. with_threads hands it the caller's thread budget instead; the bytes it writes are the same for every thread count. An instance from get_codec uses one thread.

It needs the zipnn extra.

References:

zstd/1

Class: jabara.codecs.builtin.ZstdCodec.

Compresses the whole chunk with Zstandard.

Parameters: level is the Zstandard compression level.

References: