Core AI model zoo

coreai-optimization (coreai-opt) reference — quantization & palettization

Foundation note (API reference). Complements compression.md (this project’s LLM-specific empirical notes). Relevant to the int4 / vocab-pruned head lever in the ANE-later plan and to shrinking deployable assets. Sources: coreai-optimization/README.md, docs/src/{introduction,quantization,palettization,utils}/*, skills/.../model-compression-exploration/references/{compression_patterns,size_estimation}.md.

Where it plugs in

PyTorch model → coreai-opt (compress) → finalize() → torch.export(run_decompositions(get_decomp_table()))
              → cast_to_16_bit_precision → coreai_torch.TorchConverter → .optimize() → save_asset() → .aimodel

Every compressor output is itself a PyTorch model (validate/finetune/export it). Lifecycle: Quantizer/KMeansPalettizer(model, config)prepare(example_inputs) → optional calibration_mode() / training_mode() (QAT) → finalize(backend=ExportBackend.CoreAI).

Quantization (weights ±activations)

Palettization (k-means LUT, weights only)

Mixed precision & joint compression

The LM head + embeddings (biggest tensors; the ANE-later lever)

Pitfalls

Theoretical size

weight/index bytes = numel * n_bits/8           # int4 = 0.5 B/elem, int8 = 1 B/elem
scale bytes        = n_groups * 2 (fp16)         # n_groups per granularity (per-tensor=1, per-channel=shape[axis], per-block=ceil(dim/B)*…)
zero_point bytes   = n_groups * n_bits/8         # asymmetric only
lut bytes          = 2^n_bits * n_luts * 2       # palettization
total ≈ Σ(above) + uncompressed (biases, fp embeds, skipped layers)
avg_bitwidth = Σ(numel_i * bits_i) / Σ numel_i

Sizes hit in this project: gemma4 E2B core 7.0 GB fp32 → 3.5 GB fp16 → 1.9 GB int8; qwen3.5-0.8B 969 MB.