malcolmrey commited on
Commit
8964ec1
·
1 Parent(s): 181d002

moss docs

Browse files
moss/README.md ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # MOSS-Image LoRA Training Hub (`moss/`)
2
+
3
+ Training notes and templates for character LoRAs on **MOSS-Image Base** (OpenMOSS, 5B), trained
4
+ with [maltrainer](https://github.com/malcolmamal/maltrainer) on ComfyUI's single-file checkpoints.
5
+
6
+ ---
7
+
8
+ ## 🧭 Directory Map
9
+
10
+ | Path | Description |
11
+ | :--- | :--- |
12
+ | 📘 **[Combined Optimizer Training Guide](docs/MOSS_IMAGE_COMBINED_OPTIMIZER_TRAINING_GUIDE.md)** | The method: train the dataset with AdamW 8-bit, Automagic3 and Prodigy at shorter-than-usual lengths, merge the three LoRAs at 0.7 each, and resize the merge to rank 8. Why it works, how to run it, and what's still open. |
13
+ | 📗 **[MOSS-Image Training Guide](docs/moss-image-lora-training.md)** | maltrainer's guide to MOSS-Image LoRA training: model files, how it matches ComfyUI, the timestep distribution, the templates and the first real run. |
14
+ | 🔬 **[Stacking Findings](docs/moss-image-lora-stacking-findings.md)** | The finding that started the combined method: two under-strength LoRAs, stacked at 1.0 each, gave the best results so far. |
15
+ | 🛠️ **[`templates/`](templates/)** | The three member templates: [`adamw8bit`](templates/moss_image_template-adamw8bit.yaml) (60 epochs), [`automagic3`](templates/moss_image_template-automagic3.yaml) (20 epochs), [`prodigy`](templates/moss_image_template-prodigy.yaml) (30 epochs). |
16
+
17
+ ---
18
+
19
+ ## ⚡ The Method in Four Lines
20
+
21
+ 1. **Train three times**, once per optimizer, each run kept short.
22
+ 2. **Merge** the three LoRAs exactly, at strength 0.7 each (`merge_loras.py`).
23
+ 3. **Resize** the rank-48 merge to rank 8 (`resize_lora.py`).
24
+ 4. **Load** the result at strength 1.0.
25
+
26
+ It grew out of a finding on MOSS-Image: two separately trained, under-strength LoRAs stacked at
27
+ 1.0 each looked better than either one turned up. The subject adds up across runs, while each
28
+ run's own errors partly cancel.
29
+
30
+ ## 📦 Model Files (`Comfy-Org/MOSS-Image`)
31
+
32
+ | Role | File |
33
+ | :--- | :--- |
34
+ | DiT (train on the **Base** model) | `diffusion_models/moss_image_base_bf16.safetensors` |
35
+ | VAE | `vae/flux2_vae.safetensors` |
36
+ | Text encoder (caching only) | `text_encoders/qwen3.5_9b_int8_convrot.safetensors` |
moss/docs/MOSS_IMAGE_COMBINED_OPTIMIZER_TRAINING_GUIDE.md ADDED
@@ -0,0 +1,234 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # MOSS-Image LoRAs: Combined Training With Three Optimizers
2
+
3
+ [← Back to the MOSS hub](../README.md)
4
+
5
+ This is how I now train character LoRAs for **MOSS-Image Base** (OpenMOSS, 5B). I train the same
6
+ dataset three times, once each with **AdamW 8-bit**, **Automagic3** and **Prodigy**. Each run is
7
+ kept shorter than a normal one. I then merge the three LoRAs into one file (a "LoRA soup") and
8
+ shrink that file to rank 8.
9
+
10
+ All training runs on [maltrainer](https://github.com/malcolmamal/maltrainer), my own LoRA trainer,
11
+ against ComfyUI's single-file MOSS-Image checkpoints.
12
+
13
+ ---
14
+
15
+ ## In short
16
+
17
+ | Step | What happens | Tool |
18
+ | :--- | :--- | :--- |
19
+ | 1. Train | The dataset is trained once per optimizer, one after another: AdamW 8-bit (60 epochs), Automagic3 (20 epochs), Prodigy (30 epochs) | `train_moss_image_lora.py`, driven by `scripts/train_combined.py` |
20
+ | 2. Merge | The three LoRAs are merged exactly, at **0.7 strength each**, into one rank-48 LoRA | `scripts/merge_loras.py` |
21
+ | 3. Resize | The merge is shrunk to **rank 8** with a per-layer SVD | `scripts/resize_lora.py` |
22
+ | 4. Use | Load the resized file in ComfyUI at **strength 1.0** | ComfyUI's stock LoRA loader |
23
+
24
+ The three member templates are in [`../templates/`](../templates/).
25
+
26
+ ---
27
+
28
+ ## Where it came from
29
+
30
+ The first MOSS-Image LoRAs (Felicia Day, 23 images, 512 px) were trained the usual way: one
31
+ optimizer and a long run. The results:
32
+
33
+ - **Automagic3, 100 epochs (2,300 steps).** The LoRA worked but needed strength 1.4–1.5 to look
34
+ right. Its adaptive learning rate peaked around step 200 and then decayed for the rest of the
35
+ run. Likeness at step 500 already matched step 2,300, so the remaining steps added little.
36
+ - **Prodigy.** Also under-strength. It was better at 1.5, but still not right.
37
+
38
+ Then the Automagic3 step-500 checkpoint and the Prodigy step-750 checkpoint were loaded
39
+ **together, both at strength 1.0**. That gave the best results so far, better than either LoRA
40
+ turned up on its own.
41
+
42
+ The combined run makes that accident into the recipe:
43
+ - Every optimizer stops around the point where it stopped adding likeness.
44
+ - A third optimizer (AdamW 8-bit) joins as another independent opinion.
45
+ - The merge and the resize are done for you, so you end up with one small file instead of a
46
+ stack of LoRAs.
47
+
48
+ ---
49
+
50
+ ## Why it works
51
+
52
+ ### Stacking adds the subject and cancels the noise
53
+
54
+ Loading several LoRAs adds their weight changes together. Each run's change has two parts:
55
+
56
+ - **The subject:** the face and identity all three runs set out to learn. The runs learn it
57
+ independently, but it points the same way in each of them, so it **adds up**.
58
+ - **Each run's own errors:** a pose or lighting it latched onto from one photo, drift from its
59
+ particular noise draws, the habits of its optimizer. These differ from run to run and point in
60
+ different directions, so they **partly cancel**.
61
+
62
+ The soup therefore gets roughly three times the subject with less than three times the errors.
63
+ Turning a single LoRA up to 1.5 is different: it scales the subject and its errors together.
64
+
65
+ Averaging separately trained models like this is known as a **model soup**. It works best when
66
+ the members are good but different. Three optimizers are a strong form of "different": they move
67
+ through the weights in genuinely different ways.
68
+
69
+ | Optimizer | How it moves | Its usual failure |
70
+ | :--- | :--- | :--- |
71
+ | **AdamW 8-bit** | A flat learning rate (1e-4) for the whole run | Can overshoot and memorize when run too long |
72
+ | **Automagic3** | Adapts its own rate per module family (attention / MLP / other); the rate decays as the run settles | Can stall and stop short of full strength |
73
+ | **Prodigy** | Estimates its own step size and grows it | Can overcook late in long runs |
74
+
75
+ Each member's weakness pulls the soup in a different direction, so no single one dominates it.
76
+
77
+ ### Why fewer epochs per member
78
+
79
+ A member doesn't have to be a finished LoRA. It needs to have learned the subject, and it should
80
+ stop before it learns too much of its own quirks. Two things make a short run enough:
81
+
82
+ - **Strength comes from the stack.** Three members at 0.7 each give a total weight of 2.1 on the
83
+ subject. A member that would be slightly under-strength on its own is the right size for a soup.
84
+ - **Long runs add mostly noise.** On MOSS-Image the likeness was already there by step 500
85
+ (about 22 epochs of 23 images). Later steps mostly add memorization, the "errors" that the soup
86
+ then has to cancel.
87
+
88
+ The epoch counts differ per optimizer because they learn at different speeds:
89
+
90
+ | Member | Epochs | Steps at 23 images | Rationale |
91
+ | :--- | :---: | :---: | :--- |
92
+ | Automagic3 | 20 | 460 | Its rate peaks early and decays; its likeness was in place by ~step 500 |
93
+ | Prodigy | 30 | 690 | Its step size has to grow from a tiny start (d0 1e-6) after a 100-step warmup; the stacked checkpoint was step 750 |
94
+ | AdamW 8-bit | 60 | 1,380 | A flat rate with no estimate to grow, so it needs the most steps; still well short of a long single run |
95
+
96
+ At about 0.6 s per step on an RTX 5090 (512 px, bf16 base), that is roughly 25 minutes of
97
+ training for all three, plus model loading for each member. The earlier single 100-epoch
98
+ Automagic3 run took 23 minutes.
99
+
100
+ ### Why resize the merge to rank 8
101
+
102
+ The merge is exact: three rank-16 LoRAs become one **rank-48** LoRA that applies exactly what
103
+ stacking them at 0.7 each would. Resizing then shrinks it:
104
+
105
+ - For every layer, the SVD finds the few directions that carry almost all of that layer's change
106
+ and drops the rest. It keeps as many singular values as hold 99.9 % of the layer's norm, and
107
+ at most 8.
108
+ - The subject is the part all three members agree on, so it lives in the strong directions and
109
+ survives the resize. Small, scattered components (much of the members' disagreement) are what
110
+ gets dropped.
111
+ - The file ends up a sixth of the merge's size: one small LoRA to keep, share and load.
112
+
113
+ Load the resized file at **strength 1.0**. The member strengths are already baked in.
114
+
115
+ ---
116
+
117
+ ## The templates
118
+
119
+ [`../templates/`](../templates/) holds the three member templates, exactly as my training
120
+ front-end (Stabilis) fills them. All three share everything that isn't the optimizer, so the
121
+ members differ only where it matters:
122
+
123
+ | Shared setting | Value |
124
+ | :--- | :--- |
125
+ | Base model | `moss_image_base_bf16.safetensors` (the **Base** model, not the SFT fine-tune) |
126
+ | VAE / text encoder | `flux2_vae.safetensors` / `qwen3.5_9b_int8_convrot.safetensors` (used for caching only, then unloaded) |
127
+ | LoRA | rank 16, alpha 16, `blocks`: attention + feed-forward of the 42 joint blocks (252 modules) |
128
+ | Resolution | 512 px area, aspect-ratio buckets on a 16 px grid, batch 1 |
129
+ | Timesteps | MOSS-Image's last pretraining interval: logit(σ) ~ N(1.09, 0.95), truncated at 0.95, 1 % uniform, no shift |
130
+ | Caption dropout | 0.05: the reference sampler uses real CFG against the empty prompt |
131
+ | Gradient clip | 1.0 |
132
+
133
+ | | [`adamw8bit`](../templates/moss_image_template-adamw8bit.yaml) | [`automagic3`](../templates/moss_image_template-automagic3.yaml) | [`prodigy`](../templates/moss_image_template-prodigy.yaml) |
134
+ | :--- | :--- | :--- | :--- |
135
+ | Learning rate | 1e-4, constant | 1e-6 launch point, then adaptive per module family, 8-step sign window | 1.0 (multiplier on Prodigy's own estimate), 100-step warmup |
136
+ | Weight decay | 0.01 | 0 | 0.01, decoupled |
137
+ | EMA of the weights | 0.98 | 0.98 | off |
138
+ | Epochs | 60 | 20 | 30 |
139
+ | Output | `moss_image_<person>_v1_adamw` | `moss_image_<person>_v1_automagic3` | `moss_image_<person>_v1_prodigy` |
140
+
141
+ ### Placeholders
142
+
143
+ The templates contain placeholders that get filled before a run:
144
+
145
+ | Placeholder | Fill with |
146
+ | :--- | :--- |
147
+ | `[dataset_location]` / `[person_to_train]` | The folder that holds the dataset, and the dataset's folder name (also the default trigger word) |
148
+ | `[comfyui_diffusion_models]` | ComfyUI's `models/diffusion_models` folder (the templates expect the file under `MOSS/`) |
149
+ | `[comfyui_vae]` / `[comfyui_text_encoders]` | ComfyUI's `models/vae` and `models/text_encoders` folders |
150
+
151
+ Captions come from a `.txt` file next to each image. An image without one is captioned
152
+ `a photo of <person>`.
153
+
154
+ ---
155
+
156
+ ## Running it with maltrainer
157
+
158
+ **1. Fill the three templates** for your dataset, for example as
159
+ `config/moss_feliciaday_adamw8bit.yaml`, `..._automagic3.yaml` and `..._prodigy.yaml`.
160
+
161
+ **2. Write the combined config** that lists them with their merge strengths:
162
+
163
+ ```yaml
164
+ trainer: train_moss_image_lora.py
165
+ members:
166
+ - config: config/moss_feliciaday_adamw8bit.yaml
167
+ strength: 0.7
168
+ - config: config/moss_feliciaday_automagic3.yaml
169
+ strength: 0.7
170
+ - config: config/moss_feliciaday_prodigy.yaml
171
+ strength: 0.7
172
+ output:
173
+ path: ./output/moss_image_feliciaday_combined
174
+ name: moss_image_feliciaday_v1_soup
175
+ dtype: float32 # keeps the merge exact
176
+ ```
177
+
178
+ **3. Train and merge** in one go:
179
+
180
+ ```bash
181
+ python scripts/train_combined.py --config config/moss_feliciaday_combined.yaml
182
+ ```
183
+
184
+ The members train one after another. If one fails, the run stops and nothing is merged; the
185
+ LoRAs already trained stay where their configs put them. The merge's path is printed last, on a
186
+ line starting `Merged LoRA:`.
187
+
188
+ **4. Resize** the merge to rank 8:
189
+
190
+ ```bash
191
+ python scripts/resize_lora.py output/moss_image_feliciaday_combined/moss_image_feliciaday_v1_soup.safetensors --rank 8
192
+ ```
193
+
194
+ That writes `moss_image_feliciaday_v1_soup_resized.safetensors`. Load it in ComfyUI at strength
195
+ 1.0.
196
+
197
+ ---
198
+
199
+ ## Strengths
200
+
201
+ | Members | Default strength each | Total |
202
+ | :---: | :---: | :---: |
203
+ | 3 | 0.7 | 2.1 |
204
+ | 2 | 0.95 | 1.9 |
205
+
206
+ These defaults assume each member is close to full strength on its own.
207
+ - If the soup looks overcooked (waxy skin, stiff faces, ignored prompts), lower all strengths a
208
+ little.
209
+ - If it looks weak, raise them.
210
+
211
+ Merge and resize again after any change; nothing has to be retrained. Two members also make a
212
+ valid soup, so a failed or poor member can be left out.
213
+
214
+ ---
215
+
216
+ ## What's known and what isn't
217
+
218
+ **Measured:**
219
+ - Two under-strength MOSS-Image LoRAs (Automagic3 step 500 and Prodigy step 750), stacked at 1.0
220
+ each, beat either one turned up on its own.
221
+ - Both long single-optimizer runs ended under-strength at 1.0.
222
+ - Automagic3's likeness stopped improving after about 500 steps.
223
+
224
+ **Still open:**
225
+ - **Different optimizers or different seeds?** Would three runs of one optimizer with different
226
+ seeds do as well as three optimizers?
227
+ - **Best strengths.** Are equal strengths best, or should one optimizer weigh more?
228
+ - **The timesteps.** MOSS-Image's pretraining timestep distribution centres on σ ≈ 0.74, and only
229
+ about 2 % of steps fall below σ 0.3, where fine identity detail is learned. If single LoRAs keep
230
+ coming out weak, centring the distribution lower (`timestep_logit_mean: 0`) is the next lever
231
+ to test.
232
+
233
+ The full background is in maltrainer's [MOSS-Image training guide](moss-image-lora-training.md)
234
+ and its notes on [stacking MOSS-Image LoRAs](moss-image-lora-stacking-findings.md).
moss/docs/moss-image-lora-stacking-findings.md ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # MOSS-Image: two weak LoRAs that stack into a strong one
2
+
3
+ Findings from the first feliciaday LoRA runs on MOSS-Image Base, October 2026.
4
+
5
+ **In short:** two separately trained LoRAs were each under-strength on their own. One came from
6
+ Automagic3, one from Prodigy. Loaded together, both at strength 1.0, the results were the best so far. The likely
7
+ reasons, and what to do about them, follow.
8
+
9
+ ## The runs
10
+
11
+ Both runs used the same setup:
12
+
13
+ - 23 images, 512×512
14
+ - the bf16 DiT and the int8 Qwen3.5-9B text encoder
15
+ - LoRA rank 16, alpha 16, `blocks` targets (252 adapters)
16
+ - the report's timestep distribution: logit-normal, mean sigma ~0.74, no shift
17
+ - caption dropout 0.05
18
+
19
+ They differed only in the optimizer.
20
+
21
+ | | Automagic3 | Prodigy |
22
+ |---|---|---|
23
+ | Config | `train_moss_image_feliciaday_automagic3.yaml`, run for 2300 steps | `train_moss_image_feliciaday_prodigy.yaml` |
24
+ | Optimizer | Automagic3, 8-step sign window, launch 1e-6, EMA 0.98 | Prodigy, lr 1.0, 100 warmup steps, weight decay 0.01, no EMA |
25
+ | Checkpoint used | step 500 | step 750 |
26
+ | Alone at strength 1.0 | under-strength. It worked at 1.4-1.5 | under-strength. Better at 1.5, but not right |
27
+ | Stacked together, both at strength 1.0 | **very good: the best results so far** | |
28
+
29
+ Observations from the Automagic3 log:
30
+
31
+ - **Rate.** The adaptive rate peaked at 5.7e-5 around step 200 (MLP 8.4e-5, attention
32
+ 2.9e-5). It then decayed steadily to 1.1e-5 at step 2300 (attention 7e-6).
33
+ - **Likeness.** Likeness at step 500 already matched step 2300. After about 500 steps the run
34
+ added little.
35
+ - **Loss.** Mean loss went 0.578 → 0.546. With these timesteps the loss is dominated by
36
+ high-noise steps and says little about likeness.
37
+
38
+ ## Why stacking works better than one LoRA turned up
39
+
40
+ Loading two LoRAs adds their weight changes. Each change has two parts:
41
+
42
+ - **The subject**, the thing both runs set out to learn. The two runs learned it independently,
43
+ but it points the same way in both, so it adds up. Two half-strength LoRAs make one
44
+ full-strength subject.
45
+ - **Each run's own errors:** a pose or lighting it latched onto from one photo, drift from its
46
+ particular noise draws, the optimizer's path. These differ between the runs and point in
47
+ different directions, so they partly cancel instead of adding up.
48
+
49
+ So the stack gets roughly twice the subject with less than twice the errors. One LoRA turned up
50
+ to 1.5 scales its subject and its errors together. That fits what was seen: Prodigy at 1.5 was
51
+ "better but not exactly right", while the stack looked right.
52
+
53
+ Averaging or summing separately trained runs like this is known as a "model soup" (for LoRAs,
54
+ a "LoRA soup"). It works best when the runs are good but different. Two optimizers are a
55
+ strong form of "different".
56
+
57
+ ## What it says about training
58
+
59
+ Both optimizers came out under-strength at 1.0, so the optimizer is not the main bottleneck.
60
+ What the runs share is the more likely cause:
61
+
62
+ - **The timesteps.** The report's pretraining distribution centres on sigma ~0.74, and only
63
+ ~2 % of steps fall below sigma 0.3. Fine identity detail is mostly learned at mid and low
64
+ noise, so each run spends most of its steps where likeness is decided least.
65
+ - **The update size.** Automagic3's rate decayed to a fraction of its peak, and both runs
66
+ stopped well short of strength 1.0. More, larger steps in the right noise range should help.
67
+
68
+ ## What to do with it
69
+
70
+ 1. **Keep the result now.** Merge the pair into one file with `scripts/merge_loras.py` at
71
+ 1.0 each, the strengths of the stack (the default, so no `:strength` is needed). The merge
72
+ is exact: one rank-32 LoRA that gives exactly the stacked result at strength 1.0. See
73
+ maltrainer's `docs/merge-loras.md`.
74
+ 2. **Test the diagnosis.** Train one run with `timestep_logit_mean: 0` (centred on sigma 0.5)
75
+ and everything else unchanged. If that single LoRA is right at strength 1.0, the timesteps
76
+ were the bottleneck.
77
+ 3. **Use the soup on purpose.** Even once single runs reach full strength, merging two runs
78
+ should still give a cleaner LoRA than either alone. The runs can differ by optimizer or by
79
+ seed. At ~0.6 s/step, a 1000-step run takes ~10 minutes, so a second run is cheap. When
80
+ merging two full-strength LoRAs, start at about 0.5-0.7 each, not 1.0 + 1.0.
81
+
82
+ ## Open questions
83
+
84
+ - Was the stack better because of the two optimizers, or would two Prodigy runs with different
85
+ seeds do as well?
86
+ - Does the soup still help once single runs are at full strength, or does it mainly make up
87
+ for under-training?
88
+ - Which merge strengths work best? Equal strengths, or more weight on one optimizer's LoRA?
moss/docs/moss-image-lora-training.md ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # MOSS-Image LoRA training
2
+
3
+ `train_moss_image_lora.py` trains LoRAs for **MOSS-Image Base** (OpenMOSS, 5B) from ComfyUI's
4
+ single-file checkpoints. It caches each image's latent and each caption's embedding once,
5
+ unloads the encoders, then trains on the frozen DiT.
6
+
7
+ There are three ways to run it:
8
+
9
+ ```bash
10
+ python train_moss_image_lora.py --config config/train_moss_image_feliciaday_automagic3.yaml
11
+ ```
12
+
13
+ ```bash
14
+ run_moss_image_training.bat feliciaday # fills config/moss_image_automagic_template.yaml (Automagic3)
15
+ run_moss_image_training.bat feliciaday prodigy # fills config/moss_image_prodigy_template.yaml
16
+ run_moss_image_training.bat feliciaday adamw8bit # fills config/moss_image_adamw_template.yaml
17
+ ```
18
+
19
+ The third is the web UI: pick **MOSS-Image (Base)**, a dataset and an optimizer.
20
+
21
+ `run_moss_image_training.bat` wraps `scripts/train_from_template.py`. That script fills the
22
+ template's placeholders and writes the filled config into the output folder before it starts.
23
+ Pass `--max-steps`, `--epochs`, `--trigger` or `--dry-run` after the optimizer.
24
+
25
+ ## Model files
26
+
27
+ All files come from `Comfy-Org/MOSS-Image`. ComfyUI loads MOSS-Image natively from the
28
+ 2026-10 update onwards (`comfy/ldm/moss_image`).
29
+
30
+ | Key | File | Notes |
31
+ |---|---|---|
32
+ | `model.transformer_path` | `diffusion_models/moss_image_base_bf16.safetensors` | 10 GB. `moss_image_base_int8_convrot` also works. The `_sft_` files are OpenMOSS's fine-tune of the base; the trainer warns |
33
+ | `model.vae_path` | `vae/flux2_vae.safetensors` | The Flux2 VAE, the same file FLUX.3 uses (`flux2-vae.safetensors` in the repo) |
34
+ | `model.text_encoder_path` | `text_encoders/qwen3.5_9b_int8_convrot.safetensors` | Qwen3.5-9B. A plain bf16 file also works. The `w4a8_gptq` file is not supported |
35
+
36
+ The text encoder runs only while prompts are cached. Its Linears stay int8 on the GPU (~10 GB),
37
+ and it is unloaded before the DiT loads.
38
+
39
+ ## How it matches ComfyUI
40
+
41
+ Checked numerically against ComfyUI on CPU, with small random-weight models in ComfyUI's file
42
+ layouts:
43
+
44
+ | Part | Reference | Relative difference |
45
+ |---|---|---|
46
+ | DiT, fp32 (plain and fused-qkv files) | `comfy.sd.load_diffusion_model` → `apply_model` | ~7e-7 |
47
+ | DiT, bf16 | ComfyUI's own bf16 drift from fp32 is 6.6e-3; maltrainer's is the same | — |
48
+ | Saved LoRA, applied by `comfy.lora` (plain and fused-qkv files) | the training forward | ~1e-6 |
49
+ | Text encoder, fp32 / bf16 / int8 | ComfyUI's `MOSSImageTEModel` | 2e-7 / 2e-7 / 5e-7 |
50
+ | Text encoder, fp32 | transformers' `Qwen3_5TextModel` | 3.5e-7 |
51
+ | Token ids (template, empty prompt, newlines, CJK, emoji, special-token text) | ComfyUI's `MOSSImageTokenizer` | identical |
52
+
53
+ Conventions it follows:
54
+
55
+ - **DiT input.** The Flux2 VAE's 128-channel latent, one token per 16 px, joined with the text
56
+ as `[image | text]`. All 42 blocks take one shared modulation of the timestep, text tokens
57
+ included.
58
+ - **Timestep.** The DiT gets sigma in [0, 1]. Its sinusoidal embedding is of 1000 × sigma, with
59
+ phases in float64, as in the training code.
60
+ - **Target.** The flow velocity `v = noise − x0`, under a plain per-token MSE (report equation 3).
61
+ - **Text.** The prompt is stripped and wrapped in Qwen's chat template with thinking enabled:
62
+ `<|im_start|>user\n{prompt}<|im_end|>\n<|im_start|>assistant\n<think>\n`. The encoder output
63
+ is every token's final hidden state after the last norm, at the prompt's true length (no
64
+ padding, capped at 4096 tokens). The DiT's RoPE follows that length, so training runs at batch
65
+ size 1. Use `gradient_accumulation_steps` for larger batches.
66
+ - **Encoder precision.** As in ComfyUI, the encoder's activations run in fp32 while its weights
67
+ stay int8/bf16. An all-bf16 run drifts ~3× further from fp32.
68
+ - **Caption dropout** encodes the empty prompt. That is the negative prompt the reference
69
+ sampler's CFG uses (scale 3, 50 steps, shift 5).
70
+
71
+ ## Timesteps
72
+
73
+ The defaults reproduce the technical report's last pretraining interval (appendix A.2, Table 6):
74
+
75
+ - logit(sigma) ~ N(1.09, 0.95)
76
+ - truncated at sigma ≤ 0.95 and rescaled onto [0, 1]
77
+ - rounded up onto the 1000-step grid
78
+ - mixed with 1 % uniform
79
+ - no shift
80
+
81
+ The sampler's mean sigma is 0.745 against 0.744 for the report's equation 4. P(sigma > 0.9) is
82
+ 0.217 against 0.215.
83
+
84
+ This distribution favours high noise: only ~2 % of steps fall below sigma 0.3. If a likeness
85
+ LoRA learns composition but not fine detail, try `timestep_logit_mean: 0` (centred on sigma 0.5)
86
+ and compare checkpoints.
87
+
88
+ | Key | Default | Meaning |
89
+ |---|---|---|
90
+ | `train.timestep_distribution` | `logit_normal` | or `uniform` |
91
+ | `train.timestep_logit_mean` / `_std` | 1.09 / 0.95 | logit-normal on sigma; positive = noisier |
92
+ | `train.timestep_cutoff` | 0.95 | truncate at sigma ≤ cutoff, then divide by it; 1 = off |
93
+ | `train.timestep_uniform_mix` | 0.01 | share of uniform draws |
94
+ | `train.timestep_shift` | 1.0 | `s·σ / (1 + (s − 1)·σ)`; 1 = none |
95
+ | `train.timestep_grid` | 1000 | round sigma up onto {1/N … 1}; 0 = continuous |
96
+
97
+ ## Templates
98
+
99
+ All three templates use the same model files, LoRA (rank 16, alpha 16, `blocks`), timesteps
100
+ and 512 px buckets, so their runs compare directly.
101
+
102
+ - `config/moss_image_automagic_template.yaml`: **Automagic3**. Launch point 1e-6. Attention, MLP and
103
+ other layers each adapt their own rate, over an **8-step** sign window. On FLUX.3 a 16-step
104
+ window left the rate stuck near 3e-5 and the LoRA under-trained. EMA 0.98, 20 epochs.
105
+ - `config/moss_image_prodigy_template.yaml`: **Prodigy**, with FLUX.3's Prodigy settings.
106
+ lr 1.0 (a multiplier on Prodigy's own estimate d), 100 warmup steps, decoupled weight decay
107
+ 0.01, beta2 0.99, bias correction and safeguarded warmup, no EMA, 20 epochs.
108
+ - `config/moss_image_adamw_template.yaml`: **AdamW 8-bit** at a flat 1e-4 (Fizgig 8.1's rate
109
+ for FLUX.3 and Krea 2), weight decay 0.01, EMA 0.98, as in the Automagic3 template.
110
+
111
+ The feliciaday runs built from them are `config/train_moss_image_feliciaday_automagic3.yaml`,
112
+ `_prodigy.yaml` and `_adamw.yaml`.
113
+
114
+ LoRA target presets (`lora.targets`):
115
+
116
+ | Preset | Adapters | What |
117
+ |---|---|---|
118
+ | `blocks` | 252 | attention (`proj.q/k/v/o`) + feed-forward (`proj.ffn_up_gate/ffn_down`) of the 42 joint blocks |
119
+ | `attn` | 168 | attention only |
120
+ | `all` | 269 | `blocks` + the 2 text-embedder blocks + input, timestep, modulation and output Linears |
121
+
122
+ Saved keys are ComfyUI's module paths (`diffusion_model.layers.N.proj.q.lora_A.weight`).
123
+ ComfyUI loads them with its stock LoRA loader, including on the repacked files with a fused
124
+ `proj.qkv`.
125
+
126
+ ## First real run (feliciaday, Automagic3, 2026-10-17)
127
+
128
+ The run used 23 images at 512×512, 100 epochs (2300 steps), the Automagic3 template, the bf16 DiT
129
+ and the int8 text encoder.
130
+
131
+ - **Loading.** The real `moss_image_base_bf16` file stores **fused** `proj.qkv`. The LoRA still
132
+ saves separate q/k/v adapters, which ComfyUI slices in. The text encoder logged 32 layers
133
+ (8 full attention) and hidden 4096. Captions were 43-82 tokens.
134
+ - **Speed.** ~0.6 s/step, 23 minutes for the run.
135
+ - **Rate.** Automagic3's average rate peaked at 5.7e-5 by step 200 (MLP 8.4e-5, attention
136
+ 2.9e-5). It then decayed steadily to 1.1e-5 by the end (attention 7e-6).
137
+ - **Loss.** Mean loss went 0.578 → 0.546. It is dominated by the high-noise timesteps, so it
138
+ says little about likeness.
139
+ - **Result.** The LoRA works but needs strength 1.4-1.5, so it is under-trained. Likeness at
140
+ step 500 already matched step 2300, which fits the decaying rate.
141
+
142
+ Two levers are untested yet: a higher constant rate (the AdamW template) and lower-noise
143
+ timesteps (`timestep_logit_mean: 0`). Change one per run to see which one matters.
144
+
145
+ The Prodigy run was under-strength too. Stacked at 1.0 each, the Automagic3 step-500 and
146
+ Prodigy step-750 LoRAs gave the best results so far: see
147
+ [moss-image-lora-stacking-findings.md](moss-image-lora-stacking-findings.md). To keep such a
148
+ stack as one file, merge it with maltrainer's `scripts/merge_loras.py`.
moss/templates/moss_image_template-adamw8bit.yaml ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # MOSS-Image LoRA -- MalTrainer (train_moss_image_lora.py), AdamW 8-bit.
2
+ #
3
+ # The recipe of MalTrainer's own config/moss_image_adamw_template.yaml
4
+ # (docs/moss-image-lora-training.md there), 60 epochs. Trains the bf16 BASE model ComfyUI
5
+ # already has, so nothing is downloaded.
6
+ #
7
+ # Placeholders filled by trainer-runner-config.service.ts:
8
+ # [dataset_location] [person_to_train] the dataset folder
9
+ # [comfyui_diffusion_models] [comfyui_vae] [comfyui_text_encoders]
10
+ # COMFYUI_MODELS_PATH / COMFYUI_VAE_PATH / COMFYUI_TEXT_ENCODERS_PATH
11
+ # `trigger` and `default_caption` are rewritten from the job's token and class.
12
+ #
13
+ # The output file is moss_image_<person>_v1_adamw.safetensors. After training it is copied into
14
+ # ComfyUI's loras/Moss/celebs (resized first when "Resize LoRA" is on), with the version raised
15
+ # when that name is taken. moss_image_template-combined.yaml trains this template as one member
16
+ # of a soup.
17
+
18
+ model:
19
+ transformer_path: '[comfyui_diffusion_models]/MOSS/moss_image_base_bf16.safetensors'
20
+ vae_path: '[comfyui_vae]/flux2_vae.safetensors'
21
+ # Qwen3.5-9B. Only used while caching prompt embeddings, then unloaded.
22
+ text_encoder_path: '[comfyui_text_encoders]/qwen3.5_9b_int8_convrot.safetensors'
23
+
24
+ dataset:
25
+ path: '[dataset_location]/[person_to_train]'
26
+ resolution: 512 # area target; buckets keep each image's aspect on a 16 px grid
27
+ aspect_mode: 'bucket'
28
+ trigger: '[person_to_train]'
29
+ default_caption: 'a photo of [person_to_train]'
30
+ repeats: 1
31
+
32
+ lora:
33
+ rank: 16
34
+ alpha: 16
35
+ prefix: 'diffusion_model.'
36
+ targets: 'blocks' # attention + feed-forward of the 42 joint blocks (252 modules)
37
+ dtype: 'float32'
38
+
39
+ train:
40
+ batch_size: 1
41
+ gradient_accumulation_steps: 1
42
+ max_steps: 0 # 0 = train num_epochs full epochs
43
+ num_epochs: 60
44
+ save_every: 0 # 0 = only the final file
45
+ # The report's last pretraining interval: logit(sigma) ~ N(1.09, 0.95), truncated at 0.95,
46
+ # 1 % uniform, no shift.
47
+ timestep_distribution: 'logit_normal'
48
+ timestep_logit_mean: 1.09
49
+ timestep_logit_std: 0.95
50
+ timestep_cutoff: 0.95
51
+ timestep_uniform_mix: 0.01
52
+ timestep_shift: 1.0
53
+ timestep_grid: 1000
54
+ max_grad_norm: 1.0
55
+ gradient_checkpointing: true
56
+ int8_grad_precision: 'bf16'
57
+ optimizer: 'adamw8bit'
58
+ learning_rate: 1.0e-4 # constant, no warmup
59
+ weight_decay: 0.01
60
+ ema_decay: 0.98 # checkpoints save the average
61
+ # The reference sampler uses real CFG against the empty prompt; dropping a caption now and then
62
+ # keeps the LoRA's unconditional branch in step.
63
+ caption_dropout: 0.05
64
+
65
+ dtype: 'bfloat16'
66
+ mixed_precision: 'bf16'
67
+ seed: 42
68
+
69
+ output:
70
+ path: './output/moss_image_[person_to_train]_adamw'
71
+ name: 'moss_image_[person_to_train]_v1_adamw'
72
+ dtype: 'bfloat16'
73
+ embed_config: true
74
+
75
+ logging:
76
+ level: 'INFO'
moss/templates/moss_image_template-automagic3.yaml ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # MOSS-Image LoRA -- MalTrainer (train_moss_image_lora.py), Automagic3.
2
+ #
3
+ # The recipe of MalTrainer's own config/moss_image_automagic_template.yaml
4
+ # (docs/moss-image-lora-training.md there), 20 epochs. Trains the bf16 BASE model ComfyUI
5
+ # already has, so nothing is downloaded.
6
+ #
7
+ # Placeholders filled by trainer-runner-config.service.ts:
8
+ # [dataset_location] [person_to_train] the dataset folder
9
+ # [comfyui_diffusion_models] [comfyui_vae] [comfyui_text_encoders]
10
+ # COMFYUI_MODELS_PATH / COMFYUI_VAE_PATH / COMFYUI_TEXT_ENCODERS_PATH
11
+ # `trigger` and `default_caption` are rewritten from the job's token and class.
12
+ #
13
+ # The output file is moss_image_<person>_v1_automagic3.safetensors. After training it is copied into
14
+ # ComfyUI's loras/Moss/celebs (resized first when "Resize LoRA" is on), with the version raised
15
+ # when that name is taken. moss_image_template-combined.yaml trains this template as one member
16
+ # of a soup.
17
+
18
+ model:
19
+ transformer_path: '[comfyui_diffusion_models]/MOSS/moss_image_base_bf16.safetensors'
20
+ vae_path: '[comfyui_vae]/flux2_vae.safetensors'
21
+ # Qwen3.5-9B. Only used while caching prompt embeddings, then unloaded.
22
+ text_encoder_path: '[comfyui_text_encoders]/qwen3.5_9b_int8_convrot.safetensors'
23
+
24
+ dataset:
25
+ path: '[dataset_location]/[person_to_train]'
26
+ resolution: 512 # area target; buckets keep each image's aspect on a 16 px grid
27
+ aspect_mode: 'bucket'
28
+ trigger: '[person_to_train]'
29
+ default_caption: 'a photo of [person_to_train]'
30
+ repeats: 1
31
+
32
+ lora:
33
+ rank: 16
34
+ alpha: 16
35
+ prefix: 'diffusion_model.'
36
+ targets: 'blocks' # attention + feed-forward of the 42 joint blocks (252 modules)
37
+ dtype: 'float32'
38
+
39
+ train:
40
+ batch_size: 1
41
+ gradient_accumulation_steps: 1
42
+ max_steps: 0 # 0 = train num_epochs full epochs
43
+ num_epochs: 20
44
+ save_every: 0 # 0 = only the final file
45
+ # The report's last pretraining interval: logit(sigma) ~ N(1.09, 0.95), truncated at 0.95,
46
+ # 1 % uniform, no shift.
47
+ timestep_distribution: 'logit_normal'
48
+ timestep_logit_mean: 1.09
49
+ timestep_logit_std: 0.95
50
+ timestep_cutoff: 0.95
51
+ timestep_uniform_mix: 0.01
52
+ timestep_shift: 1.0
53
+ timestep_grid: 1000
54
+ max_grad_norm: 1.0
55
+ gradient_checkpointing: true
56
+ int8_grad_precision: 'bf16'
57
+ optimizer: 'automagic3'
58
+ learning_rate: 1.0e-6 # Automagic3 launch point; it adapts from here
59
+ weight_decay: 0.0
60
+ automagic_param_groups: true # attention / MLP / other each adapt their own rate
61
+ automagic_polarity_history: 8
62
+ automagic_clip_threshold: 1.0
63
+ automagic_beta2: 0.999
64
+ automagic_eps: 1.0e-30
65
+ ema_decay: 0.98 # checkpoints save the average
66
+ # The reference sampler uses real CFG against the empty prompt; dropping a caption now and then
67
+ # keeps the LoRA's unconditional branch in step.
68
+ caption_dropout: 0.05
69
+
70
+ dtype: 'bfloat16'
71
+ mixed_precision: 'bf16'
72
+ seed: 42
73
+
74
+ output:
75
+ path: './output/moss_image_[person_to_train]_automagic3'
76
+ name: 'moss_image_[person_to_train]_v1_automagic3'
77
+ dtype: 'bfloat16'
78
+ embed_config: true
79
+
80
+ logging:
81
+ level: 'INFO'
moss/templates/moss_image_template-prodigy.yaml ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # MOSS-Image LoRA -- MalTrainer (train_moss_image_lora.py), Prodigy.
2
+ #
3
+ # The recipe of MalTrainer's own config/moss_image_prodigy_template.yaml
4
+ # (docs/moss-image-lora-training.md there), 30 epochs. Trains the bf16 BASE model ComfyUI
5
+ # already has, so nothing is downloaded.
6
+ #
7
+ # Placeholders filled by trainer-runner-config.service.ts:
8
+ # [dataset_location] [person_to_train] the dataset folder
9
+ # [comfyui_diffusion_models] [comfyui_vae] [comfyui_text_encoders]
10
+ # COMFYUI_MODELS_PATH / COMFYUI_VAE_PATH / COMFYUI_TEXT_ENCODERS_PATH
11
+ # `trigger` and `default_caption` are rewritten from the job's token and class.
12
+ #
13
+ # The output file is moss_image_<person>_v1_prodigy.safetensors. After training it is copied into
14
+ # ComfyUI's loras/Moss/celebs (resized first when "Resize LoRA" is on), with the version raised
15
+ # when that name is taken. moss_image_template-combined.yaml trains this template as one member
16
+ # of a soup.
17
+
18
+ model:
19
+ transformer_path: '[comfyui_diffusion_models]/MOSS/moss_image_base_bf16.safetensors'
20
+ vae_path: '[comfyui_vae]/flux2_vae.safetensors'
21
+ # Qwen3.5-9B. Only used while caching prompt embeddings, then unloaded.
22
+ text_encoder_path: '[comfyui_text_encoders]/qwen3.5_9b_int8_convrot.safetensors'
23
+
24
+ dataset:
25
+ path: '[dataset_location]/[person_to_train]'
26
+ resolution: 512 # area target; buckets keep each image's aspect on a 16 px grid
27
+ aspect_mode: 'bucket'
28
+ trigger: '[person_to_train]'
29
+ default_caption: 'a photo of [person_to_train]'
30
+ repeats: 1
31
+
32
+ lora:
33
+ rank: 16
34
+ alpha: 16
35
+ prefix: 'diffusion_model.'
36
+ targets: 'blocks' # attention + feed-forward of the 42 joint blocks (252 modules)
37
+ dtype: 'float32'
38
+
39
+ train:
40
+ batch_size: 1
41
+ gradient_accumulation_steps: 1
42
+ max_steps: 0 # 0 = train num_epochs full epochs
43
+ num_epochs: 30
44
+ save_every: 0 # 0 = only the final file
45
+ # The report's last pretraining interval: logit(sigma) ~ N(1.09, 0.95), truncated at 0.95,
46
+ # 1 % uniform, no shift.
47
+ timestep_distribution: 'logit_normal'
48
+ timestep_logit_mean: 1.09
49
+ timestep_logit_std: 0.95
50
+ timestep_cutoff: 0.95
51
+ timestep_uniform_mix: 0.01
52
+ timestep_shift: 1.0
53
+ timestep_grid: 1000
54
+ max_grad_norm: 1.0
55
+ gradient_checkpointing: true
56
+ int8_grad_precision: 'bf16'
57
+ optimizer: 'prodigy'
58
+ learning_rate: 1.0 # Prodigy's multiplier on its own estimated step size
59
+ learning_rate_warmup_steps: 100
60
+ weight_decay: 0.01
61
+ adam_beta1: 0.9
62
+ prodigy_beta2: 0.99
63
+ prodigy_eps: 1.0e-8
64
+ prodigy_d0: 1.0e-6 # initial step-size guess; Prodigy grows it
65
+ prodigy_d_coef: 1.0
66
+ prodigy_decouple: true
67
+ prodigy_use_bias_correction: true
68
+ prodigy_safeguard_warmup: true
69
+ ema_decay: 0.0 # Prodigy's step size does the smoothing
70
+ # The reference sampler uses real CFG against the empty prompt; dropping a caption now and then
71
+ # keeps the LoRA's unconditional branch in step.
72
+ caption_dropout: 0.05
73
+
74
+ dtype: 'bfloat16'
75
+ mixed_precision: 'bf16'
76
+ seed: 42
77
+
78
+ output:
79
+ path: './output/moss_image_[person_to_train]_prodigy'
80
+ name: 'moss_image_[person_to_train]_v1_prodigy'
81
+ dtype: 'bfloat16'
82
+ embed_config: true
83
+
84
+ logging:
85
+ level: 'INFO'