--- 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](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)
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}, } ```