4-bit phi-lattice v2 build of Falah/vit-base-breast-cancer (85.8M parameter Vision Transformer for breast cancer histopathological image classification, 200 / 200 tensors).
vit-base-breast-cancer-phi-lattice-v2/
├── vit_phi_v2_packed_4bit.pt # 44.8 MiB (46.9 MB) 4-bit packed archive (all 200/200 tensors)
├── phi_loader.py # Standalone loader (low_vram_4bit, triton_4bit, unrolled_fp32)
├── phi_lut_gemm.py # Fused Triton 4-bit LUT-GEMM kernel (all 72 Linear layers K%64==0)
├── model.safetensors # Unrolled FP32 fallback for standard AutoModel loading
├── config.json & preprocessor_config.json
├── vit_v2_comparison.png # 4-way visual & quantitative comparison chart
└── README.md
| Checkpoint Variant | Disk Size | RAM / GPU VRAM Footprint | Savings vs FP32 |
|---|---|---|---|
Upstream Falah/vit-base-breast-cancer (FP32) |
327.3 MiB (343.2 MB) |
327.30 MiB |
1.00x |
vit_phi_v2_packed_4bit.pt (low_vram_4bit / triton_4bit) |
44.8 MiB (46.9 MB) |
46.33 MiB |
7.06x RAM/VRAM savings |
Baseline FP32 vs Uniform vs phi-lattice v1 vs phi-lattice v2)| Method | Memory Footprint | 4-bit Weight SQNR | 4-bit Logit MSE | 3-bit Weight SQNR | 3-bit Logit MSE | Top-1 Agreement vs FP32 |
|---|---|---|---|---|---|---|
1. Baseline (FP32) |
327.3 MiB | Reference | 0.00000 | Reference | 0.00000 | 100.0% |
| 2. Standard Uniform | 46.3 MiB | 18.87 dB | 0.00033 | 11.80 dB | 0.00603 | 100.0% |
3. phi-lattice v1 |
46.3 MiB | 18.60 dB | 0.00047 | 12.52 dB | 0.00143 | 100.0% |
4. phi-lattice v2 (This Repo) |
46.3 MiB (7.06x smaller) |
19.51 dB | 0.00028 | 12.77 dB | 0.00134 (4.5x lower error than Uniform) |
100.0% |
phi_loader.py (low_vram_4bit = 46.33 MiB RAM/VRAM, skips 343 MB safetensors)import importlib.util
from huggingface_hub import hf_hub_download
from transformers import AutoImageProcessor
repo_id = "ununununununununununununununununununun/vit-base-breast-cancer-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: "low_vram_4bit" (46.3 MiB memory), "triton_4bit" (fused GPU LUT-GEMM), or "unrolled_fp32"
model = phi_loader.load_vit_from_packed_4bit(repo_id=repo_id, mode="low_vram_4bit")
processor = AutoImageProcessor.from_pretrained(repo_id)
weights_only=True)import math, torch
from transformers import AutoConfig, AutoModelForImageClassification
from huggingface_hub import hf_hub_download
REPO = "ununununununununununununununununununun/vit-base-breast-cancer-phi-lattice-v2"
model = AutoModelForImageClassification.from_config(AutoConfig.from_pretrained(REPO))
blob = torch.load(
hf_hub_download(REPO, "vit_phi_v2_packed_4bit.pt"),
map_location="cpu",
weights_only=True,
)
cb = blob["codebook"].float()
sd = {k: v.float() for k, v in blob["protected_tensors"].items()}
for name, item in blob["layers"].items():
if "fp16_weight" in item:
sd[f"{name}.weight"] = item["fp16_weight"].float()
else:
n, g = math.prod(item["shape"]), int(item["group_size"])
ng = math.ceil(n / g)
p = item["packed_indices"]
idx = torch.stack([p & 0x0F, (p >> 4) & 0x0F], dim=-1).reshape(-1)[: ng * g].long()
sd[f"{name}.weight"] = (cb[idx].view(ng, g) * item["scales"].float()).reshape(-1)[:n].view(item["shape"])
if item.get("bias") is not None:
sd[f"{name}.bias"] = item["bias"].float()
model.load_state_dict(sd, strict=True)
有文件?提交种子。
发布种子model.safetensors 327 MiBvit_phi_v2_packed_4bit.pt 45 MiB