Text Generation
Transformers
Safetensors
English
diffusion-gemma
block-diffusion
mixture-of-experts
Mixture of Experts
tinystories
tiny-model
validation
debug-model
Instructions to use shibatch/tinydiffusiongemmamoe4m with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use shibatch/tinydiffusiongemmamoe4m with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="shibatch/tinydiffusiongemmamoe4m")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("shibatch/tinydiffusiongemmamoe4m", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use shibatch/tinydiffusiongemmamoe4m with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "shibatch/tinydiffusiongemmamoe4m" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "shibatch/tinydiffusiongemmamoe4m", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/shibatch/tinydiffusiongemmamoe4m
- SGLang
How to use shibatch/tinydiffusiongemmamoe4m with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "shibatch/tinydiffusiongemmamoe4m" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "shibatch/tinydiffusiongemmamoe4m", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "shibatch/tinydiffusiongemmamoe4m" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "shibatch/tinydiffusiongemmamoe4m", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use shibatch/tinydiffusiongemmamoe4m with Docker Model Runner:
docker model run hf.co/shibatch/tinydiffusiongemmamoe4m
File size: 12,450 Bytes
d657346 | 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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | ---
library_name: transformers
pipeline_tag: text-generation
language:
- en
license: mit
datasets:
- roneneldan/TinyStories
tags:
- diffusion-gemma
- block-diffusion
- mixture-of-experts
- moe
- tinystories
- tiny-model
- text-generation
- validation
- debug-model
---
# Tiny Diffusion Gemma MoE 4M
This repository contains a tiny, text-only `DiffusionGemmaForBlockDiffusion`
Mixture-of-Experts language model trained from scratch on TinyStories.
The model is intentionally small: it has **4,190,512 parameters** and an
8-token diffusion canvas. It is primarily intended for validation, debugging,
and experimentation with the Diffusion Gemma implementation in Hugging Face
Transformers.
This is a synthetic tiny checkpoint. It is not an official Google model, does
not contain weights from an original Gemma checkpoint, and should not be
expected to match the quality of production language models.
## Repository contents
- `hf/`: recommended EMA checkpoint using an exponential moving average of the
weights during the final 140,000-step training segment
- `eval_text_generation.json`: final example generations
- `artifact_metadata.json`: training arguments and evaluation metrics
- `diffusion_gemma_config_dump.json`: expanded model configuration
Only the recommended EMA checkpoint is included in this distribution package.
Its aggregate validation metrics were slightly better than the final
non-averaged checkpoint, and its sampled outputs were generally more readable
in the final evaluation.
## Model purpose
This model is designed for:
- testing `DiffusionGemmaConfig`
- testing `DiffusionGemmaForBlockDiffusion`
- checking block-diffusion generation
- exercising first-pass and self-conditioned second-pass prediction
- testing Diffusion Gemma MoE expert routing
- exercising sliding-attention and full-attention layers
- exercising grouped-query attention
- validating custom tokenizer save/load behavior
- checking `save_pretrained()` and `from_pretrained()`
- providing a compact checkpoint for inference-engine development
It is not designed for:
- instruction following
- chat use
- high-quality long-form generation
- benchmark comparison with production language models
- production deployment
- image input or multimodal use
- reproducing the behavior of an official Gemma checkpoint
## Model architecture
The model uses `DiffusionGemmaForBlockDiffusion` with a small Diffusion
Gemma-style encoder/decoder and MoE configuration.
```yaml
model_type: diffusion_gemma
architecture: DiffusionGemmaForBlockDiffusion
parameter_count: 4,190,512
trainable_parameter_count: 4,147,360
vocab_size: 1,003
hidden_size: 128
intermediate_size: 384
moe_intermediate_size: 192
num_hidden_layers: 8
num_attention_heads: 4
num_key_value_heads: 1
num_global_key_value_heads: 1
head_dim: 32
global_head_dim: 32
num_experts: 4
top_k_experts: 2
layer_pattern: sssssFsF
sliding_window: 64
max_position_embeddings: 1,024
canvas_length: 8
hidden_activation: gelu_pytorch_tanh
tie_word_embeddings: true
rms_norm_eps: 1.0e-6
```
The attention pattern is:
```text
sssssFsF
```
where `s` means `sliding_attention` and `F` means `full_attention`. The final
layer uses full attention.
The checkpoint includes the minimal vision modules required by the
Diffusion Gemma configuration schema, but those modules were frozen and were
not trained. This checkpoint is text-only.
## MoE configuration
Each decoder layer contains four local experts and routes each token to the
top two experts:
```yaml
num_experts: 4
top_k_experts: 2
moe_intermediate_size: 192
```
This configuration keeps the checkpoint small while exercising router
parameters, expert dispatch, weighted expert combination, and interaction
between MoE blocks and both attention types.
## Training data
The model was trained on the full TinyStories training corpus:
```yaml
training_rows: 2,098,522
validation_rows: 21,197
validation_fraction: 0.01
training_blocks: 9,764,172
validation_blocks: 98,619
block_size: 64
```
Stories were tokenized as a continuous stream:
```text
BOS + story 1 + EOS + BOS + story 2 + EOS + ...
```
The stream was packed into fixed 64-token blocks without padding. Only the
final incomplete block was discarded.
## Tokenizer
The checkpoint uses a small custom byte-level BPE tokenizer. The base BPE
vocabulary was trained with:
```text
BPE()
ByteLevel(add_prefix_space=False)
vocab_size: 1,000
min_frequency: 2
normalizer: None
```
Special tokens were added after BPE training:
```text
<s> -> 1000
</s> -> 1001
<|im_start|> -> 1002
```
The tokenizer uses:
```yaml
bos_token: <s>
eos_token: </s>
pad_token: <s>
```
Use `PreTrainedTokenizerFast` directly. `AutoTokenizer` may not infer this
minimal custom tokenizer correctly in every Transformers version.
## Training setup
The checkpoint was trained in float32 on an NVIDIA GeForce GTX 1650.
```yaml
dtype: float32
batch_size: 8
gradient_accumulation_steps: 2
effective_batch_size: 16
block_size: 64
ar_steps: 10,000
partial_diffusion_steps: 5,000
full_diffusion_steps_cumulative: 220,000
ar_learning_rate: 2.0e-4
diffusion_learning_rate_initial: 1.0e-4
minimum_learning_rate: 1.0e-5
adam_beta1: 0.9
adam_beta2: 0.95
adam_eps: 1.0e-8
weight_decay: 0.01
grad_clip: 1.0
ema_decay: 0.999
```
Training used three phases:
1. 10,000 autoregressive warmup updates.
2. 5,000 partial-diffusion updates with at most four corrupted canvas tokens.
3. 220,000 cumulative full-diffusion updates with up to all eight canvas
tokens corrupted.
The original long run was interrupted after 89,483 full-diffusion updates.
Training resumed from the complete 80,000-step checkpoint for another 140,000
updates. The final checkpoint therefore represents 220,000 cumulative
full-diffusion updates, but it is not an uninterrupted optimizer trajectory.
The optimizer and EMA accumulator were restarted for the final 140,000-step
segment.
At batch size 8 with two gradient-accumulation steps, the cumulative
full-diffusion phase consumed approximately 0.36 packed-data epochs.
## Evaluation
The final EMA checkpoint produced:
```yaml
autoregressive_validation_loss: 2.0143
autoregressive_validation_perplexity: 7.4955
```
Diffusion evaluation used stochastic corruption and reports second-pass metrics
over the complete 8-token canvas:
| Corrupted canvas tokens | Validation loss | Accuracy |
| ---: | ---: | ---: |
| 2 of 8 | 0.6831 | 0.8613 |
| 4 of 8 | 1.5972 | 0.6719 |
| 6 of 8 | 3.1330 | 0.4316 |
| 8 of 8 | 4.8636 | 0.1406 |
The unweighted mean across these four corruption levels is approximately:
```yaml
mean_diffusion_validation_loss: 2.5692
mean_diffusion_accuracy: 0.5264
```
These values were computed over eight validation batches and should be treated
as compact checkpoint diagnostics, not as general language-model benchmarks.
## Example generation
Examples below come from the final EMA checkpoint with the saved generation
settings.
### Prompt: `Once upon`
```text
Once upon a time, there was a little girl. She loved to play on the swings and
play. One day, she decided to go.
```
### Prompt: `There was a little`
```text
There was a little girl named Lily. She liked to play with her toys and spend
all her toys in her room with her mommy. One day, she went to play with her
toys and Lily saw a beautiful yellow berriy. She wanted to make it, but her
mom said her it was right. Her
```
### Prompt: `One day`
```text
One day, a little girl named Mia and Ben went walking in the park. They saw a
big block and a big car. Lily wanted to toub it, but she just wanted it.
"Oh, Ben, what is that, doing?" Ben asked.
"Well,
```
The model has learned recognizable TinyStories-style English, but malformed
words, grammatical errors, unfinished sentences, repetition, and semantic
drift are expected.
## Usage
This example loads the recommended EMA checkpoint from the `hf` subdirectory.
```python
import torch
from transformers import (
DiffusionGemmaForBlockDiffusion,
DiffusionGemmaGenerationConfig,
EntropyBoundSamplerConfig,
PreTrainedTokenizerFast,
)
repo = "shibatch/tinydiffusiongemmamoe4m"
subfolder = "hf"
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
tokenizer = PreTrainedTokenizerFast.from_pretrained(
repo,
subfolder=subfolder,
)
model = DiffusionGemmaForBlockDiffusion.from_pretrained(
repo,
subfolder=subfolder,
dtype=torch.float32,
).to(device)
model.eval()
generation_config = DiffusionGemmaGenerationConfig(
max_new_tokens=64,
max_denoising_steps=64,
sampler_config=EntropyBoundSamplerConfig(entropy_bound=1.0),
t_min=0.4,
t_max=0.8,
stability_threshold=3,
confidence_threshold=0.05,
bos_token_id=tokenizer.bos_token_id,
eos_token_id=tokenizer.eos_token_id,
pad_token_id=tokenizer.pad_token_id,
cache_implementation="dynamic",
return_dict_in_generate=True,
)
prompt = "Once upon"
input_ids = torch.tensor(
[[tokenizer.bos_token_id] + tokenizer.encode(
prompt,
add_special_tokens=False,
)],
dtype=torch.long,
device=device,
)
with torch.no_grad():
output = model.generate(
input_ids=input_ids,
generation_config=generation_config,
)
sequences = output.sequences if hasattr(output, "sequences") else output
print(tokenizer.decode(sequences[0].tolist(), skip_special_tokens=True))
```
## Loading requirements
The checkpoint requires a Transformers release that includes:
```python
from transformers import (
DiffusionGemmaConfig,
DiffusionGemmaForBlockDiffusion,
DiffusionGemmaGenerationConfig,
EntropyBoundSamplerConfig,
)
```
The checkpoint was trained and tested with:
```text
transformers 5.14.1
torch 2.14.0.dev20260720+cu126
```
If these Diffusion Gemma imports fail, install a newer Transformers release
that includes the architecture.
The usage example constructs `DiffusionGemmaGenerationConfig` explicitly so
that its nested `EntropyBoundSamplerConfig` is restored as the correct config
class rather than as a plain dictionary.
## Intended validation coverage
This checkpoint is intended to validate support for:
- `DiffusionGemmaConfig`
- `DiffusionGemmaForBlockDiffusion`
- `DiffusionGemmaGenerationConfig`
- `EntropyBoundSamplerConfig`
- block-diffusion generation with an 8-token canvas
- first-pass prediction
- detached self-conditioning logits
- second-pass self-conditioned prediction
- stochastic token corruption
- sliding attention
- full attention
- GQA with one key/value head
- four local MoE experts
- top-2 expert routing
- tied token embeddings
- custom byte-level BPE loading
- `generate()`
- `save_pretrained()`
- `from_pretrained()`
## Limitations
Known limitations include:
- very small model capacity
- small 1,003-token vocabulary
- malformed or invented words
- weak semantic consistency
- weak long-form coherence
- repetition and TinyStories template collapse
- only an 8-token diffusion canvas
- no instruction tuning
- no chat template
- no image or multimodal capability
- no production-use claim
- no quality-equivalence claim with official Gemma models
- no current llama.cpp or GGUF inference support for this architecture
The checkpoint is most useful for testing and improving Diffusion Gemma
implementations without downloading a large model.
## Why include MoE?
A dense tiny model would be simpler, but it would not cover the MoE router,
expert dispatch, top-k selection, or expert output-combination paths. Four
experts with top-2 routing provide useful implementation coverage while keeping
the checkpoint compact.
## Why mix sliding and full attention?
A full-attention-only model would not exercise Diffusion Gemma's local
attention path. The `sssssFsF` pattern covers both implementations and keeps
the final layer globally attentive.
## Notes on GGUF and quantization
The checkpoint is distributed as normal float32 Hugging Face Safetensors.
Current llama.cpp conversion tools do not support
`DiffusionGemmaForBlockDiffusion`, and llama.cpp does not provide the matching
block-diffusion inference graph. A GGUF container could be produced with a
custom converter, but it would not currently be usable for inference in
llama.cpp.
## Citation
This is a synthetic tiny Diffusion Gemma-compatible MoE checkpoint trained
from scratch on TinyStories. It is intended for implementation testing,
debugging, and small-scale block-diffusion experiments.
|