Text-to-Image
Diffusers
Safetensors
Swedish
moss-image
handwriting
historical-documents
archives
htr
synthetic-data
Instructions to use Gabriel/diffu-moss-above with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use Gabriel/diffu-moss-above 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-above", 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
The sample-above full fine-tune at 2 MP, step 10,257 (EMA), with its model card
Browse files- README.md +119 -0
- config.json +13 -0
- diffusion_pytorch_model.safetensors +3 -0
- export.json +7 -0
README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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-above
|
| 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 16th to 19th centuries, **in the look and pen of a
|
| 21 |
+
sample page**. It is a drawing model of [diffu](https://github.com/Borg93/diffu2), which makes training pages for
|
| 22 |
+
page-level handwriting recognition: a page layout (a PAGE/ALTO file, or the lines' boxes as JSON), the text to write in
|
| 23 |
+
it and a sample page go in; a page image and its exact ALTO and 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. Only the DiT is in this repository. The text encoder, tokenizer, VAE and scheduler are
|
| 27 |
+
MOSS-Image-Base's, unchanged.
|
| 28 |
+
|
| 29 |
+
**How it differs from [diffu-moss-r6b](https://huggingface.co/Gabriel/diffu-moss-r6b):**
|
| 30 |
+
|
| 31 |
+
- **The sample page lies above the drawn page.** MOSS-Image lays a reference image over the drawn one, each of its
|
| 32 |
+
tokens at the position of the drawn token under it. This model was trained with the sample's tokens placed just
|
| 33 |
+
above the drawn page instead, where the lines before the page's first would lie (`reference_place: above` in
|
| 34 |
+
`config.json`). diffu's `MossTransformer` reads that setting and places the sample accordingly. **Code that places
|
| 35 |
+
the sample over the page (MOSS-Image's own pipeline, r6b's settings, the SGLang plugin) gives this model inputs it
|
| 36 |
+
was never trained on: use diffu at commit `b8e07de` or later.**
|
| 37 |
+
- **It was trained to take the hand from the sample.** Each window of a page was paired with the other window of the
|
| 38 |
+
same page as its sample (the same scribe on the same sheet, for certain), so the pen can only come from the sample.
|
| 39 |
+
r6b's samples came from other pages of the volume, and its hand did not follow the sample.
|
| 40 |
+
- **2 MP** pages (r6b: about 1 MP), three passes over the data with the learning rate wound down at the end.
|
| 41 |
+
|
| 42 |
+
## Files
|
| 43 |
+
|
| 44 |
+
| File | What |
|
| 45 |
+
|---|---|
|
| 46 |
+
| `diffusion_pytorch_model.safetensors` | the DiT's weights, bfloat16 (10.2 GB, the same names and shapes as Base's DiT): the exponential moving average (decay 0.999) at the last step, 10,257 |
|
| 47 |
+
| `config.json` | `diffu_moss.transformer.MossTransformer` (diffu's own implementation of MOSS-Image's DiT), with `reference_place: above` |
|
| 48 |
+
| `export.json` | `takes_reference: true`, `sample_size: legible`: the model takes a sample page, sized at the drawn page's writing scale |
|
| 49 |
+
|
| 50 |
+
## Use
|
| 51 |
+
|
| 52 |
+
With diffu:
|
| 53 |
+
|
| 54 |
+
```bash
|
| 55 |
+
hf download OpenMOSS-Team/MOSS-Image-Base --revision 85975793d8b3d432f1b6e27f352abaa4c2a4c0d3 --local-dir base
|
| 56 |
+
hf download Gabriel/diffu-moss-above --local-dir dit
|
| 57 |
+
git clone https://github.com/Borg93/diffu2 && cd diffu2 && uv sync --all-packages
|
| 58 |
+
uv run diffu-moss-init --base ../base --transformer ../dit --out ../moss-diffu
|
| 59 |
+
uv run diffu-generate --model ../moss-diffu --templates templates/0105.xml --text-from text.txt \
|
| 60 |
+
--reference samples/court-sample.jpg --reference-caption sample --whole-page --page-megapixels 2 --out pages
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
The sample page is an ordinary scan (JPEG or PNG) of a page whose paper, ink and hand the drawn page should have.
|
| 64 |
+
Run files for many pages work as for r6b (see its card and diffu's `docs/INFERENCE.md`).
|
| 65 |
+
|
| 66 |
+
Drawn in the checks below: 2 MP, 50 steps, guidance 3, shift 5, block 22 skipped in the unconditional pass
|
| 67 |
+
(MOSS-Image's own recipe), no reference guidance. Reference guidance (a third pass toward the sample), which r6b
|
| 68 |
+
recommends, has not been measured with this model yet.
|
| 69 |
+
|
| 70 |
+
## Training
|
| 71 |
+
|
| 72 |
+
- Data: diffu's Swedish archival handwriting ground truth at 2 MP, held-out volumes excluded: 54,700 training pairs,
|
| 73 |
+
windows of whole lines each with the other window of its own page as its sample, and whole pages in their own
|
| 74 |
+
prompt forms. Court, chancery, church, police, mining, military and travel records, 16th to 19th century.
|
| 75 |
+
- Recipe: MOSS-Image's own full fine-tune from Base at revision `85975793`: Muon on the joint blocks' matrices and
|
| 76 |
+
AdamW elsewhere, learning rate 5e-5 after warmup, wound down linearly to 0 over the last 1,709 steps, gradients
|
| 77 |
+
clipped at 1, float32 weights under bfloat16 autocast, an exponential moving average of the weights at 0.999; text
|
| 78 |
+
encoder and VAE frozen. Samples grouped by size into rounds (size blocks of 32).
|
| 79 |
+
- Scale: 16 samples a step over 8 A100 64 GB (two nodes of the Leonardo supercomputer, CINECA; FSDP2), 10,257 steps:
|
| 80 |
+
164,112 samples, three passes, each pair seen three times. Trained 13-17 Nov 2026 as a chain of 30-minute jobs,
|
| 81 |
+
each resuming from the last checkpoint with its optimizer state and data order (every step trained exactly once).
|
| 82 |
+
- Training loss (mean over 1,000 steps): 0.616 (steps 1-1,000), 0.601 (3,001-4,000), 0.598 (6,001-7,000), 0.590 (the
|
| 83 |
+
last 257).
|
| 84 |
+
|
| 85 |
+
## Evaluation
|
| 86 |
+
|
| 87 |
+
Judged by eye beside the real scans, on held-out pages from volumes the model never saw in training.
|
| 88 |
+
|
| 89 |
+
**Over training**, six held-out pages each drawn with a sample from its own page, the same noise at every checkpoint:
|
| 90 |
+
at step 1,000 the model writes its own heavy, near-printed hand whatever the sample; from step 2,000 it writes in the
|
| 91 |
+
sample's pen (stroke weight, slant, ink colour); steps 3,000 to 10,257 differ only in detail. Layout, line breaks and
|
| 92 |
+
paper follow the page at every step.
|
| 93 |
+
|
| 94 |
+
**The swap test** (final weights): each of the six pages drawn again with the samples of two pages from other volumes
|
| 95 |
+
(other scribes), the same noise as with its own sample:
|
| 96 |
+
|
| 97 |
+
| Check | Pages of 12 |
|
| 98 |
+
|---|---|
|
| 99 |
+
| The page takes the sample's look (paper and ink colour, grey or colour scan) | nearly all |
|
| 100 |
+
| The page takes the sample's pen (stroke weight, slant, how regular the writing is) | about 8 |
|
| 101 |
+
| The page takes the sample's letter forms as well | about 3 |
|
| 102 |
+
|
| 103 |
+
Letter size and line spacing stay with the layout, as they should: the line boxes set them.
|
| 104 |
+
|
| 105 |
+
## Limitations
|
| 106 |
+
|
| 107 |
+
- **The hand follows the sample's pen more than its letter forms.** In most pages the drawn hand moves toward the
|
| 108 |
+
sample's but keeps much of a generic hand for the period.
|
| 109 |
+
- **The placement is fixed:** the sample has to be placed above the page (see above). Older diffu code and other
|
| 110 |
+
MOSS-Image pipelines place it over the page.
|
| 111 |
+
- Drawing new layouts (letters, forms, tables, registers) with samples from unseen volumes is being tested; the
|
| 112 |
+
results above are on held-out pages with their own layouts.
|
| 113 |
+
- Every line has to be checked: diffu reads each drawn line back and marks a line it cannot confirm as unclear in the
|
| 114 |
+
labels.
|
| 115 |
+
- Trained on Swedish archival handwriting; printed forms and other kinds of pages are untested.
|
| 116 |
+
|
| 117 |
+
## Licence
|
| 118 |
+
|
| 119 |
+
Apache-2.0, as MOSS-Image-Base.
|
config.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
"reference_place": "above",
|
| 11 |
+
"rope_base": 10000.0,
|
| 12 |
+
"text_dim": 4096
|
| 13 |
+
}
|
diffusion_pytorch_model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0076a15ca5440c94cd1820d2fe859f9761f4f3f5f7bb0497ad9ffd8164e424c0
|
| 3 |
+
size 10164664128
|
export.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"takes_reference": true,
|
| 3 |
+
"base": "OpenMOSS-Team/MOSS-Image-Base@85975793d8b3d432f1b6e27f352abaa4c2a4c0d3 (full fine-tune, sample above the page: 10,257 steps of 16 samples at 2 MP)",
|
| 4 |
+
"checkpoint": "full_above2mp/step_010257 (EMA, decay 0.999)",
|
| 5 |
+
"adapter": null,
|
| 6 |
+
"sample_size": "legible"
|
| 7 |
+
}
|