llama-3.1-8b-instruct-phi-lattice-v2
4-bit phi-lattice v2 build of RedHatAI/Llama-3.1-8B-Instruct (8.03B parameters, 32 transformer layers, 6,979,321,856 quantized linear weights across 224 linear layers, 291 / 291 stored tensors).
RedHatAI/Llama-3.1-8B-Instruct is a BF16 redistribution of meta-llama/Llama-3.1-8B-Instruct. The pack was made from the Red Hat copy because this account's request for the official Meta repo was rejected.
lm_head and embed_tokens stay BF16. They are the token tables (tie_word_embeddings is false, so both are stored). Norms stay BF16.
llama31_8b_instruct_phi_v2_packed_4bit.pt(5,540.7 MiB) plusphi_loader.pyandphi_lut_gemm.py. The archive is true 4-bituint8nibbles plus fp16 group scales (3,535.9 MiBfor the 224 linears,2,004.8 MiBfor the BF16 token tables and norms).mode="low_vram_4bit"andmode="triton_4bit"keep that archive resident. Upstream BF16 is14.96 GiB.- The codebook used to unpack the nibbles is stored inside the archive as
codebook.
Archive sha256: 4a8670afeb50e731167cefdf5b83d6c335e70fe71b408874313559d10c8d7ed3 (5,809,819,310 bytes). Every quantized layer has K % 64 == 0.
1. Repository layout and memory
llama-3.1-8b-instruct-phi-lattice-v2/
├── llama31_8b_instruct_phi_v2_packed_4bit.pt # 5,540.7 MiB packed archive (291/291 tensors)
├── phi_loader.py # low_vram_4bit, triton_4bit, unrolled_bf16
├── phi_lut_gemm.py # fused Triton 4-bit LUT-GEMM
├── run_text_evals.py # MMLU, GSM8K, IFEval, HellaSwag, one task at a time
├── config.json and tokenizer files
└── README.md
| Checkpoint | Disk | Resident | Linear weights (6.98B) | Versus upstream BF16 |
|---|---|---|---|---|
| Upstream BF16 | 14.96 GiB | 14.96 GiB | 13,311.6 MiB | 1.00x |
Packed 4-bit (low_vram_4bit / triton_4bit) | 5,540.7 MiB | 5,540.7 MiB | 3,535.9 MiB (3.76x) | 2.76x |
This number is the streaming pack that is actually in the file. Weight SQNR against the upstream tensors is 19.34 dB. Exact zeros in the packed indices: 861,824,004 (12.35%).
A separate crystallizer pass (v1 versus v2, with perplexity) has not been run for this model. On Gemma 3 270M and Qwen3-4B that pass moved SQNR. On Qwen2.5-Coder-7B it did not. The gain depends on the model, and it is not claimed here.
2. Quick start
import importlib.util
import torch
from huggingface_hub import hf_hub_download
from transformers import AutoTokenizer
repo_id = "ununununununununununununununununununun/llama-3.1-8b-instruct-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)
# "triton_4bit" fused LUT-GEMM on CUDA
# "low_vram_4bit" PyTorch dequant inside each linear
# "unrolled_bf16" unpacks all 291 tensors into BF16 linears
model = phi_loader.load_llama31_instruct_from_packed_4bit(
repo_id=repo_id,
mode="low_vram_4bit",
device="cuda",
dtype=torch.bfloat16,
)
tokenizer = AutoTokenizer.from_pretrained(repo_id)
mode="triton_4bit" reads phi_lut_gemm.py from the same repo. Every packed layer has K % 64 == 0.
Text benchmarks for this archive:
python3 run_text_evals.py --target llama31-instruct-base --task mmlu
python3 run_text_evals.py --target llama31-instruct-v2 --task mmlu
llama31-instruct-v2 unrolls this repo. llama31-instruct-base is RedHatAI/Llama-3.1-8B-Instruct. Omit --task to run MMLU, GSM8K, IFEval, and HellaSwag one at a time.
HumanEval
humaneval_instruct, greedy, chat template on, 164 tasks, pass@1. Both runs are NVIDIA A100. The scores are in evals/humaneval_llama31_instruct.json.
| Model | Log | pass@1 | stderr | solved |
|---|---|---|---|---|
Base RedHatAI/Llama-3.1-8B-Instruct | llama31-instruct-humaneval | 0.6951 | 0.0361 | 114 / 164 |
| phi-lattice v2 | llama31-instruct-humaneval-v2 | 0.6463 | 0.0374 | 106 / 164 |
v2 solved 8 fewer tasks. The gap is 0.049. The combined stderr is 0.052, so the drop is about one error bar.
v2 was scored from unrolled_bf16: the packed archive is unpacked once, then generation matches the base run.