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.
File size: 5,895 Bytes
52843c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cca6e03
 
 
 
 
52843c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e36a376
 
74a78f1
 
 
 
52843c8
5c34fea
52843c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74a78f1
52843c8
 
 
 
 
5c34fea
52843c8
5c34fea
52843c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
---
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
---

<div align="center">

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/XylolabsInc/tensix-bfp-gptq/main/assets/xylolabs-lockup-dark.svg">
  <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/XylolabsInc/tensix-bfp-gptq/main/assets/xylolabs-lockup.svg">
  <img class="mx-auto" alt="Xylolabs" src="https://raw.githubusercontent.com/XylolabsInc/tensix-bfp-gptq/main/assets/xylolabs-lockup.svg" width="256" height="40">
</picture>

<h1>Gemma 4 12B QAT for Tenstorrent Tensix</h1>

[![Base model](https://img.shields.io/badge/base-google%2Fgemma--4--12B--it--qat--q4__0--unquantized-blue)](https://huggingface.co/google/gemma-4-12B-it-qat-q4_0-unquantized)
[![Formats](https://img.shields.io/badge/formats-BFP4--GateUp%20%2F%20BFP8-5B2C83)](#folders)
[![License](https://img.shields.io/badge/license-Apache--2.0-green)](https://huggingface.co/Xylolabs/gemma-4-12B-it-qat-q4_0-unquantized-Tenstorrent-Tensix/blob/main/LICENSE)
[![Code](https://img.shields.io/badge/code-tensix--bfp--gptq-black)](https://github.com/XylolabsInc/tensix-bfp-gptq)
[![Tenstorrent Tensix](https://img.shields.io/badge/Tenstorrent-Tensix-5B2C83)](https://docs.tenstorrent.com)

</div>

These weights from [google/gemma-4-12B-it-qat-q4_0-unquantized](https://huggingface.co/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](./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`.

```bash
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
```

```python
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.

```python
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)
```

```bash
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](https://github.com/XylolabsInc/tensix-bfp-gptq/tree/5c52065fffec88021a0703a1bfe5266e4c674711/tools). The `bfp8/` copies are from [tensix-bfp-gptq v0.1.0](https://github.com/XylolabsInc/tensix-bfp-gptq/tree/e889353de041209696cf4932339613b5ebe5daa6/tools), under `bfp8/CODE_LICENSE`.

## Citation

Cite the [original Google release](https://huggingface.co/google/gemma-4-12B-it-qat-q4_0-unquantized) and the Gemma 4 Technical Report.

```bibtex
@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},
}
```