--- library_name: pytorch tags: - nexttransformer - others - causal-lm - pretrained - safetensors pipeline_tag: text-generation --- # NextTransformer MQA All twelve query heads share one key head and one value head. This is the final Multi-Query Attention · MQA checkpoint in the NextTransformer 49.152B-token architecture comparison. It has 737,673,296 parameters and a 2,048-token context. The model was pretrained on ClimbMix for 46,875 updates. The 49B in the repository name refers to training tokens. Every layer keeps full causal attention with 12 query heads of dimension 128, but projects a single key/value head that every query reads. RoPE, the parameter-free QK RMSNorm and the ×1.2 scale act on the shared key once; the fused kernel broadcasts it, so the shared projections receive the sum of the query heads' gradients. Calibrated to 27 layers at FFN 6016 to fit the shared budget. | Final evaluation | Result | |---|---:| | Validation BPB | 0.6743 | | CORE-22 (×100) | 31.96 | [Architecture](https://github.com/Interactive-Active-AI/NextTransformer/blob/b2ea46627f7d0d5c9ef57a655c43b553558417d3/results/methods/mqa.json) · [Run record](https://github.com/Interactive-Active-AI/NextTransformer/blob/b2ea46627f7d0d5c9ef57a655c43b553558417d3/results/runs/mqa.json) Trained from scratch, not uptrained from a multi-head checkpoint. Value embeddings are disabled in this family because their width follows the key/value heads; the matching multi-head control without them has not been trained, so a gap to Dense cannot be attributed to key/value sharing alone. Attention arithmetic is charged per query head, and no KV-cache or decoding saving is measured. Single seed 42; trained from the frozen Others branch, not yet ported to the current code. The upstream run record reports completed training and the trainer's cumulative compute audit; its independent read-only audit remains pending. ## Load the weights The run record lists this checkpoint as trained from a frozen source revision whose shell is not in the current code: `ReferenceLM` always builds multi-head attention with value embeddings, while this run uses fewer key/value heads and no value embeddings. The example therefore builds the native shell directly from `model_config.json` and loads the weights strictly; the architecture itself is unchanged native attention. Install the tested NextTransformer implementation and the safetensors reader in a Python 3.10–3.13 environment. ```bash pip install "nexttransformer @ git+https://github.com/Interactive-Active-AI/NextTransformer.git@b2ea46627f7d0d5c9ef57a655c43b553558417d3" safetensors ``` The example encodes a prompt with the checkpoint's tokenizer and prints its most likely next token. ```python import base64 import json import os from pathlib import Path os.environ["CUDA_VISIBLE_DEVICES"] = "" # This example runs on CPU. import tiktoken import torch from huggingface_hub import snapshot_download from safetensors.torch import load_file from torch import nn from nexttransformer.models.backbone import GPT, GPTConfig from nexttransformer.models.lm import FlexibleMLP root = Path(snapshot_download("NextTransformer/MQA-49B-Tokens")) config = json.loads((root / "model_config.json").read_text()) model = GPT(GPTConfig( sequence_len=config["sequence_len"], vocab_size=config["vocab_size"], n_layer=config["layers"], n_embd=config["width"], n_head=config["heads"], n_kv_head=config["kv_heads"], window_pattern=config["window_pattern"], )) class _Widths: # FlexibleMLP reads only these two fields. width, mlp_width = config["width"], config["mlp_width"] for block in model.transformer.h: if config["mlp_width"] != 4 * config["width"]: block.mlp = FlexibleMLP(_Widths) block.attn.ve_gate = None # this run trains without value embeddings model.value_embeds = nn.ModuleDict() model.load_state_dict(load_file(root / "model.safetensors"), strict=True) model.eval() spec = json.loads((root / "tokenizer.tiktoken.json").read_text()) encoding = tiktoken.Encoding( name=spec["name"], pat_str=spec["pat_str"], mergeable_ranks={base64.b64decode(b): rank for b, rank in spec["mergeable_ranks"]}, special_tokens=spec["special_tokens"], ) prompt = [encoding.encode_single_token("<|bos|>")] + encoding.encode_ordinary("The sky is") with torch.inference_mode(): logits = model(torch.tensor([prompt])) print(encoding.decode([int(logits[0, -1].argmax())])) ```