Skip to content
MorrowmakePublic

About

FITQ (Fewest-Instruction Trellis Quantization) — open format specification, C99/Python reference decoders, and conformance vectors

Topics

Resources

Contributing

Stars

32 stars

Watchers

2 watching

Forks

Repository files navigation

FITQ — Fewest-Instruction Trellis Quantization

by Morrowmake
Smaller. Faster. Sharper. Everywhere.

Follow @Morrowmake on X FITQ Specification v1 (CC BY 4.0)

FITQ — Fewest-Instruction Trellis Quantization

FITQ is an open, engine-agnostic, hardware-portable weight format for large dense and Mixture-of-Experts (MoE) language models. One .fitq file is designed to run natively across modern GPUs and unified-memory accelerators — built from first principles so any inference engine and any vendor's 8-bit integer matrix units can push both single-user decode and long-context prefill right up to silicon rooflines.

This repository contains the complete FITQ format specification, normative C99 reference decoder and test-vector checker, independent Python + NumPy reader, binary conformance vectors, and the open-source FITQ converter (fitq Python package + multi-arch CUDA trellis encoders) for quantizing dense and MoE Hugging Face models into .fitq checkpoints.

Early-format note: FITQ is brand new. Our first-generation inference kernels (launching first in TensorFold) have only been hardware-tested and tuned on NVIDIA Ampere (sm_80 / sm_86) so far. Newer NVIDIA architectures (sm_89–sm_120) and Apple Silicon (Metal) are early/experimental and not yet hardware-tuned, and AMD, Intel, Vulkan, and fast CPU inference backends do not exist yet. The CUDA converter requires NVIDIA Ampere or newer (sm_80+). See Current Implementation Status below.


Why FITQ?

Scalar quantization formats (like GGUF K-quants, GPTQ, or AWQ) are fast to unpack, but leave significant model quality on the table below 4 bits per weight. Trellis quantization preserves far more accuracy per bit, yet existing trellis formats pay a heavy runtime tax: high per-weight decode instruction counts or shared-memory lookup tables that stall ALUs, exhaust registers, and bottleneck high-bandwidth GPUs or Apple Silicon.

FITQ was designed to remove that tradeoff by compounding four format-level advantages:

  1. Fast, branchless, lookup-table-free unpacking (~0.97 ops/weight at 3-bit, ~1–2 ops across 2–6 bits): Every FITQ trellis code (t2–t6) decodes 4 weights per step using only 32-bit integer arithmetic — zero lookup tables, zero shared-memory bank conflicts, and no vendor-specific unpack instructions (compare 5.26 ops/weight in EXL3). Decode instructions hide cleanly behind memory loads, keeping single-stream weight reads at or near the memory-bandwidth roofline even on HBM GPUs and modern high-bandwidth Apple Silicon.
  2. Direct INT8 output (2× matrix-unit compute across every major GPU vendor, virtually lossless vs. BF16): Instead of dequantizing weights back to FP16/BF16, FITQ unpacks straight into packed INT8 ready for native 8-bit integer matrix multiplication — where NVIDIA Tensor Cores (mma.sync), Apple Silicon Metal 4 matrix units, AMD RDNA 4 / CDNA (WMMA / MFMA, e.g. Radeon AI PRO R9700: 383 INT8 TOPS vs 191 FP16 TFLOPS), and Intel Xe2 (XMX, e.g. Arc Pro B70: 367 INT8 TOPS vs 183.5 FP16 TFLOPS) all deliver 2× higher throughput than FP16/BF16. Because FITQ applies Hadamard rotations to spread outlier channels evenly across every vector, INT8 matrix math is virtually lossless compared to BF16 — directly doubling matrix compute headroom on prefill, multi-user concurrency, and speculative verify batches without giving up quality (see Current Implementation Status for which backends exist today).
  3. Fine-grained mixed precision (2.0–6.0 bpw + plain8 / int8row / exact): Every linear layer and individual MoE expert can be stored at the exact bit-width its sensitivity warrants (t2, t2p5, t3, t3p5, t4, t5, t6, or plain8), with Hadamard rotations baked cleanly into the format. Because single-user token generation is memory-bandwidth bound — each token must stream the active weights out of VRAM — matching quality at fewer bits per weight directly increases decode speed while freeing VRAM for longer context windows and more concurrent streams.
  4. Self-verifying, portable model folders with generic speculative drafters: Every .fitq file carries per-tensor SHA-256 digests, a provenance-independent weights_sha256, a whole-header signature, and integrity checks over byte-exact copies of config.json, tokenizer files, and LICENSE. Companion speculative drafters pair generically by (model_type, config_sha256), so a single standalone drafter works across every quantization size of the same base model.

