Run this model with HF Jobs

Run Xylolabs/gemma-4-12B-it-qat-q4_0-unquantized-Tenstorrent-Tensix on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs to fine-tune https://huggingface.co/Xylolabs/gemma-4-12B-it-qat-q4_0-unquantized-Tenstorrent-Tensix. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/Xylolabs/gemma-4-12B-it-qat-q4_0-unquantized-Tenstorrent-Tensix on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
hletrd's picture
Fix dual light/dark logo rendering with HTML5 <picture>
cca6e03 verified
|
Raw History Blame Contribute Delete
5.9 kB
metadata
license: apache-2.0
base_model:
  - google/gemma-4-12B-it-qat-q4_0-unquantized
base_model_relation: quantized
library_name: transformers
pipeline_tag: any-to-any
language:
  - en
  - ko
tags:
  - tenstorrent
  - tensix
  - tt-metal
  - ttnn
  - tt-forge
  - block-floating-point
  - bfloat4_b
  - bfloat8_b
  - quantized
Xylolabs

Gemma 4 12B QAT for Tenstorrent Tensix

Base model Formats License Code Tenstorrent Tensix

These weights from google/gemma-4-12B-it-qat-q4_0-unquantized are quantized for Tenstorrent Tensix NPUs, with each format in its own folder.

Folders

Folder Formats Size (GB, packed) Mean KL to BF16 Top-1 (%)
Xylolabs BFP4-gateup bfp4-gateup/ MLP gate and up bfloat4_b (GPTQ with per-block exponent search), attention and MLP down bfloat8_b (round to nearest), tied LM head, embedding, norms, audio, vision, and other tensors bf16 10.765 0.03348 92.88
Xylolabs BFP8 bfp8/ Attention and MLP bfloat8_b (GPTQ), tied LM head, embedding, norms, audio, vision, and other tensors bf16 13.596 0.001488625 -

All files and rivals: BENCHMARKS.md

KL and top-1 cover 8,048 scored positions on the saved English and Korean chat texts (WikiText-2 test and Korean Wikipedia), four chunks per language.

How to run

Use Transformers 5.23.0 with PyTorch and accelerate.

hf download Xylolabs/gemma-4-12B-it-qat-q4_0-unquantized-Tenstorrent-Tensix --include "bfp4-gateup/*" --local-dir gemma-4-12B-it-qat-q4_0-unquantized-Tenstorrent-Tensix
hf download Xylolabs/gemma-4-12B-it-qat-q4_0-unquantized-Tenstorrent-Tensix --include "bfp8/*" --local-dir gemma-4-12B-it-qat-q4_0-unquantized-Tenstorrent-Tensix
from transformers import AutoTokenizer, Gemma4UnifiedForConditionalGeneration

d = "gemma-4-12B-it-qat-q4_0-unquantized-Tenstorrent-Tensix/bfp4-gateup"
tok = AutoTokenizer.from_pretrained(d)
model = Gemma4UnifiedForConditionalGeneration.from_pretrained(d, dtype="bfloat16", device_map="auto")

messages = [{"role": "user", "content": "What is the capital of France?"}]
inputs = tok.apply_chat_template(messages, add_generation_prompt=True, tokenize=True,
                                 return_tensors="pt", return_dict=True).to(model.device)
out = model.generate(**inputs, max_new_tokens=64)
print(tok.decode(out[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True))

Run on Tensix

Pack one matrix.

import json
import torch
import ttnn
from safetensors import safe_open

d = "gemma-4-12B-it-qat-q4_0-unquantized-Tenstorrent-Tensix/bfp4-gateup"
name = "model.language_model.layers.0.mlp.gate_proj.weight"
fmt = json.load(open(f"{d}/quant4.json"))["layers"]["0"]["mlp.gate_proj"]["format"]
dtype = {"bfp4": ttnn.bfloat4_b, "bfp8": ttnn.bfloat8_b}[fmt]
shard = json.load(open(f"{d}/model.safetensors.index.json"))["weight_map"][name]
with safe_open(f"{d}/{shard}", "pt") as f:
    w = f.get_tensor(name).t().contiguous()

device = ttnn.open_device(device_id=0)
w_tt = ttnn.as_tensor(w, dtype=dtype, layout=ttnn.TILE_LAYOUT,
                      device=device, memory_config=ttnn.DRAM_MEMORY_CONFIG)
assert torch.equal(ttnn.to_torch(w_tt).float(), w.float())
ttnn.close_device(device)
d=gemma-4-12B-it-qat-q4_0-unquantized-Tenstorrent-Tensix/bfp4-gateup
python "$d/pack_tensix.py" "$d"
python "$d/verify_grid.py" "$d"

Add --device to pack_tensix.py to round-trip the packed values. To use BFP8, substitute bfp8 for bfp4-gateup in the local paths.

Updates

  • 2026-12-05: Moved the full comparison to BENCHMARKS.md.
  • 2026-11-29: Merged the BFP4-GateUp and BFP8 repos into one repo with a folder per format.
  • 2026-11-22: Corrected the BF16 size for bfp4-gateup/ in the summary to match the evaluation table.

License

Apache 2.0, as declared by the base model (LICENSE). The changes are listed in NOTICE.

The bfp4-gateup/ copies of pack_tensix.py and verify_grid.py are from commit 5c52065. The bfp8/ copies are from tensix-bfp-gptq v0.1.0, under bfp8/CODE_LICENSE.

Citation

Cite the original Google release and the Gemma 4 Technical Report.

@misc{gemmateam2026gemma4,
      title={Gemma 4 Technical Report},
      author={Gemma Team},
      year={2026},
      eprint={2607.02770},
      archivePrefix={arXiv},
      primaryClass={cs.CL},
      url={https://arxiv.org/abs/2607.02770},
}