qwen3-4b-instruct-2507-phi-lattice-v2
4-bit phi-lattice v2 build of Qwen/Qwen3-4B-Instruct-2507 (4.0B parameters, 36 transformer layers, 3,633,315,840 quantized linear weights across 252 linear layers, 398 / 398 total tensors).
qwen3_4b_phi_v2_packed_4bit.pt (2,583.2 MiB / 2.71 GB) plus phi_loader.py and phi_lut_gemm.py: true 4-bit uint8 archive (1,841.1 MiB for all 252 linear layers + 742.1 MiB BF16 token table and norms). mode="low_vram_4bit" and mode="triton_4bit" keep 2,583.0 MiB resident versus 7,671.6 MiB upstream BF16.
Run it with phi_loader.py. There is no separate runtime container in this repo.
1. Repository Layout & Memory Footprint
qwen3-4b-instruct-2507-phi-lattice-v2/
├── qwen3_4b_phi_v2_packed_4bit.pt # 2,583.2 MiB 4-bit packed archive (all 398/398 tensors, sha256: c617c04a...)
├── phi_loader.py # Standalone loader (low_vram_4bit, triton_4bit, unrolled_bf16)
├── phi_lut_gemm.py # Fused Triton 4-bit LUT-GEMM kernel (all 252 Linear layers K%64==0)
├── config.json & tokenizer files
└── README.md
| Checkpoint Variant | Disk Size | RAM / GPU VRAM Footprint | Linear Weights Footprint (3.63B params) | Savings vs Upstream BF16 |
|---|---|---|---|---|
Upstream Qwen/Qwen3-4B-Instruct-2507 (BF16) | 7,671.6 MiB (8.05 GB) | 7,671.6 MiB | 6,930.0 MiB | 1.00x |
qwen3_4b_phi_v2_packed_4bit.pt (low_vram_4bit / triton_4bit) | 2,583.2 MiB (2.71 GB) | 2,583.0 MiB | 1,841.1 MiB (3.76x vs BF16) | 2.97x total (3.76x linear) |
2. Quantitative Benchmark (Baseline BF16 vs Uniform vs phi-lattice v1 vs phi-lattice v2)
| Method | 4-bit Weight SQNR | 4-bit Exact Sparsity (Zeroed Weights) | 3-bit Weight SQNR | 3-bit Exact Sparsity |
|---|---|---|---|---|
1. Baseline (BF16) | Reference | 0.00% (0) | Reference | 0.00% |
| 2. Standard Uniform | 19.04 dB | 0.00% (0) | 11.70 dB | 0.00% |
3. phi-lattice v1 | 18.62 dB | 7.82% (284,125,300 weights) | 12.66 dB | 19.39% |
4. phi-lattice v2 (This Repo) | 19.63 dB (+1.01 dB vs v1) | 12.53% (455,352,162 weights zeroed) | 12.90 dB (+1.20 dB vs Uniform) | 21.24% |
Text Benchmarks (lm-evaluation-harness)
Evaluated with run_text_evals.py (batch_size=16, unrolled_bf16 for phi-lattice v2). Raw JSON files are in evals/lm_eval_qwen_base/ and evals/lm_eval_qwen_v2/.
| Task | Metric | Base Qwen/Qwen3-4B-Instruct-2507 (BF16) | phi-lattice v2 (4-bit archive) | stderr (Base / v2) |
|---|---|---|---|---|
| MMLU (14,042 items) | acc | 0.7063 | 0.6806 | 0.0036 / 0.0037 |
| GSM8K (1,319 items) | exact_match, strict-match | 0.8590 | 0.8393 | 0.0096 / 0.0101 |
| IFEval (541 prompts) | prompt_level_strict_acc | 0.5786 | 0.4547 | 0.0212 / 0.0214 |
| IFEval (541 prompts) | inst_level_strict_acc | 0.6918 | 0.6007 | — |
| IFEval (541 prompts) | prompt_level_loose_acc | 0.6414 | 0.5139 | 0.0206 / 0.0215 |
| IFEval (541 prompts) | inst_level_loose_acc | 0.7410 | 0.6487 | — |
| HellaSwag (10,042 items) | acc | 0.5256 | 0.5064 | 0.0050 / 0.0050 |
| HellaSwag (10,042 items) | acc_norm | 0.6905 | 0.6719 | 0.0046 / 0.0047 |
Takeaway (4B Dense Quantization): Across
3.63Blinear weights compressed by3.76x(2.97xtotal VRAM reduction from7.67 GiBto2.58 GiB, with12.53%exact zeros and zero calibration data),phi-lattice v2retains97.7%of baseline mathematical reasoning on GSM8K (0.8393vs0.8590),96.4%of multi-subject knowledge on MMLU (0.6806vs0.7063), and97.3%of commonsense reasoning on HellaSwag (0.6719vs0.6905).
3. Quick Start & Loading Modes
Option A: PyTorch / Triton 4-Bit Mode via phi_loader.py (2,583.0 MiB VRAM)
import importlib.util
import torch
from huggingface_hub import hf_hub_download
from transformers import AutoTokenizer
repo_id = "ununununununununununununununununununun/qwen3-4b-instruct-2507-phi-lattice-v2"
loader_path = hf_hub_download(repo_id=repo_id, filename="phi_loader.py")
spec = importlib.util.spec_from_file_location("phi_loader", loader_path)
phi_loader = importlib.util.module_from_spec(spec)
spec.loader.exec_module(phi_loader)
# Modes:
# - "triton_4bit" : 2,583.0 MiB VRAM (fused Triton LUT-GEMM in GPU registers)
# - "low_vram_4bit": 2,583.0 MiB VRAM (PyTorch on-the-fly per-layer dequantization)
# - "unrolled_bf16": 7,671.6 MiB VRAM (unpacks all 398/398 tensors into BF16 nn.Linear on load)
model = phi_loader.load_qwen3_from_packed_4bit(
repo_id=repo_id,
mode="triton_4bit",
device="cuda",
dtype=torch.bfloat16,
)
tokenizer = AutoTokenizer.from_pretrained(repo_id)