Skip to content
Other

Tree-gram generators

a family of autoregressive text generators

2 min read

A collection of compact autoregressive models (which predict the next token from preceding ones) by hugs-from-a-25 for generating synthetic text corpora. Under the hood is the tree-gram architecture—a hierarchical structure that estimates the next token based on a window of n - 1 preceding tokens. The repository includes 30 model variants with varying context lengths (1 to 31 tokens) and layer widths d (64 to 1024), trained on three well-known datasets: TinyStories, WikiText-103, and FineWeb-Edu. It is useful for researchers and developers looking to quickly sample synthetic text, study context scaling, and experiment with lightweight generative models without the overhead of full-scale LLMs.

Key features

  • 30 pre-trained variants: 10 configurations for each of the three domains (TinyStories, WikiText-103, and FineWeb-Edu) spanning different context depths and dimensions.
  • Minimal dependencies: running the modeling_treegram.py script requires only torch and safetensors.
  • Classic bigram support: alongside the neural tree-gram models, the suite includes frequency-based bigram models in counts.npz format with uniform distribution fallback.
  • Full metric transparency: the model card reports exact entropy and validation loss in nats per token for every checkpoint.

What you can do

  • Generate synthetic datasets: produce text in the style of children's stories, encyclopedia articles, or educational content to train and test other models.
  • Benchmark context and width scaling: use the provided checkpoints to test how varying context length (1 to 31 tokens) and width d (64 to 1024) affect sampling quality and entropy.
  • Integrate into research pipelines: call the next_token_logits function to extract next-token logits and analyze probability distributions in your own PyTorch scripts.

Example

from huggingface_hub import snapshot_download
import sys
path = snapshot_download("hugs-from-a-25/tree-gram-generators", allow_patterns=["modeling_treegram.py", "tinystories/n8_d1024/*", "tokenizers/*"])
sys.path.insert(0, path)
from modeling_treegram import load_generator, sample
model, cfg = load_generator(f"{path}/tinystories/n8_d1024")
tokens = sample(model, n_tokens=200, batch=4, eos_token_id=cfg["eos_token_id"])
Read moreDetails
Weights are stored in model.safetensors format (float32), with config.json and generation.json included for each model.
Best validation loss per group: TinyStories (n32_d1024) — 1.7407, WikiText-103 (n32_d1024) — 3.9298, FineWeb-Edu (n16_d1024) — 4.2983 nats/token.
VRAM and hardware requirements are not specified in the model card.
Licenses depend on the corpus: CDLA-Sharing-1.0 (TinyStories), CC BY-SA 3.0 (WikiText-103), and ODC-By 1.0 (FineWeb-Edu).
Discuss Telegram 0

Will it run?

Runs in BF16

Fits without quantisation.

  • BF16weights 0.7 GB · ready files1.2 GB
  • FP8 / INT8recommendedweights 0.3 GB0.9 GB
  • 4-bitweights 0.2 GB0.7 GB

Tip: go 8-bit.FP8 / INT8 is within about a percent of full precision in quality, takes half the memory and runs faster on RTX 40/50 and H100. Full precision only pays off for fine-tuning.

What to get for this model

Massed ComputeOpen Massed Compute

Your own GPU: FP8 / INT8 — from RTX 2060 · BF16 — from RTX 2060

Massed Compute hourly prices, November 2026. The discounted price applies with the coupon at checkout.

Estimate: weights plus working memory. Long videos, high resolutions and long contexts need more.

Run it on Massed Compute

The script downloads the model to the rented machine. How to run it is in the model card.

  1. 1. Rent a machine with a fitting GPU

    Open Massed Compute
  2. 2. Paste the script into the machine's terminal

    Connect over SSH (the Massed Compute panel shows the command) or open a terminal on the machine's desktop.

    HF_TOKEN / CIVITAI_TOKENThe script starts with token lines: paste yours between the quotes. The Hugging Face token is for gated models, the Civitai one for Civitai models.

    # hugs-from-a-25/tree-gram-generators
    mkdir -p ~/models
    curl -LsSf https://astral.sh/uv/install.sh | sh
    source "$HOME/.local/bin/env"
    uv tool install "huggingface_hub[cli]"
    hf download hugs-from-a-25/tree-gram-generators --local-dir ~/models/tree-gram-generators
    # The model is in ~/models. How to run it is in the model card (link above).
    Add more LoRAs to tree-gram-generators
  3. 3. Use it

    The model is in ~/models. How to run it is in the model card (link above).

Stop the machine in the panel when you are done: it bills by the minute while it runs.

How to speed it up

Picked for this model type. Choose your hardware above to see what fits you exactly.

  • FlashAttention 44.0.0b40from November 18, 2026new release

    fastest exact attention on B200

    Kernels for Blackwell (beta). Exact attention without quantisation — fine for everything, LLMs included.

    How to enable: pip install flash-attn-4; vLLM and SGLang pick it up themselves.

    Earlier generations (2)
    • FlashAttention 3 — The Hopper (H100/H200) version with FP8.
    • FlashAttention 2 — The standard for RTX 30/40/50 and A100: exact attention without the memory cost of long contexts.
  • torch.compile2.15.0from October 28, 2026new release

    10–30% for free

    Compiles the model for your GPU. Slower first run, faster afterwards.

    How to enable: model = torch.compile(model); in ComfyUI the TorchCompileModel node.

Model family

New posts about versions of tree-gram-generators (quants, finetunes, LoRAs) will show up under the bell.

No known relatives of this model yet. All derivatives on Hugging Face

About the model

hugs-from-a-25/tree-gram-generators
Author
hugs-from-a-25
Category
Other
Released
Posted

On NeyroLearn

Hugging Face

00

Ask AI about this model

Answered by Gemini 4 · the chat is kept only in this tab

Comments

Other

mars-dfd-hr

mars-dfd-hr