Skip to main content

ClikaRT::dtype::nf4_t

struct

Header: ClikaRT/compute/scalar_types.h

nf4_t: a 4-bit index into a 16-entry table of standard-normal quantiles scaled to [-1, +1]. No exponent/mantissa structure; purely a lookup quantizer. Callers normalize their data to roughly [-1, +1] (e.g. per-block max-abs scaling) before quantizing; out-of-range inputs saturate to ±1. The table is monotonic, so the stored index orders the same as the dequantized value. Low 4 bits of a byte.

Reference: Dettmers et al., "QLoRA" (2023), §3.1.

Static member functions

from_bits()

static constexpr nf4_t from_bits(std::uint8_t b) noexcept

Reinterpret the low 4 bits of b as a table index without converting.

Declared in ClikaRT/compute/scalar_types.h, line 365

Member functions

nf4_t()

constexpr constexpr nf4_t() noexcept=default

Declared in ClikaRT/compute/scalar_types.h, line 356

nf4_t(float)

explicit nf4_t(float f) noexcept

Quantize a normalized fp32 (in [-1, +1]) to the nearest table index.

Declared in ClikaRT/compute/scalar_types.h, line 359

operator float()

operator float() const noexcept

Dequantize (a single table lookup).

Declared in ClikaRT/compute/scalar_types.h, line 362

Data members

bits

std::uint8_t bits = 0

Raw encoding in the low 4 bits (the storage/ABI form).

Declared in ClikaRT/compute/scalar_types.h, line 354

Friends

operator==

friend bool operator==(nf4_t a, nf4_t b) noexcept

Compares a and b by table index (monotonic, so index order equals value order).

Declared in ClikaRT/compute/scalar_types.h, line 368

operator!=

friend bool operator!=(nf4_t a, nf4_t b) noexcept

Compares a and b by table index (monotonic, so index order equals value order).

Declared in ClikaRT/compute/scalar_types.h, line 369

operator<

friend bool operator<(nf4_t a, nf4_t b) noexcept

Compares a and b by table index (monotonic, so index order equals value order).

Declared in ClikaRT/compute/scalar_types.h, line 370

operator<=

friend bool operator<=(nf4_t a, nf4_t b) noexcept

Compares a and b by table index (monotonic, so index order equals value order).

Declared in ClikaRT/compute/scalar_types.h, line 371

operator>

friend bool operator>(nf4_t a, nf4_t b) noexcept

Compares a and b by table index (monotonic, so index order equals value order).

Declared in ClikaRT/compute/scalar_types.h, line 372

operator>=

friend bool operator>=(nf4_t a, nf4_t b) noexcept

Compares a and b by table index (monotonic, so index order equals value order).

Declared in ClikaRT/compute/scalar_types.h, line 373