Text Generation
Transformers
Safetensors
sumi
mask-generation
diffusion
discrete-diffusion
uniform-diffusion
custom_code
Instructions to use tohoku-nlp/sumi-7b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tohoku-nlp/sumi-7b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="tohoku-nlp/sumi-7b", trust_remote_code=True)# Load model directly from transformers import AutoModelForMaskGeneration model = AutoModelForMaskGeneration.from_pretrained("tohoku-nlp/sumi-7b", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use tohoku-nlp/sumi-7b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tohoku-nlp/sumi-7b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tohoku-nlp/sumi-7b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/tohoku-nlp/sumi-7b
- SGLang
How to use tohoku-nlp/sumi-7b 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 "tohoku-nlp/sumi-7b" \ --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": "tohoku-nlp/sumi-7b", "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 "tohoku-nlp/sumi-7b" \ --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": "tohoku-nlp/sumi-7b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use tohoku-nlp/sumi-7b with Docker Model Runner:
docker model run hf.co/tohoku-nlp/sumi-7b
Update README.md
Browse files
README.md
CHANGED
|
@@ -8,22 +8,20 @@ tags:
|
|
| 8 |
- uniform-diffusion
|
| 9 |
---
|
| 10 |
|
|
|
|
|
|
|
| 11 |
# Sumi-7B
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
|
| 20 |
-
|
| 21 |
-
- 36 layers, hidden 4096, 32 heads / 8 KV heads, vocab 100,278, context 4,864.
|
| 22 |
-
- `model_type: "sumi"`, loaded via `trust_remote_code=True`.
|
| 23 |
|
| 24 |
-
|
| 25 |
-
> ships its own modeling code; pass `trust_remote_code=True`. The tokenizer is bundled in
|
| 26 |
-
> this repo.
|
| 27 |
|
| 28 |
## Quickstart
|
| 29 |
|
|
@@ -31,104 +29,37 @@ canvas of random tokens appended to the prompt and **iteratively denoises** it.
|
|
| 31 |
import torch
|
| 32 |
from transformers import AutoModelForMaskGeneration, AutoTokenizer
|
| 33 |
|
| 34 |
-
model_id = "tohoku-nlp/sumi-7b"
|
| 35 |
-
|
| 36 |
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
|
| 37 |
model = AutoModelForMaskGeneration.from_pretrained(
|
| 38 |
model_id, trust_remote_code=True, dtype=torch.bfloat16
|
| 39 |
).to("cuda").eval()
|
| 40 |
|
| 41 |
-
prompt = "
|
| 42 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 43 |
-
|
| 44 |
out = model.generate(
|
| 45 |
**inputs,
|
| 46 |
-
max_new_tokens=
|
| 47 |
-
num_denoising_steps=
|
| 48 |
-
|
|
|
|
| 49 |
)
|
| 50 |
print(tokenizer.decode(out.sequences[0], skip_special_tokens=True))
|
| 51 |
```
|
| 52 |
|
| 53 |
-
`generate` returns
|
| 54 |
-
max_new_tokens]` (prompt followed by the generated completion). It is a drop-in custom
|
| 55 |
-
generation loop — `AutoModelForMaskGeneration` also works and is the semantically exact
|
| 56 |
-
auto-class.
|
| 57 |
-
|
| 58 |
-
## Generation parameters
|
| 59 |
-
|
| 60 |
-
The diffusion generation loop replaces the usual autoregressive decoding knobs. The
|
| 61 |
-
parameters you will normally set:
|
| 62 |
-
|
| 63 |
-
| parameter | default | description |
|
| 64 |
-
|---|---|---|
|
| 65 |
-
| `max_new_tokens` | — (required) | Length of the completion. These tokens are initialised at random and denoised; the prompt stays fixed. |
|
| 66 |
-
| `num_denoising_steps` | `128` | Number of denoising iterations. More steps → better quality at higher cost; quality saturates after a couple hundred. **This is the main quality/compute dial.** |
|
| 67 |
-
| `sampler` | `"ancestral"` | `"ancestral"` — stochastic sampling from the analytic diffusion posterior (good general-purpose default). `"adaptive"` — confidence-based: each step commits only the most-confident position(s) and revises the rest, which gives sharper, more coherent outputs on structured tasks (e.g. code, math). |
|
| 68 |
-
| `temperature` | `1.0` | Sampling temperature. **`0.7` is the recommended canonical setting.** Lower → more decisive denoising. |
|
| 69 |
-
| `seed` / `generator` | `None` | Set a `seed` (int) or pass a `torch.Generator` for reproducible samples. |
|
| 70 |
-
|
| 71 |
-
```python
|
| 72 |
-
# More coherent / "decisive" decoding, e.g. for code or math:
|
| 73 |
-
out = model.generate(**inputs, max_new_tokens=256,
|
| 74 |
-
num_denoising_steps=256, sampler="adaptive", temperature=0.7)
|
| 75 |
-
```
|
| 76 |
-
|
| 77 |
-
### Advanced knobs
|
| 78 |
-
|
| 79 |
-
You rarely need these; defaults are fine for normal use.
|
| 80 |
-
|
| 81 |
-
| parameter | default | description |
|
| 82 |
-
|---|---|---|
|
| 83 |
-
| `tokens_per_step` | `1` | `adaptive` sampler only: how many positions to commit per step. Keep at `1`. |
|
| 84 |
-
| `schedule` | `"linear"` | `ancestral` only: log-SNR noise schedule, `"linear"` or `"cosine"`. |
|
| 85 |
-
| `min_log_snr` / `max_log_snr` | `-9.0` / `9.0` | `ancestral` only: bounds of the SNR schedule. |
|
| 86 |
-
| `frozen` | `None` | Pin `(position, token_id)` pairs at fixed canvas positions (kept fixed during denoising). Used for in-filling and for the `[EOS][BOS]` document-boundary **anchor** used in evaluation. |
|
| 87 |
-
| `denoise_end` | `None` | Per-row exclusive upper bound; freezes the tail of the canvas so the step budget concentrates on the content window. |
|
| 88 |
-
|
| 89 |
-
## How it works
|
| 90 |
-
|
| 91 |
-
1. The prompt is placed at the front of a canvas of length `prompt_len + max_new_tokens`.
|
| 92 |
-
2. The completion region is filled with **uniformly random** vocabulary tokens (there is
|
| 93 |
-
no `[MASK]` token — this is *uniform* diffusion).
|
| 94 |
-
3. For `num_denoising_steps`, the model does one bidirectional forward over the whole
|
| 95 |
-
canvas and updates the completion region (the prompt is frozen). `ancestral` resamples
|
| 96 |
-
every completion position from the analytic posterior each step; `adaptive` commits the
|
| 97 |
-
highest-confidence position(s) and leaves the rest for later steps.
|
| 98 |
-
4. The final denoised canvas is returned.
|
| 99 |
-
|
| 100 |
-
There is no KV cache (every step is a full bidirectional pass), so cost scales with
|
| 101 |
-
`num_denoising_steps × sequence_length²`.
|
| 102 |
-
|
| 103 |
-
## Evaluation
|
| 104 |
-
|
| 105 |
-
Sumi is scored with diffusion-native metrics: a Monte-Carlo estimate of the diffusion
|
| 106 |
-
**NELBO** for multiple-choice / log-likelihood tasks, and iterative denoising for
|
| 107 |
-
generative tasks. A companion [`lm-evaluation-harness`](https://github.com/EleutherAI/lm-evaluation-harness)
|
| 108 |
-
plugin (`sumi-eval`, `--model sumi`) implements this end-to-end.
|
| 109 |
-
|
| 110 |
-
Representative 0-shot results (the HF conversion reproduces the original training-stack
|
| 111 |
-
model — ARC-Easy acc_norm agrees within sampling CI and the diffusion NELBO is a byte-exact
|
| 112 |
-
port):
|
| 113 |
-
|
| 114 |
-
| task | metric | score |
|
| 115 |
-
|---|---|---|
|
| 116 |
-
| ARC-Easy | acc_norm | ≈ 0.69 |
|
| 117 |
-
| HumanEval | pass@1 | 0.226 |
|
| 118 |
|
| 119 |
-
(HumanEval generated with `sampler="adaptive"`, `num_denoising_steps=256`,
|
| 120 |
-
`max_new_tokens=256`; scored on the raw model output, with no answer-extraction.)
|
| 121 |
|
| 122 |
## Citation
|
| 123 |
|
| 124 |
```bibtex
|
| 125 |
-
@misc{
|
| 126 |
-
title={Sumi
|
| 127 |
-
author={Mengyu Ye and Keito Kudo and Wataru Ikeda and Ryosuke Matsuda and Keisuke Sakaguchi and Jun
|
| 128 |
year={2026},
|
| 129 |
-
eprint={2606.
|
| 130 |
archivePrefix={arXiv},
|
| 131 |
-
primaryClass={cs.
|
| 132 |
-
url={https://arxiv.org/abs/2606.
|
| 133 |
-
}
|
| 134 |
```
|
|
|
|
| 8 |
- uniform-diffusion
|
| 9 |
---
|
| 10 |
|
| 11 |
+
|
| 12 |
+
|
| 13 |
# Sumi-7B
|
| 14 |
|
| 15 |
+
<p align="left">
|
| 16 |
+
<a href="https://www.nlp.ecei.tohoku.ac.jp/projects/sumi/"><img src="https://img.shields.io/badge/%F0%9F%8C%90%20Project%20HP-1f72b8" alt="Project Page"></a>
|
| 17 |
+
<a href="https://arxiv.org/abs/2606.19005"><img src="https://img.shields.io/badge/arXiv-2606.19005-b31b1b?logo=arxiv&logoColor=white" alt="arXiv"></a>
|
| 18 |
+
</p>
|
| 19 |
+
Sumi is a native uniform diffusion language model trained from scratch, so it runs full bidirectional attention and denoises a canvas of randomly corrupted tokens.
|
| 20 |
+
We provide Sumi in a custom model class, therefore you need to set `trust_remote_code=True` to use it in transformers.
|
| 21 |
|
| 22 |
+
We recommend `transformers==5.8.1`.
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
For more details, please refer to [our project page](https://www.nlp.ecei.tohoku.ac.jp/projects/sumi/) and [technical report](https://arxiv.org/abs/2606.19005).
|
|
|
|
|
|
|
| 25 |
|
| 26 |
## Quickstart
|
| 27 |
|
|
|
|
| 29 |
import torch
|
| 30 |
from transformers import AutoModelForMaskGeneration, AutoTokenizer
|
| 31 |
|
| 32 |
+
model_id = "tohoku-nlp/sumi-7b"
|
|
|
|
| 33 |
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
|
| 34 |
model = AutoModelForMaskGeneration.from_pretrained(
|
| 35 |
model_id, trust_remote_code=True, dtype=torch.bfloat16
|
| 36 |
).to("cuda").eval()
|
| 37 |
|
| 38 |
+
prompt = "Our journey into exploring diffusion language model begins,"
|
| 39 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
|
|
|
| 40 |
out = model.generate(
|
| 41 |
**inputs,
|
| 42 |
+
max_new_tokens=256, # content budget; the EOS/BOS delimiter is anchored here
|
| 43 |
+
num_denoising_steps=64, # refinement iterations — the main quality/compute dial
|
| 44 |
+
sampler="ancestral", # "ancestral" (default) or "adaptive" (sharper, for code/math)
|
| 45 |
+
temperature=0.7,
|
| 46 |
)
|
| 47 |
print(tokenizer.decode(out.sequences[0], skip_special_tokens=True))
|
| 48 |
```
|
| 49 |
|
| 50 |
+
`generate()` returns the trimmed completion in `out.sequences` and the full untrimmed canvas in `out.canvas`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
|
|
|
|
|
|
| 52 |
|
| 53 |
## Citation
|
| 54 |
|
| 55 |
```bibtex
|
| 56 |
+
@misc{ye2026sumi,
|
| 57 |
+
title={Sumi: Open Uniform Diffusion Language Model from Scratch},
|
| 58 |
+
author={Mengyu Ye and Keito Kudo and Wataru Ikeda and Ryosuke Matsuda and Keisuke Sakaguchi and Jun Suzuki},
|
| 59 |
year={2026},
|
| 60 |
+
eprint={2606.19005},
|
| 61 |
archivePrefix={arXiv},
|
| 62 |
+
primaryClass={cs.CL},
|
| 63 |
+
url={https://arxiv.org/abs/2606.19005},
|
| 64 |
+
}
|
| 65 |
```
|