Consumer-GPU Quantization Harness

💎 OPAL

Optimized Precision for Adaptive LLMs

A 3-pass Python harness for generating imatrix data and quantizing massive Mixture-of-Experts (MoE) LLMs on 8GB consumer GPUs. Bypass datacenter requirements using PyTorch's meta device.

📄 Abstract

Generating importance matrices (imatrix.dat) for 35B+ parameter Mixture-of-Experts (MoE) models usually requires datacenter-grade hardware. Tools like llama-imatrix demand loading the entire model into VRAM or system RAM. OPAL bypasses this completely. By streaming model weights layer-by-layer and "vaporizing" them from VRAM after use via PyTorch's meta device, OPAL enables anyone with an 8GB consumer GPU to calculate activation scales and apply cutting-edge APEX mixed-precision quantization gradients.

🚀 The OPAL Evolution

Adapting the APEX methodology and enhancing it for consumer hardware and dynamic architectures.

Dynamic Layer Gradients

APEX uses hardcoded layer indices designed for 40-layer models. OPAL uses dist_from_edge logic, automatically adapting the precision gradient to safely quantize models with 24, 32, or 48 layers.

Inherent I-Variants

Because OPAL always generates a high-quality imatrix, every OPAL quant is inherently an "I-variant". We streamlined the tiers, removing the confusing i- prefix entirely.

Refined Dense Layer Strategy

OPAL V2.1 introduces IQ4_XS for Shared Experts in the balanced and compact tiers. Because dense MoE layers have heavy-tailed outliers, using the imatrix to protect them at 4.25 bits saves VRAM without quality loss.

Extreme Edge Protection

Added the exp-minimalist tier, which uses a 3-tier staircase to heavily protect the first/last 5 layers with Q5_K while crushing the redundant middle layers to IQ2_XXS.

⚙️ The 3-Pass Architecture

A streamlined pipeline to bypass VRAM limits and apply mixed-precision gradients.

01

Parser

Tokenizes Bartowski's high-quality semantic calibration dataset and caches batches to disk.

02

Imatrix Harvest

Uses a "Ghost Model" on the meta device. Streams layers to GPU, captures activation scales via forward hooks, and writes imatrix.dat.

03

Map & Handoff

Dynamically generates an OPAL tensor-type-file.txt and shells out to llama-quantize to apply gradients.

📊 Deployment Tiers

Dynamically generated tensor maps using distance-from-edge logic, adapting to any model layer count.

Tier Target Size Middle Layer Use Case
{{ tier.name }} {{ tier.size }} {{ tier.quant }} {{ tier.use }}

💻 Usage & CLI

Run the entire pipeline in one command.

Run the entire pipeline (Tokenize, Harvest Imatrix, Quantize):

python opal.py run-all \
    --model ./Qwen3.5-35B-A3B \
    --tier mini \
    --vram-limit 8 \
    --samples 2075

Batch Quantization (multiple tiers from one F16 conversion):

python opal.py pass3 \
    --model ./Qwen3.5-35B-A3B \
    --tier nano micro exp-minimalist

⚠️ Known Limitations

Important note on Unsloth models and extreme low-bit tiers.

Unsloth Limitation

OPAL is designed to hook into individual nn.Linear modules. Unsloth merges MoE experts into a single FastLinear module. OPAL handles this gracefully by injecting a uniform fallback array for experts.

  • Quality/Balanced/Compact: Work perfectly on Unsloth models.
  • Mini/Micro/Nano/exp-minimalist (IQ2/IQ1): May degrade on Unsloth models. For extreme low-bit tiers, use standard HuggingFace model formats.

📚 Credits & Acknowledgements

APEX Quantization Method
Ettore Di Giacinto & Richard Palethorpe (LocalAI Team). OPAL adapts the layer-wise precision gradients and MoE-aware tensor classification outlined in the APEX technical paper.

Bartowski & Lamim
For the excellent semantic imatrix calibration dataset that powers OPAL's activation scaling.

llama.cpp
Georgi Gerganov and contributors for the foundational inference and quantization engine.

HuggingFace Accelerate
For the init_empty_weights() context manager that makes the 0-RAM "Ghost Model" possible.

Jackrong
For the sexy markdown readme inspo.