Skip to main content

TernaryFormat

Enum TernaryFormat 

Source
#[non_exhaustive]
pub enum TernaryFormat { Tq1_0, Tq2_0, I2sInt8, }
Expand description

Canonical packing schemes for ternary weights — the shared vocabulary across crates. The byte-exact layout, pack, and unpack live in tritium-format; this enum only fixes the names, block size, and effective width so every crate agrees on them.

Both follow ggml’s 256-element super-block with one fp16 block scale.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Tq1_0

llama.cpp TQ1_0 — 5 trits per byte (3^5 = 243 < 256). 1.6875 bpw incl. block scale. Most compact; unpack needs base-3 division — CPU/edge oriented.

§

Tq2_0

llama.cpp TQ2_0 — 2 bits per trit, 4 per byte. 2.0625 bpw incl. block scale. Cheap shift/mask unpack; matches BitNet’s int8 packing — GPU oriented.

§

I2sInt8

I2sInt8 — the IMMA (int8 tensor-core) GPU layout, derived from an I2_S checkpoint at load (tritium_format::convert_i2s_to_int8). Weights stay 2-bit packed in VRAM (≈2.0 bpw, no per-block scale — the I2_S source carries a single per-tensor f32 scale), interleaved so the IMMA kernel can unpack them to int8 operands for mma.m16n8k32 in shared memory. Added in v0.30 (ADR 0005) for the compute-bound prefill path; the CPU/reference backends do not consume it and return an unsupported-format error — it is a GPU-only packing.

Implementations§

Source§

impl TernaryFormat

Source

pub const fn bits_per_weight(self) -> f32

Effective bits per weight, block scale amortized over the block.

Source

pub const fn block_size(self) -> usize

Weights per quantization block (ggml QK_K). One fp16 scale per block.

Source

pub const fn is_bit_aligned(self) -> bool

Whether unpack is a cheap shift/mask (true, GPU-friendly) or base-3 division (false, CPU/edge). Both Tq2_0 and I2sInt8 are 2-bit aligned.

Trait Implementations§

Source§

impl Clone for TernaryFormat

Source§

fn clone(&self) -> TernaryFormat

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for TernaryFormat

Source§

impl Debug for TernaryFormat

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for TernaryFormat

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Short canonical token per variant (e.g. tq1_0, tq2_0).

Source§

impl Eq for TernaryFormat

Source§

impl Hash for TernaryFormat

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for TernaryFormat

Source§

fn eq(&self, other: &TernaryFormat) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for TernaryFormat

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.