Why FITQ Is Fast — 5.4x fewer decode ops, direct INT8


Format Performance Ceiling (vs. EXL3 & FP16 Trellis Formats)

FITQ's primary performance comparator is EXL3 and other FP16-output trellis quantization formats. Independent of today's early first-generation kernels, FITQ's ~5.4× lower unpack instruction count and direct INT8 output raise the format-level ceiling across prefill, high-concurrency multi-user decode, speculative verify batches, and single-user decode (calculated from published chip specs and sm_80 SASS counts):

FITQ Format Performance Ceiling vs EXL3 and FP16 trellis formats across NVIDIA, AMD, Intel, and Apple Silicon

Hardware Class Format Ceiling Advantage vs EXL3 / FP16 Trellis Formats Underlying Silicon Math
Desktop GPUs (NVIDIA, AMD, Intel) 2.0× prefill, multi-user concurrency & speculative decode matrix-compute ceiling Direct INT8 matrix units vs FP16 trellis dequant: RTX 4090 (660 vs 330), RTX 3090 (284 vs 142), AMD Radeon AI PRO R9700 (383 vs 191), Intel Arc Pro B70 (367 vs 183.5 INT8 TOPS vs FP16 TFLOPS); 1u decode stays bandwidth-bound where tighter bits/weight cuts VRAM reads
High-Bandwidth HBM GPUs (CMP 170HX / A100) 1.63×–2.18× higher 3-bit single-stream decode ceiling + 2.0× prefill & multi-user decode matrix peak sm_80 SASS decode roofline (1.55 vs 5.83 total ops/wt): FITQ saturates 100% of HBM while EXL3 stalls on ALU at 46% (CMP 170HX, 180 W) and 62% (A100 80 GB), while high-concurrency & speculative verify batches also gain 2.0× INT8 Tensor Core headroom
Apple Silicon (M5 Max / M5 Ultra, Metal 4) ~2.0× prefill & multi-user decode INT8 matrix peak + full 1,228 GB/s 3-bit single-user decode headroom < 1 unpack op/weight stays well inside the ~4.85 lane-ops/weight ALU budget at 1,228 GB/s, where ~5+ ops/weight FP16 trellis formats hit an ALU wall

(These are theoretical format ceilings, not measured performance on every chip — see Current Implementation Status below for which backends are hardware-tested today.)


Proven Results (No Fine-Tuning)

Evaluated head-to-head against published baselines by forward KL divergence against exact BF16 references, strictly external one-shot validation (240 external documents), and live execution benchmarks:

FITQ Quality Head-to-Head vs EXL3 and TFQ3

  • Qwen3.8-Flash-Next (114.09 GB vs EXL3 at 114.19 GB — equal disk size): -15.8% lower overall forward KL across 7 / 7 domain types and -16.2% overall (-19.0% per-document average) across 6 / 6 external domains (182 / 240 item wins, -38.2% fewer high-confidence token flips at p ≥ 0.90), while hitting 81.10% on MBPP+, 80.41% on BFCL v3 (+0.59 pp over BF16), and 90.66% on GPQA Diamond 64K.
  • Inkling-2-Mini (15.90 GB vs TFQ3 at 16.76 GB — 5.1% smaller): -26.9% lower overall forward KL across 6 / 6 open domains and -14.7% across 6 / 6 external domains (217 / 240 wins, 98.40% top-1 agreement), ranking #1 on both MBPP+ (75.75%) and BFCL v3 (78.05).

Full benchmark receipts, model cards, and serving recipes (launching first on TensorFold) are published alongside this release — follow @Morrowmake for updates and new model drops.


