leffff commited on
Commit
b231d5b
·
verified ·
1 Parent(s): 5fa5c8c

Sana-600M samples with rewards for the diffusion alignment workshop

Browse files
README.md ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ task_categories:
4
+ - text-to-image
5
+ language:
6
+ - en
7
+ tags:
8
+ - diffusion
9
+ - alignment
10
+ - rlhf
11
+ - text-rendering
12
+ - synthetic
13
+ - sana
14
+ pretty_name: Diffusion Alignment Workshop (Sana-600M samples with rewards)
15
+ size_categories:
16
+ - 1K<n<10K
17
+ configs:
18
+ - config_name: default
19
+ data_files:
20
+ - split: train
21
+ path: data/train-*.parquet
22
+ - split: eval
23
+ path: data/eval-*.parquet
24
+ ---
25
+
26
+ # Diffusion Alignment Workshop dataset
27
+
28
+ 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.
29
+
30
+ 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).
31
+
32
+ | split | prompts | samples |
33
+ |---|---|---|
34
+ | `train` | 2048 | 5 per prompt |
35
+ | `eval` | 64 | 5 per prompt |
36
+
37
+ 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:
38
+ - 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`);
39
+ - short ASCII targets that a 600M model at 512 px can plausibly render: at most 3 words and 16 characters;
40
+ - at most 2 prompts per target string (there are 219 "Happy Birthday" prompts in the source).
41
+
42
+ ## Columns (one row per prompt)
43
+
44
+ | column | content |
45
+ |---|---|
46
+ | `prompt`, `text` | the prompt and the string that must appear in the image |
47
+ | `source_id` | the row id in the source dataset |
48
+ | `seeds` | 5 seeds, `torch.Generator("cuda").manual_seed(seed)` for the initial noise of each sample |
49
+ | `images` | 5 decoded 512×512 JPEGs (quality 95) |
50
+ | `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)` |
51
+ | `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) |
52
+ | `ocr_read` | 5 × what the OCR model ([Qwen3-VL-2B-Instruct](https://huggingface.co/Qwen/Qwen3-VL-2B-Instruct), greedy) read |
53
+ | `pickscore` | 5 × [PickScore](https://huggingface.co/yuvalkirstain/PickScore_v1) (`logit_scale · cos`, ≈ 15–25) |
54
+ | `aesthetic` | 5 × LAION aesthetic predictor v2 on CLIP ViT-L/14 ([weights](https://huggingface.co/trl-lib/ddpo-aesthetic-predictor), ≈ 1–10) |
55
+ | `clip` | 5 × CLIP score, `100 · cos(image, prompt)` with `openai/clip-vit-large-patch14` |
56
+ | `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` |
57
+ | `prompt_attention_mask` | `uint8` bytes, shape `(128,)` |
58
+
59
+ `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.
60
+
61
+ ## Generation
62
+
63
+ `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.
64
+
65
+ ## Loading
66
+
67
+ ```python
68
+ import numpy as np, torch, pyarrow.parquet as pq
69
+ from huggingface_hub import hf_hub_download
70
+
71
+ path = hf_hub_download("leffff/diffusion-alignment-workshop", "data/train-00000-of-00008.parquet", repo_type="dataset")
72
+ t = pq.read_table(path, columns=["prompt", "text", "latents", "ocr", "prompt_embeds", "prompt_attention_mask"]).to_pydict()
73
+ latents = torch.from_numpy(np.stack([np.frombuffer(b, np.float16).reshape(5, 32, 16, 16) for b in t["latents"]]))
74
+ embeds = torch.from_numpy(np.stack([np.frombuffer(b, np.float16).reshape(128, 2304) for b in t["prompt_embeds"]]))
75
+ ocr = torch.tensor(t["ocr"]) # (n, 5)
76
+ ```
77
+
78
+ ## License
79
+
80
+ 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`.
data/eval-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b689ebfc2b95b300aabf3ab4c81dfa23cd9f84631e1abf1fc1061a69e245a8a8
3
+ size 72422473
data/train-00000-of-00008.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:96b7d7297a6037fcd13d1b4b559a970e69881782fd2e25627f6e253341575264
3
+ size 293178793
data/train-00001-of-00008.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2c7ceb63141f8bd2467ecff4b49739731e5bab581701dd0558df7fbf9d249ea9
3
+ size 290671632
data/train-00002-of-00008.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:72d5ff7d5b119a29fb675178e1a98c5a3de93b00753d508bdac4341f92547cc0
3
+ size 292274392
data/train-00003-of-00008.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e66194b9e930d685a159ab8cec5c1148a7fdf6b26903681cee6d52c8dd163431
3
+ size 296793297
data/train-00004-of-00008.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2897571c595ec1e692695c0d1d02eb8278511feab4ac441734c30b6db4ad352a
3
+ size 292144475
data/train-00005-of-00008.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f4d2eca36097533f47e5c2bd4a67e2a0855017297770540796be62299bbb02cd
3
+ size 295038324
data/train-00006-of-00008.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8d49ffd53c5a97b157f7076756b45fed21fd0897ea04310e1a0343c636f6e101
3
+ size 294599041
data/train-00007-of-00008.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:64e2e1422e535456e7e22ec8d71d2f9a3918f5fb68e7fe6e910eca7cc1bf3012
3
+ size 291208336
meta.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model": "Efficient-Large-Model/Sana_600M_512px_diffusers",
3
+ "sampler": "SanaPipeline default (DPMSolverMultistep, flow)",
4
+ "steps": 20,
5
+ "guidance_scale": 4.5,
6
+ "resolution": 512,
7
+ "samples_per_prompt": 5,
8
+ "complex_human_instruction": true,
9
+ "max_sequence_length": 128,
10
+ "latent_shape": [
11
+ 5,
12
+ 32,
13
+ 16,
14
+ 16
15
+ ],
16
+ "latent_dtype": "float16",
17
+ "latent_space": "model (x0 fed to the transformer)",
18
+ "vae_scaling_factor": 0.41407,
19
+ "prompt_embeds_shape": [
20
+ 128,
21
+ 2304
22
+ ],
23
+ "prompt_embeds_dtype": "float16",
24
+ "prompt_attention_mask_dtype": "uint8",
25
+ "rewards": {
26
+ "ocr": "1 - (character edits to find the target text in the Qwen/Qwen3-VL-2B-Instruct transcription) / len(target)",
27
+ "pickscore": "yuvalkirstain/PickScore_v1, logit_scale * cos(image, prompt) (~ 15..25)",
28
+ "aesthetic": "LAION aesthetic predictor v2 (trl-lib/ddpo-aesthetic-predictor) on CLIP ViT-L/14 (~ 1..10)",
29
+ "clip": "100 * cos(image, prompt), openai/clip-vit-large-patch14"
30
+ },
31
+ "n_train": 2048,
32
+ "n_eval": 64,
33
+ "diffusers": "0.41.0",
34
+ "torch": "2.9.0+cu128"
35
+ }
null_prompt_embeds.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:45f3dbe291156ed5c85a19dd8518b43665c54e2f0b64a5ed133ab2440251f7fb
3
+ size 590136