gemma-3-270m-it-phi-lattice-v2
4-bit phi-lattice v2 build of unsloth/gemma-3-270m-it (270M parameters, 18 transformer layers, 100,270,080 quantized linear weights across 126 linear layers, 236 / 236 stored tensors).
gemma3_270m_phi_v2_packed_4bit.pt (371.02 MiB) plus phi_loader.py and phi_lut_gemm.py: true 4-bit uint8 archive (50.80 MiB for all 126 linear layers + 320.11 MiB BF16 token table and norms). mode="low_vram_4bit" keeps 370.91 MiB resident versus 511.36 MiB for the unrolled BF16 model. The linear backbone alone is 3.76x smaller than BF16 (7.53x versus FP32). The 262,144-token embedding stays BF16 because it is tied to lm_head.
torch.load(..., weights_only=True) round-trip of low_vram_4bit versus unrolled_bf16 is bit-exact (max |Δlogits| = 0.0 at torch.set_num_threads(1)). Against the published BF16 model.safetensors, the packed weights are a second codebook snap of the already crystallized checkpoint: probe cosine 0.99903, top-1 match on the probe, max absolute logit gap 5.5. The lattice change is confined to the 126 quantized Linear layers. Details in section 5.
Run it with phi_loader.py (low_vram_4bit or triton_4bit). model.safetensors is the unrolled BF16 fallback for transformers.
1. Repository Layout & Memory Footprint
gemma-3-270m-it-phi-lattice-v2/
├── gemma3_270m_phi_v2_packed_4bit.pt # 371.02 MiB packed archive (236/236 tensors, sha256: 8b0c406f...)
├── phi_loader.py # Standalone loader (low_vram_4bit, triton_4bit, unrolled_bf16)
├── phi_lut_gemm.py # Fused Triton 4-bit LUT-GEMM kernel (all 126 Linear layers, K % 64 == 0)
├── model.safetensors # 511.37 MiB unrolled BF16 fallback
├── config.json and tokenizer files
└── README.md
| Checkpoint Variant | Disk Size | RAM / GPU VRAM Footprint | Linear Weights (100.27M params) | Savings vs Published BF16 |
|---|---|---|---|---|
Published model.safetensors (BF16) | 511.37 MiB | 511.36 MiB | 191.25 MiB | 1.00x |
gemma3_270m_phi_v2_packed_4bit.pt (low_vram_4bit / triton_4bit) | 371.02 MiB | 370.91 MiB | 50.80 MiB (3.76x vs BF16) | 1.38x total (3.76x linear) |
Archive sha256: 8b0c406f29618b6d9762e5c1d2a5c23fcf4a5fb301298fe180230e88b5df7472 (389,045,392 bytes). Every quantized layer has K % 64 == 0, so flat groups of 64 never cross rows.
2. Quantitative Benchmark (Baseline BF16 vs Uniform vs phi-lattice v1 vs phi-lattice v2)
| Method | 4-bit Weight SQNR | 4-bit Perplexity | 4-bit Exact Sparsity | 3-bit Weight SQNR | 3-bit Perplexity |
|---|---|---|---|---|---|
1. Baseline (BF16) | Reference | 86.22 | 0.00% | Reference | 86.22 |
| 2. Standard Uniform | 18.69 dB | 352.63 | 0.00% | 11.39 dB | 1,165,167.0 (Collapsed) |
3. phi-lattice v1 | 18.65 dB | 158.80 | 8.41% | 12.63 dB | 2,121.3 |
4. phi-lattice v2 (This Repo) | 19.48 dB | 110.58 (3.19x better than Uniform) | 13.48% | 12.63 dB | 1,618.3 |
3. Quick Start
Option A: PyTorch 4-bit mode via phi_loader.py
import importlib.util
import torch
from huggingface_hub import hf_hub_download
from transformers import AutoTokenizer
repo_id = "ununununununununununununununununununun/gemma-3-270m-it-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)
model = phi_loader.load_gemma3_from_packed_4bit(repo_id=repo_id, mode="low_vram_4bit")
tokenizer = AutoTokenizer.from_pretrained(repo_id)
mode="unrolled_bf16" materializes the full BF16 state dict (strict=True). mode="triton_4bit" swaps in PhiLUTGemmLinear from phi_lut_gemm.py on CUDA.
On CPU, set torch.set_num_threads(1) before comparing bfloat16 logits. Multi-threaded OpenMP reductions reorder partial sums and can move the same forward pass by several logit units.
Option B: transformers (model.safetensors)
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
repo_id = "ununununununununununununununununununun/gemma-3-270m-it-phi-lattice-v2"
tokenizer = AutoTokenizer.from_pretrained(repo_id)
model = AutoModelForCausalLM.from_pretrained(repo_id, dtype=torch.bfloat16)
4. Text benchmarks (lm-evaluation-harness 0.4.13)
0-shot. The base column is the original unsloth/gemma-3-270m-it in BF16, run on CPU, finished 16:11 Europe/Minsk on 9 Nov 2026. The full dump is evals/lm_eval_gemma_base/results_2026-11-09T13-11-06.757545.json.
The v2 column is this repo's unrolled BF16 checkpoint, model.safetensors, which is the packed archive decompressed back to BF16. MMLU, IFEval, and HellaSwag ran on CPU. GSM8K ran on a GPU. Per-task files are in evals/lm_eval_gemma_v2/.
| Task | Metric | Base BF16 | phi-lattice v2 |
|---|---|---|---|
| MMLU | acc | 0.2508 | 0.2594 |
| GSM8K | exact_match, strict | 0.0243 | 0.0061 |
| GSM8K | exact_match, flexible | 0.0265 | 0.0129 |
| IFEval | prompt_level_strict_acc | 0.2421 | 0.1774 |
| IFEval | inst_level_strict_acc | 0.3729 | 0.2866 |
| IFEval | prompt_level_loose_acc | 0.2514 | 0.1848 |
| IFEval | inst_level_loose_acc | 0.3789 | 0.2962 |
| HellaSwag | acc | 0.3343 | 0.3253 |
| HellaSwag | acc_norm | 0.3929 | 0.3793 |
MMLU stays next to the 0.25 chance line and is slightly higher for v2. HellaSwag is about one point lower. GSM8K and IFEval are lower. Both models are weak on those two tasks in absolute terms. The size win is the packed archive: 371.02 MiB against 511.37 MiB for this BF16 file, and 3.76x on the linear weights.
5. Independent verification (2026-11-13)
Tensor-level checks of the packed archive against model.safetensors and the base checkpoint. No behavioral sampling.
| Check | Result |
|---|---|
Pack integrity: 110 protected BF16 tensors vs model.safetensors | 110/110 bit-exact |
Pack reconstruction: 126 quantized layers vs model.safetensors | median SQNR 52.57 dB (min 51.94 dB). The archive is a lossy codebook encoding of the published BF16 checkpoint |
Provenance vs base (unsloth/gemma-3-270m-it): protected tensors | 110/110 bit-exact (embedding, all norms, tied head untouched) |
| Provenance vs base: 126 quantized Linear layers | median SQNR 19.51 dB (min 17.62, max 19.68), consistent with the 19.48 dB claimed in section 2 |
Artifact digests: model.safetensors 271433716e7a05d3... (536,223,056 B), gemma3_270m_phi_v2_packed_4bit.pt 8b0c406f29618b6d... (389,045,392 B).
phi_loader.py in the 4-bit modes serves the codebook reconstruction. model.safetensors is the unrolled BF16 checkpoint. The lattice change is confined to the 126 quantized Linear layers. Embeddings, RMSNorm, q_norm, k_norm, and the tied LM head match the base checkpoint.