Current Implementation Status

Because FITQ is a brand-new format, runtime coverage is still early: most inference kernels are only lightly tuned or untested on hardware, and several hardware backends do not exist yet.

Target / Component Status Notes
FITQ Converter (fitq plan | quantize | eval | drafter | verify) Released & tested Open-source Apache-2.0 Python package + multi-arch CUDA trellis encoders (sm_80+: Ampere, Ada, Hopper, Blackwell), streamed layer-by-layer conversion, multi-GPU sharding, sensitivity-aware per-expert bit allocation (--quality max), held-out KL/top-1/PPL evaluation (fitq eval), and automatic generic Hugging Face dense & MoE model support.
Normative C99 decoder (FORMAT.md) & Python reader (reader2/) Tested 19 / 19 spec vectors and 3 / 3 golden .fitq files pass (check_spec.py --plant-fault fails loudly). Correctness references only, not fast inference kernels.
NVIDIA CUDA — Ampere (sm_80 / sm_86, e.g. CMP 170HX, RTX 3090, A100) Hardware-tested & tuned (early) First-generation kernels in TensorFold; verified by contract tests, sanitizers, and live serving benchmarks, with substantial optimization headroom still ahead.
NVIDIA CUDA — Ada / Hopper / Blackwell (sm_89 / sm_90 / sm_120) Compiled only (untested on hardware) Release binaries emit SASS via the Ampere mma.sync path and should run, but have not been hardware-tested or tuned for Ada, Hopper (WGMMA/TMA), or Blackwell yet.
Apple Silicon (Metal) Experimental (not yet tuned) Metal shaders compile cleanly and earlier M4 kernel checks passed, but the backend is not yet end-to-end served or tuned.
AMD (ROCm / RDNA 4 / CDNA), Intel (SYCL / Xe2), Vulkan, fast CPU (AVX-512 / NEON) Not yet implemented No inference kernels exist yet. The format was designed so native 8-bit matrix units on these platforms can target it directly — contributions and third-party engine ports are very welcome.

Format at a Glance

  • Container: 16-byte little-endian prefix (FITQ magic, container version = 1, header length), followed by a 64-byte-aligned canonical JSON header and 64-byte-aligned tensor payloads.
  • Six storage kinds:
    • packed — Hadamard-rotated trellis-coded linear matrices (t2–t6)
    • packedrow — row-wise trellis-coded lookup tables (t2–t6, row width divisible by 32)
    • plain8 — Hadamard-rotated 8-bit linear matrices
    • int8row — 8-bit per-row lookup tables (embeddings, n-gram tables, 2D vision projections)
    • exact — unmodified tensors in original dtype (norms, routers, small gates)
    • signs — packed ±1 sign vectors for input and output Hadamard rotations
  • Seven trellis code types: t2 (2.0 bpw), t2p5 (2.5 bpw), t3 (3.0 bpw), t3p5 (3.5 bpw), t4 (4.0 bpw), t5 (5.0 bpw), and t6 (6.0 bpw) — all decoding 4 INT8 weights per step using only 32-bit integer arithmetic.
  • Model folders: A converted model is a folder holding a single *.fitq file (such as model.fitq or a publisher-named file like <Model>-FITQ-<bpw>bpw-<Publisher>.fitq) alongside verified copies of config.json, tokenizer files, fitq_stats.json, and LICENSE. Folders with multiple .fitq files are refused cleanly.

Repository Contents

Path Description
fitq/ Open-source FITQ Python package (fitq plan, fitq quantize, fitq eval, fitq drafter, fitq verify), CUDA trellis encoders (t2–t6), two-sided input/output sensitivity statistics (H_in/H_out), sensitivity-based bit allocator, and model profiles
docs/CONVERTING.md End-to-end converter guide: quality tiers, calibration text, held-out fitq eval, hardware requirements, and adding new model architectures
CONTRIBUTING.md Repository map, 2-file model plugin guide (@register_family, @register_router), source-format registry, and test checklist
pyproject.toml Python package metadata (pip install -e ".[cuda]")
FORMAT.md Complete FITQ binary container specification, storage kinds, seven trellis code types (t2–t6), normative C99 reference decoder, and 19 test vectors
check_spec.py Extracts and compiles the C99 decoder from FORMAT.md (-std=c99 -O2 -Wall -Wextra -Werror) and verifies all 19 test vectors, invariants, and fault controls
reader2/ Independent Python 3 + NumPy reader written directly from FORMAT.md
vectors/ Binary .fitq conformance files (rows.fitq, ends.fitq, drafter.fitq) and EXPECTED.json
tests/ Spec, format, allocator, and CUDA kernel bit-exactness test suite
LICENSE Apache-2.0 licence for code and scripts (Copyright 2026 Morrowmake)
LICENSE-CC-BY-4.0 CC BY 4.0 licence for FORMAT.md and test vectors

