Text-to-Image
Diffusers
Safetensors
Swedish
moss-image
handwriting
historical-documents
archives
htr
synthetic-data
Instructions to use Gabriel/diffu-moss-r6b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use Gabriel/diffu-moss-r6b with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("Gabriel/diffu-moss-r6b", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Draw Things
- DiffusionBee
diffu-moss-r6b: full fine-tune of MOSS-Image-Base's DiT, step 750 of r6b
Browse files- README.md +98 -0
- config.json +12 -0
- diffusion_pytorch_model.safetensors +3 -0
- export.json +6 -0
README.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model: OpenMOSS-Team/MOSS-Image-Base
|
| 4 |
+
base_model_relation: finetune
|
| 5 |
+
pipeline_tag: text-to-image
|
| 6 |
+
language:
|
| 7 |
+
- sv
|
| 8 |
+
tags:
|
| 9 |
+
- moss-image
|
| 10 |
+
- handwriting
|
| 11 |
+
- historical-documents
|
| 12 |
+
- archives
|
| 13 |
+
- htr
|
| 14 |
+
- synthetic-data
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# diffu-moss-r6b
|
| 18 |
+
|
| 19 |
+
A full fine-tune of the DiT of [MOSS-Image-Base](https://huggingface.co/OpenMOSS-Team/MOSS-Image-Base) that draws
|
| 20 |
+
whole synthetic archive pages: Swedish handwritten records of the 17th to 19th centuries. It is the drawing model of
|
| 21 |
+
[diffu](https://github.com/Borg93/diffu2), which makes training pages for page-level handwriting recognition: a page
|
| 22 |
+
layout (from a PAGE/ALTO file), the text to write in it and a sample page go in; a page image and its exact ALTO and
|
| 23 |
+
PAGE labels come out.
|
| 24 |
+
|
| 25 |
+
The model reads a MOSS Layout prompt, one text item per line with its exact text and its box, and a sample page given
|
| 26 |
+
as extra image tokens, whose paper, ink and look it follows. Only the DiT is in this repository. The text encoder,
|
| 27 |
+
tokenizer, VAE and scheduler are MOSS-Image-Base's, unchanged.
|
| 28 |
+
|
| 29 |
+
## Files
|
| 30 |
+
|
| 31 |
+
| File | What |
|
| 32 |
+
|---|---|
|
| 33 |
+
| `diffusion_pytorch_model.safetensors` | the DiT's weights, bfloat16 (10.2 GB, 462 tensors, the same names and shapes as Base's DiT) |
|
| 34 |
+
| `config.json` | `diffu_moss.transformer.MossTransformer` (diffu's own implementation of MOSS-Image's DiT) |
|
| 35 |
+
| `export.json` | `takes_reference: true`: the model takes a sample page |
|
| 36 |
+
|
| 37 |
+
## Use
|
| 38 |
+
|
| 39 |
+
With diffu (see its `docs/INFERENCE.md` for running on a Ray or KubeRay cluster):
|
| 40 |
+
|
| 41 |
+
```bash
|
| 42 |
+
hf download OpenMOSS-Team/MOSS-Image-Base --revision 85975793d8b3d432f1b6e27f352abaa4c2a4c0d3 --local-dir base
|
| 43 |
+
hf download Gabriel/diffu-moss-r6b --local-dir dit
|
| 44 |
+
git clone https://github.com/Borg93/diffu2 && cd diffu2 && uv sync --all-packages
|
| 45 |
+
uv run diffu-moss-init --base ../base --transformer ../dit --out ../moss-r6b
|
| 46 |
+
uv run diffu-run --jobs run.jsonl --draw-settings draw.json --model ../moss-r6b --out out --gpus 1
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
`run.jsonl` holds one page job per line (template, text, style, sample page, id); `docs/INFERENCE.md` section 5
|
| 50 |
+
describes it with worked examples.
|
| 51 |
+
|
| 52 |
+
On Blackwell GPUs the DiT can run in MXFP8, quantized from these weights as the model loads: give the draw settings
|
| 53 |
+
`{"precision": "mxfp8", "compile_blocks": true}`. On a GB10 at 1024 x 1024 this draws at 1.38 s a step, against
|
| 54 |
+
1.76 s for bfloat16 compiled and 3.46 s uncompiled; its pages look like bfloat16's, slightly less saturated.
|
| 55 |
+
|
| 56 |
+
For SGLang Diffusion, `diffu-moss-export-hf` writes this DiT in the official MOSS-Image layout, and diffu's plugin
|
| 57 |
+
`diffu_sglang_moss` adds the sample page (`docs/INFERENCE.md` section 13).
|
| 58 |
+
|
| 59 |
+
Recommended drawing: about 1 MP, 50 steps, guidance 3, shift 5, block 22 skipped in the unconditional pass (MOSS-Image's
|
| 60 |
+
own recipe).
|
| 61 |
+
|
| 62 |
+
## Training
|
| 63 |
+
|
| 64 |
+
- Data: 3,406 page pairs balanced across eight collections of Swedish archival handwriting ground truth (court,
|
| 65 |
+
chancery, mining and travel records): 2,031 whole pages and 1,375 windows of pages, about 1 MP each, each paired with
|
| 66 |
+
a sample page from the same volume.
|
| 67 |
+
- Prompt forms: no sample, the volume named (20 %); the sample with the look in words (20 %); the sample with the
|
| 68 |
+
volume named (20 %); the sample alone (40 %). In the last 1,000 steps half of the sample-alone pairs were restyled the
|
| 69 |
+
same way on page and sample (microfilm grey, colourised, tinted), so the look has to come from the sample.
|
| 70 |
+
- Recipe: MOSS-Image's own full fine-tune: Muon on the joint blocks' matrices and AdamW elsewhere, learning rate 5e-5,
|
| 71 |
+
weight decay 0.01, gradients clipped at 1, one pair a step, float32 weights under bfloat16 autocast; text encoder and
|
| 72 |
+
VAE frozen.
|
| 73 |
+
- Steps: 1,500 from Base on the sample form, then 1,000 with the restyled pairs (2,500 in all), on one DGX Spark.
|
| 74 |
+
|
| 75 |
+
## Evaluation
|
| 76 |
+
|
| 77 |
+
On held-out pages of the training volumes, each drawn with its own sample and with samples of other volumes, from the
|
| 78 |
+
same noise:
|
| 79 |
+
|
| 80 |
+
| Check | Result |
|
| 81 |
+
|---|---|
|
| 82 |
+
| The page's own sample gives a page of the right kind (colour or grey) | 4 of 5 |
|
| 83 |
+
| A grey sample makes a colour page grey | 3 of 5 |
|
| 84 |
+
| Colour and grey changes together | 78 % |
|
| 85 |
+
| The sample's handwriting is followed instead of the volume's | 1 of 12 |
|
| 86 |
+
|
| 87 |
+
## Limitations
|
| 88 |
+
|
| 89 |
+
- The handwriting does not follow the sample page. Trained on eight volumes, the model recognises a volume from its
|
| 90 |
+
text and layout and writes that volume's hand. Training on many more volumes is being tested.
|
| 91 |
+
- The look follows the sample only in part (above).
|
| 92 |
+
- Every line has to be checked: diffu reads each drawn line back and marks a line it cannot confirm as unclear in the
|
| 93 |
+
labels.
|
| 94 |
+
- Only eight volumes' hands and layouts were trained; other kinds of pages are untested.
|
| 95 |
+
|
| 96 |
+
## Licence
|
| 97 |
+
|
| 98 |
+
Apache-2.0, as MOSS-Image-Base.
|
config.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_class_name": "MossTransformer",
|
| 3 |
+
"_diffusers_version": "0.42.0.dev0",
|
| 4 |
+
"dim": 3072,
|
| 5 |
+
"ffn_dim": 8192,
|
| 6 |
+
"freq_dim": 256,
|
| 7 |
+
"latent_channels": 128,
|
| 8 |
+
"num_heads": 24,
|
| 9 |
+
"num_layers": 42,
|
| 10 |
+
"rope_base": 10000.0,
|
| 11 |
+
"text_dim": 4096
|
| 12 |
+
}
|
diffusion_pytorch_model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2cc4c67a4fbce820dd5743a8fbc345e63ef2d5c574e29dc73c3f6550963c2894
|
| 3 |
+
size 10164664128
|
export.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"takes_reference": true,
|
| 3 |
+
"base": "OpenMOSS-Team/MOSS-Image-Base@85975793d8b3d432f1b6e27f352abaa4c2a4c0d3 (full fine-tunes r5 1500 steps, r6 250, r6b 750)",
|
| 4 |
+
"checkpoint": "full_r6b/step_000750",
|
| 5 |
+
"adapter": null
|
| 6 |
+
}
|