File size: 4,830 Bytes
b231d5b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: apache-2.0
task_categories:
- text-to-image
language:
- en
tags:
- diffusion
- alignment
- rlhf
- text-rendering
- synthetic
- sana
pretty_name: Diffusion Alignment Workshop (Sana-600M samples with rewards)
size_categories:
- 1K<n<10K
configs:
- config_name: default
  data_files:
  - split: train
    path: data/train-*.parquet
  - split: eval
    path: data/eval-*.parquet
---

# Diffusion Alignment Workshop dataset

Offline data for a hands-on workshop on **aligning a diffusion model with rewards** (SFT, RWR, DPO, online DPO, GRPO, DiffusionNFT, on-policy distillation). The model is [Sana-600M-512px](https://huggingface.co/Efficient-Large-Model/Sana_600M_512px_diffusers) and the task is **text rendering**: every prompt asks for a short string to be written in the image.

For every prompt there are **5 samples** of the model, each scored with four rewards. With it, a Colab student can run the offline methods without sampling or scoring anything, and the online methods without the 2.6B Gemma-2 text encoder. It is the alignment companion of [`leffff/diffusion-distillation-workshop`](https://huggingface.co/datasets/leffff/diffusion-distillation-workshop) (same model, same embedding format).

| split | prompts | samples |
|---|---|---|
| `train` | 2048 | 5 per prompt |
| `eval` | 64 | 5 per prompt |

Prompts come from [`leffff/Diffusion-Reward-Modeling-for-Text-Rendering-Dataset`](https://huggingface.co/datasets/leffff/Diffusion-Reward-Modeling-for-Text-Rendering-Dataset) (train / test splits), filtered to:
- exactly one quoted target, which must be **written in the image**: a rendering keyword next to the quote (`written`, `spelled`, `the word`, `sign`, `label`, `a mug that says`, ...), and not speech or an attribution (`he says "..."`, `"...", says Stan Lee`, `written by`);
- short ASCII targets that a 600M model at 512 px can plausibly render: at most 3 words and 16 characters;
- at most 2 prompts per target string (there are 219 "Happy Birthday" prompts in the source).

## Columns (one row per prompt)

| column | content |
|---|---|
| `prompt`, `text` | the prompt and the string that must appear in the image |
| `source_id` | the row id in the source dataset |
| `seeds` | 5 seeds, `torch.Generator("cuda").manual_seed(seed)` for the initial noise of each sample |
| `images` | 5 decoded 512×512 JPEGs (quality 95) |
| `latents` | `float16` bytes, shape `(5, 32, 16, 16)`. DC-AE latents in **model space** (the x₀ the transformer sees). Decode with `vae.decode(latent / 0.41407)` |
| `ocr` | 5 × OCR-Levenshtein reward in [0, 1]: `1 - min(d, len(t)) / len(t)`, where `d` is the fewest character edits that make the target `t` appear somewhere in the transcription (case, spaces and punctuation ignored) |
| `ocr_read` | 5 × what the OCR model ([Qwen3-VL-2B-Instruct](https://huggingface.co/Qwen/Qwen3-VL-2B-Instruct), greedy) read |
| `pickscore` | 5 × [PickScore](https://huggingface.co/yuvalkirstain/PickScore_v1) (`logit_scale · cos`, ≈ 15–25) |
| `aesthetic` | 5 × LAION aesthetic predictor v2 on CLIP ViT-L/14 ([weights](https://huggingface.co/trl-lib/ddpo-aesthetic-predictor), ≈ 1–10) |
| `clip` | 5 × CLIP score, `100 · cos(image, prompt)` with `openai/clip-vit-large-patch14` |
| `prompt_embeds` | `float16` bytes, shape `(128, 2304)`. Gemma-2 hidden states from Sana's `encode_prompt` with the complex human instruction, `max_sequence_length=128` |
| `prompt_attention_mask` | `uint8` bytes, shape `(128,)` |

`null_prompt_embeds.safetensors` holds the unconditional (empty negative prompt) embedding and mask for classifier-free guidance. `meta.json` holds all generation parameters and the reward definitions.

## Generation

`SanaPipeline` default sampler (flow DPM-Solver), 20 steps, CFG 4.5, 512×512, transformer in fp16, Gemma-2 in bf16, DC-AE in fp32, on H100s. The rewards are computed on the decoded fp32 images before JPEG encoding. Code: `generate_dataset.py` and `rewards.py` of the workshop.

## Loading

```python
import numpy as np, torch, pyarrow.parquet as pq
from huggingface_hub import hf_hub_download

path = hf_hub_download("leffff/diffusion-alignment-workshop", "data/train-00000-of-00008.parquet", repo_type="dataset")
t = pq.read_table(path, columns=["prompt", "text", "latents", "ocr", "prompt_embeds", "prompt_attention_mask"]).to_pydict()
latents = torch.from_numpy(np.stack([np.frombuffer(b, np.float16).reshape(5, 32, 16, 16) for b in t["latents"]]))
embeds = torch.from_numpy(np.stack([np.frombuffer(b, np.float16).reshape(128, 2304) for b in t["prompt_embeds"]]))
ocr = torch.tensor(t["ocr"])        # (n, 5)
```

## License

Apache-2.0 for the images, latents and rewards generated by the apache-2.0 Sana-600M model. The prompts come from the MIT-licensed `leffff/Diffusion-Reward-Modeling-for-Text-Rendering-Dataset`.