Quantizing Your Own Models (fitq Converter)

Requirements for GPU conversion: Linux with Python 3.10+, CUDA toolkit (nvcc), and an NVIDIA Ampere or newer GPU (sm_80+: RTX 30/40/50 series, CMP 170HX, A100, H100, B200). CUDA encoder kernels JIT-compile automatically on first run into ~/.cache/fitq/torch_ext.

Install

git clone https://github.com/Morrowmake/fitq.git
cd fitq
pip install -e ".[cuda]"

(For CPU-only planning, verification, and container reading without PyTorch/CUDA: pip install -e .)

1. Plan size, VRAM, KV cache, and bit breakdown (no GPU needed)

# Preview a 4.0 bpw mixed-precision plan (local dir or Hugging Face repo ID)
fitq plan --model Qwen/Qwen3-8B --bpw 4.0

# Or target your exact GPU VRAM + context window (shows a context menu if --context is omitted)
fitq plan --model Qwen/Qwen3-30B-A3B --vram 24G --cards 1 --context 32k

2. Quantize a model end-to-end

# Quick start: 4.0 bpw using the bundled offline 6-domain calibration corpus (zero flags needed)
fitq quantize --model Qwen/Qwen3-8B --bpw 4.0 --out ./Qwen3-8B-FITQ-4.0bpw

# Fit a specific VRAM budget + context length with custom calibration data
fitq quantize \
  --model /path/to/My-MoE-Model \
  --text ./calib.jsonl \
  --vram 24G --cards 1 --context 64k \
  --out ./My-MoE-FITQ

# Maximum quality on MoE or dense models: sensitivity-guided per-expert bit allocation across multiple GPUs
fitq quantize \
  --model /path/to/My-MoE-Model \
  --text code=./code.jsonl --text chat=./chat.jsonl \
  --bpw 3.9 \
  --quality max \
  --gpus auto \
  --out ./My-MoE-FITQ-3.9bpw

Key options:

  • Sizing targets (pick one): --bpw B (average trunk bits/weight), --target-gb G (on-disk GB cap), --vram SIZE --context TOK [--cards N] (GPU VRAM + KV budget), or --bits {2,2.5,3,3.5,4,5,6} (uniform width).
  • Calibration text (--text, repeatable): accepts .jsonl, .jsonl.gz, .txt, .txt.gz, a directory of text files, category=file.jsonl, or hf:<dataset>[:<subset>]. If omitted, uses the bundled offline 6-domain calibration corpus (~5.8M permissive-license tokens across code, tools, math, multilingual, chat, and structured with automatic MoE coverage sizing); supply your own --text (or own-model replies) for specialized workloads or heavy reasoning models.
  • Resumable: every stage checkpoints atomically into <out>.work; re-running the exact same command resumes where it left off and deletes <out>.work automatically once fitq verify passes (pass --keep-work to retain scratch artifacts).
  • Supported architectures: standard Hugging Face dense and MoE CausalLM models (llama, qwen2, qwen3, qwen3_moe, qwen3_5, mistral, mixtral, gemma, gemma2, gemma3, phi3, olmoe, deepseek_v3, inkling2_loop, glm5_next, etc.) work out of the box, alongside dedicated plugins for Amazon-FMR/Ergo (ergo: BF16 / MXFP8 / MXFP4) and DeepSeek-V4.1-Flash (deepseek_v41: FP8 [32,32] + FP4 experts, shared KV/indexer, Engram host-RAM n-gram tables, 4-stream hyper-connections — both verified on real HF headers and synthetic GPU checkpoints; full-scale checkpoint runs pending). Pass --trust-remote-code for checkpoints with custom Hub modeling code, or see CONTRIBUTING.md to add a new model plugin in 1–2 files.

3. Verify integrity, measure held-out quality & convert a drafter

# Verify header signature, per-tensor SHA-256 digests, finite scales, and multi-GPU tensor-parallel alignment
fitq verify ./Qwen3-8B-FITQ-4.0bpw

# Measure forward KL divergence, top-1/top-5 agreement, and perplexity
# (omitting --text uses the bundled strictly disjoint 6-domain held-out eval set with a By Domain table;
#  pass --text ./heldout.jsonl for your own benchmark)
fitq eval \
  --orig Qwen/Qwen3-8B \
  --quant ./Qwen3-8B-FITQ-4.0bpw \
  --out ./eval_report.json

# Convert a standalone speculative drafter (pairs generically across all quant tiers of the same base model)
fitq drafter --model /path/to/DFlash2 --target ./Qwen3-8B-FITQ-4.0bpw --out ./DFlash2-FITQ

For full guidance on quality tiers, calibration corpora, hardware requirements, and converting unfamiliar or newly released architectures, see docs/CONVERTING.md.


Format Spec & Conformance Checks (CPU Only)

Requirements: Python 3.10+, a C99 compiler (cc), and numpy (for reader2).

1. Verify the C99 reference decoder and all 19 spec vectors

python3 check_spec.py FORMAT.md

Verify that a planted 1-bit corruption fails loudly (exits non-zero):

python3 check_spec.py --plant-fault FORMAT.md

2. Verify with the independent Python + NumPy reader

python3 reader2/fitq_golden.py --vectors FORMAT.md
python3 reader2/fitq_golden.py --check vectors/EXPECTED.json

Inspect any .fitq file or model folder directly:

python3 reader2/fitq_read.py vectors/rows.fitq --list

Implementing FITQ in Your Engine

Everything an inference engine needs to load, verify, and decode FITQ files is self-contained in FORMAT.md:

  1. Parse the 16-byte prefix and canonical JSON header (FORMAT.md §3–§4) and verify meta.signature, meta.source_files, and per-tensor payload digests.
  2. Implement the two small integer decoder families (t2–t3 and t3p5–t6, FORMAT.md §6) against the 19 normative C99 vectors via check_spec.py.
  3. Validate end-to-end tensor reconstruction (including Hadamard unrotation, plain8, int8row, packedrow, and generic drafter pairing) against vectors/EXPECTED.json.

FITQ is completely engine-agnostic — nothing in the container format, header schema, or trellis decoders depends on any specific runtime. Our Day-1 serving recipes (targeting TensorFold, with early CUDA and Apple Silicon Metal kernels) are live alongside this repository, and additional engine integrations (llama.cpp, vLLM, SGLang, MLX, and others) are welcome.


Licences

  • Specification (FORMAT.md) and test vectors (vectors/): Creative Commons Attribution 4.0 International (LICENSE-CC-BY-4.0), Copyright 2026 Morrowmake.
  • Converter package (fitq/ code and CUDA encoders), reference C99 decoder, check_spec.py, and reader2/: Apache License 2.0 (LICENSE), Copyright 2026 Morrowmake.
  • Bundled default calibration and evaluation corpora (fitq/text/default_*.jsonl.gz): Third-party open datasets under their respective upstream permissive licenses (Apache-2.0, CC-BY-4.0, ODC-BY-1.0, and MIT/BSD/ISC). See fitq/text/NOTICE.md for full provenance, attribution notices, and license terms.

Special Thanks

Developing and validating FITQ required a huge amount of GPU time across real hardware. A sincere thank you to @iotapi322, @CarlSandburg19, @blockshieldcom, @ashxhart and @MiguelCamba for generously letting us use their machines throughout development — this format genuinely would not have been possible without them.

About

FITQ (Fewest-Instruction Trellis Quantization) — open format specification, C99/Python reference decoders, and conformance vectors

Topics

Resources

Contributing

Stars

32 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages