MOSS-SFT-Distill-4step-LoRA
lvladikov/MOSS-SFT-Distill-4step-LoRA
- 作者
- lvladikov
- 任务
- 图像生成
- 下载量
- 10,726
- 点赞数
- 87
- 趋势分
- 13
- 许可证
- apache-2.0
- 收录时间
- 2026/11/20
base_model: OpenMOSS-Team/MOSS-Image-SFT base_model_relation: adapter license: apache-2.0 library_name: diffusers tags:
- lora
- text-to-image
- distillation
- step-distillation
- moss-image pipeline_tag: text-to-image widget:
- text: >- Portrait of a young woman with freckles and windswept auburn hair, soft window light, shallow depth of field, photograph, sharp detail output: url: assets/images/portrait.jpg
- text: >- A snow leopard walking along a rocky ridge in falling snow, telephoto wildlife photograph, natural light output: url: assets/images/snowleopard.jpg
- text: >- A fox in a red scarf reading a small book with a plain cover under a mushroom, whimsical watercolour painting, one continuous scene filling the entire frame, watercolour texture, soft edges output: url: assets/images/watercolourfox.jpg
- text: >- Busy outdoor street market crowded with many people browsing colorful fruit and vegetable stalls, awnings, midday sun, wide shot, photorealistic output: url: assets/images/market.jpg
- text: >- A kingfisher bird bursting out of water with spread wings, water droplets frozen mid-air, iridescent blue and orange feathers, high-speed photography output: url: assets/images/kingfisher.jpg
- text: >- A curious young inventor girl with oversized goggles, 3D animated film style, subsurface skin, soft studio lighting, shallow depth of field output: url: assets/images/inventor.jpg
- text: >- A giant mecha standing in a rain-soaked city plaza, anime style, panel lining, glowing cockpit, dramatic low angle output: url: assets/images/mecha.jpg
- text: >- Rainy night city street with glowing neon shop signs and readable text, wet asphalt reflections, pedestrians with umbrellas, cinematic output: url: assets/images/neonstreet.jpg
- text: >- A storm sorceress channelling lightning, video-game splash art, bold rim lighting, energetic brush strokes, high contrast output: url: assets/images/sorceress.jpg
- text: >- A claymation chef holding a tiny cake, visible fingerprints in the clay, miniature set, tilt-shift output: url: assets/images/claychef.jpg
- text: >- A rainy Shanghai street at night with a large red neon sign that reads "深夜食堂" above a noodle shop and a smaller blue neon sign that says "OPEN 24H", reflections on the wet pavement, people with umbrellas, cinematic photograph output: url: assets/images/text_shanghai.jpg
- text: >- A printed paper menu card standing on a restaurant table with the title "LUNCH" and five lines below it that read "Tomato Soup $6.00", "Cheese Toast $7.50", "Fish Tacos $11.00", "Lemon Cake $5.00" and "Green Tea $3.75", a glass of water and cutlery beside it, soft daylight, photograph output: url: assets/images/text_menu5.jpg
MOSS-Image SFT — 4-Step Distillation LoRA
4 steps at CFG 1 instead of 50 at CFG 3 · 4 model calls instead of 100 · about 14× less GPU time per picture · close to the teacher's tone, fine texture 1.22× the teacher's · 12 trained resolutions up to 1824×1024 and 1024×1824 · 15,000 training samples
A LoRA for MOSS-Image SFT that renders in 4 steps without CFG what the model renders in 50 steps at CFG 3 — MOSS's own sampler and schedule, one model call per step instead of two, trained by distribution matching against the 50-step teacher, with a critic that compares its pictures with the teacher's and with real photographs.
- ⚡ 4 steps, CFG 1 — 4 model calls against the teacher's 100 (50 steps, two calls each at CFG 3), on MOSS's own 4-step schedule
- ⏱️ About 14× less GPU time — 26.6 s against 387.3 s for the same 22 pictures at 1024×1024 on Comfy Cloud (one job each, the whole job's billed GPU time)
- 🎯 Close to the teacher's tone, with more fine detail — on 21 test prompts at 1824×1024 the mean lightness sits 0.7 L* above the teacher's (scale 0–100), haze 0.94×, colour 1.02×; fine texture 1.22× the teacher's on 22
- 🔤 Writes the words a prompt spells out — every requested string right on 14 of the 15 text test prompts at 1024×1024 (the teacher 15, akhaliq's 4-step LoRA 12)
- 📐 12 trained resolutions — wide, tall and square, from 768×512 and 512×768 up to 1824×1024 and 1024×1824
- 🔌 Two files, one LoRA — the exact LoRA for diffusers / Python, and a ComfyUI file that is right at strength 1.0 in ComfyUI's standard loader
- 🧩 Eight ComfyUI workflows — text to image, layout, image edit and PiD 4×, each for local ComfyUI and for Comfy Cloud
- 🎲 34,000 prompts from Lakonik's 3M-prompt dataset and 2,877 prompts that spell out words — signs, menus, posters, labels
- 📷 About 8,000 captioned photo crops and 3,600 teacher pictures in the critic's real set
- 🔢 15,000 training samples in the shipped weights — rank 64, 252 modules
- 📅 Trained on a single NVIDIA B300 in about 30 hours
Current published checkpoint: chk00015000 — 15,000 training samples, produced 19 Nov 2026.
💡 In ComfyUI, use the
_comfyuifile at strength 1.0. ComfyUI adds a LoRA to the bf16 weights and rounds the sum, and a change as small as this LoRA's loses part of itself on the way: about a fifth, measured. The_comfyuifile carries the measured factor (1.18) in its alpha values, so ComfyUI's standard LoRA loader at 1.0 applies the trained change. diffusers and other exact loaders take the plain file at 1.0.
Examples
This LoRA at 4 steps, CFG 1, 1024×1024, rendered in ComfyUI on Comfy Cloud; each picture's prompt is in its caption. Click a picture to open it. Side by side with the teacher and akhaliq's 4-step: Compared with the teacher.
Files
| file | what it is |
|---|---|
moss_sft_4step_rank_64_lora.safetensors | the LoRA, exact — diffusers / Python at strength 1.0, see diffusers |
moss_sft_4step_rank_64_lora_comfyui.safetensors | the same LoRA for ComfyUI's standard loader at strength 1.0 — see ComfyUI |
moss_sft_4step_lora_*_local.json, moss_sft_4step_lora_*_cloud.json | eight ComfyUI workflows, core nodes only — see ComfyUI |
moss_sft_4step_rank_64_lora_checkpoint_info.md | which checkpoint the files are, with their SHA-256s |
LICENSE | the Apache License 2.0, the base model's licence |
NOTICE.txt | the notice |
The two LoRA files hold the same tensors; the ComfyUI file's alpha values carry the measured factor (64 → 75.5). Both carry the training details in their safetensors metadata. The file names carry no checkpoint number: both hold chk00015000, which also sits in _archive/checkpoints/.
Quick Start
diffusers
As on the official card: Python 3.10+, PyTorch 2.9+ with CUDA, then
pip install "diffusers>=0.38" "transformers>=5.3" "accelerate>=1.10" "safetensors>=0.6" "Pillow>=10"
import torch
import torch.nn.functional as F
from diffusers import DiffusionPipeline
from huggingface_hub import hf_hub_download
from safetensors.torch import load_file
def apply_4step_lora(transformer, strength=1.0):
"""Adds this LoRA beside the transformer's weights, unmerged: y = W x + scale * up(down(x)).
Call it after pipe.to("cuda"), so the LoRA lands on the transformer's device."""
path = hf_hub_download("lvladikov/MOSS-SFT-Distill-4step-LoRA", "moss_sft_4step_rank_64_lora.safetensors")
state = load_file(path)
for key in state:
if not key.endswith(".lora_down.weight"):
continue
stem = key[: -len(".lora_down.weight")] # diffusion_model.layers.N.proj.NAME
layer = transformer.get_submodule(stem.removeprefix("diffusion_model."))
down = state[key].to(layer.weight.device, layer.weight.dtype)
up = state[stem + ".lora_up.weight"].to(layer.weight.device, layer.weight.dtype)
scale = strength * state[stem + ".alpha"].item() / down.shape[0]
def hook(module, args, out, down=down, up=up, scale=scale):
return out + F.linear(F.linear(args[0], down), up) * scale
layer.register_forward_hook(hook)
pipe = DiffusionPipeline.from_pretrained(
"OpenMOSS-Team/MOSS-Image-SFT",
custom_pipeline="pipeline_moss_image",
trust_remote_code=True,
torch_dtype={"default": torch.bfloat16, "vae": torch.float32},
)
pipe.scheduler = type(pipe.scheduler).from_config(pipe.scheduler.config)
pipe.to("cuda")
apply_4step_lora(pipe.transformer)
image = pipe(
"A snow leopard walking along a rocky ridge in falling snow, telephoto wildlife photograph, natural light",
height=1024,
width=1024,
num_inference_steps=4,
guidance_scale=1.0,
generator=torch.Generator("cpu").manual_seed(42),
).images[0]
image.save("moss_4step.png")
num_inference_steps=4andguidance_scale=1.0are the whole configuration. The pipeline's own scheduler lands on σ = 1.0, 0.910, 0.717, 0.024 at 4 steps — the four noise levels the LoRA is trained on — and atguidance_scale=1.0it makes one model call per step, with no negative pass.- Why the helper: MOSS's custom pipeline has no
load_lora_weights.apply_4step_loraaddsmoss_sft_4step_rank_64_lora.safetensorsbeside the bf16 weights, as in training. Merged into bf16 weights with plain rounding, this LoRA would lose part of its change.
ComfyUI
| file | put it in |
|---|---|
moss_sft_4step_rank_64_lora_comfyui.safetensors (this repo) | ComfyUI/models/loras/ |
moss_image_sft_bf16.safetensors (Comfy-Org/MOSS-Image) | ComfyUI/models/diffusion_models/ |
qwen3.5_9b_w4a8_gptq.safetensors (same repo) | ComfyUI/models/text_encoders/ |
flux2-vae_small.safetensors (same repo) | ComfyUI/models/vae/ |
Load moss_sft_4step_lora_t2i_local.json — or its _cloud twin on Comfy Cloud. Core ComfyUI nodes only; update ComfyUI first, MOSS-Image support in it is recent.
Settings: euler with Manual Sigmas 1.0, 0.91, 0.717, 0.024, 0.0 (MOSS's own 4-step schedule), CFG 1 (Basic Guider), LoRA strength 1.0 with the _comfyui file, on the bf16 MOSS file. The pictures on this page used the full-precision text encoder, qwen3.5_9b_bf16 (same repo); the workflows load the templates' 4-bit one.
⚙️ Manual Sigmas, not
simple. ComfyUI'ssimplescheduler at 4 steps lands on other noise levels than the four the LoRA is trained on. CFG 1 is one model call per step: no negative prompt and no Skip Layer Guidance, both of which act on the negative pass.
workflow (_local.json / _cloud.json) | what it does |
|---|---|
moss_sft_4step_lora_t2i | text to image, the official MOSS-Image template set up for the LoRA. Its default size, 2848×1600, is above the sizes the LoRA is trained at |
moss_sft_4step_lora_layout_t2i | layout-guided text to image: boxes with captions and text, the official layout template, 1024×1024 |
moss_sft_4step_lora_edit_i2i | image edit with Comfy-Org's MOSS-Image edit LoRA on top, 4 steps at CFG 1; at some seeds the change lands on another item than the one named, and another seed sets it right |
moss_sft_4step_lora_t2i_PiD | a supersampled render, 1184×672, that NVIDIA's PiD then draws at 4×: 4736×2688 |
The _cloud versions load this repo's _comfyui LoRA file from your Comfy Cloud library: import it once from its Hugging Face URL. Each workflow's Models note lists every file it needs.
🍎 On a Mac, large sizes can fail in VAE Decode with MPSGraph does not support tensor dims larger than INT_MAX (the text-to-image default, 2848×1600, is past that point; NVIDIA GPUs decode it directly). Switch to tiled decoding: delete Decode (MOSS VAE), add the core VAE Decode (Tiled) node, connect
samplesfrom the sampler'soutput,vaefrom Load MOSS VAE and itsIMAGEto the Output node. Its defaults (tile 512, overlap 64) are fine. Or start ComfyUI with--cpu-vae: every workflow then decodes on the CPU, slower, at any size.
The workflows in ComfyUI
Each graph at its defaults, then what it made. Click a picture for full size.
Text to image — 2848×1600
Layout — the boxes drawn in Create Bounding Boxes, 1024×1024
Image edit — the photo, then the edit
PiD 4× — 4736×2688
LoRA Strength
| strength | what happens |
|---|---|
| below 1.0 | only part of the trained change arrives; the pictures drift back toward the base model at 4 steps, which draws a blur |
| 1.0 | the trained point — the plain file in diffusers / Python, the _comfyui file in ComfyUI |
| above 1.0 | doubled edges: about 1.3× the trained change measured 1.7× the doubled edges (2.51 against 1.47) for little more fine texture (1.00 against 0.96) |
Keep 1.0: turning it up doubles edges rather than adding detail. The LoRA also runs at 6 and 8 steps; what they change is in More steps.
Recommended companion for photographs
For the most photographic skin, the community MOSS Realism Enhancer LoRA can be added beside this one — Civitai · Hugging Face copy. It is a separate LoRA by its own author under its own licence, not part of this training, and none of the pictures or numbers on this page use it. In ComfyUI it goes in a second LoRA loader after this one.
Method
eDMD + LADD — distribution matching with an endpoint critic (eDMD) against the 50-step teacher, plus a small LADD-style adversarial critic that compares the student's pictures with the teacher's and with about 8,000 real photo crops, so texture is anchored to real photographs as well as to the teacher. Details in the Detailed Model Card.
Hardware
Trained on a single NVIDIA B300 in about 30 hours. The frozen base runs in bf16 with no quantisation, the LoRA in fp32 beside its weights; peak GPU memory 196 GB at 4 prompts per update, every activation kept.
The released LoRA is fp32 and is applied beside the bf16 weights, as in training.
Usage Notes
- 🎯 MOSS-Image SFT only — trained against SFT's weights and its schedule
- 🚫 CFG 1 — diffusers
guidance_scale=1.0, ComfyUI CFG 1; no negative prompt - 📐 MOSS's own schedule — σ = 1.0, 0.910, 0.717, 0.024 at 4 steps; 6 and 8 steps on the same scheduler work too, at the same tone (More steps)
- 📏 Sizes — trained from 768×512 / 512×768 up to 1824×1024 / 1024×1824, in multiples of 16; larger sizes are outside the trained range
- 🧮 In ComfyUI, the bf16 MOSS file (
moss_image_sft_bf16) — the_comfyuifile's factor is measured on it; the official template's int8 file is not measured with this LoRA
Known Limitations
Seen on the published sweep and the comparison sheets:
- invented lettering on signs, decals and titles where the prompt names no words — the teacher does this too
- a rope can come out with an extra length at some sizes
- crowds can look uniform at the tall sizes
- now and then a stray extra object or person — a second cake on the clay chef's counter at 512×768; a fifth diner at the edge of the family-of-four table at 1824×1024
- dark scenes come out a little lighter than the teacher's: +2.8 L* on the nine darkest of 21 test prompts
Compared with the teacher
Every sheet below: the teacher (MOSS-Image SFT, 50 steps, CFG 3 — 100 model calls), akhaliq's MOSS-Image-SFT-4-steps v2.0 (strength 1.0, CFG 1 — 4 calls) and this LoRA (the _comfyui file at strength 1.0, CFG 1 — 4 calls), at 1024×1024, the same prompt and noise in all three panels, rendered in ComfyUI on Comfy Cloud.
Portrait of a young woman with freckles and windswept auburn hair...
Busy outdoor street market crowded with many people browsing colorful fruit and vegetable stalls...
A snow leopard walking along a rocky ridge in falling snow...
A rainy Shanghai street at night with a large red neon sign that reads "深夜食堂"...
A printed paper menu card standing on a restaurant table with the title "LUNCH" and five lines below it...
(32 more examples in the Detailed Model Card — all 37 prompts, see assets/)
Resolution Sweeps
_archive/resolution_sweeps/chk00015000/ — this LoRA at all 12 trained resolutions for the 22 test prompts, plus the 15 text prompts at 1024×1024: 279 pictures, 4 steps, CFG 1, strength 1.0 with the _comfyui file, rendered in ComfyUI on Comfy Cloud. The teacher's pictures of the same prompts at 1024×1024 are in the comparison sheets above.
| wide | tall | square |
|---|---|---|
| 768×512 | 512×768 | 1024×1024 |
| 1024×768 | 768×1024 | 1280×1280 |
| 1280×960 | 960×1280 | 1440×1440 |
| 1440×1280 | 1024×1824 | |
| 1824×1024 |
Layout:
_archive/resolution_sweeps/chk00015000/
├── 512x768/ 22 pictures, one per test prompt (portrait.jpg, kingfisher.jpg, ...)
├── 768x512/
├── ... (all 12 sizes)
├── 1024x1024/ the 22 + the 15 text prompts (text_*.jpg)
└── 1824x1024/
Two ways to read it: down the sweep (does it hold at every size?) or against the teacher at 1024×1024 in the comparison sheets.
Archive
Every published checkpoint and its resolution sweep are kept under _archive/ — checkpoints/ and resolution_sweeps/, each under its number: chk00015000, this one.
Detailed Model Card
The full write-up is in the Detailed Model Card:
- Measured against the teacher — tone, texture, haze and colour, akhaliq's 4-step on the same prompts, the words in the picture
- More steps — 4, 6 and 8 steps against the teacher
- Inference with diffusers and ComfyUI — the settings, the eight workflows, and why ComfyUI gets its own file
- Performance — the measured GPU time per picture
- LoRA strength — the trained point and what more does
- File format and compatibility — the keys, runtime by runtime
- Resolution sweeps — every trained size, every test prompt
- Method — distribution matching, the pairs on the teacher's path and the critic
- What the LoRA touches — the 252 modules
- Training data — the prompts, the photo crops and the teacher pictures
- Resolutions — the 12 training sizes
- Hardware
- Examples — all 37 prompts against the teacher and akhaliq's 4-step, and why these prompts
- Notes and limitations — what the eye found on the published pictures
- What's next
License
This adapter is a derivative of MOSS-Image SFT and is released under its licence, the Apache License 2.0. Copy of the licence: LICENSE; notice: NOTICE.txt.
Not an official OpenMOSS product, not endorsed by the OpenMOSS team. The base model is OpenMOSS's; the adapter, the workflows and the pictures in this repo are mine. The other models the workflows load (the edit LoRA and PiD) come under their own licences.
内容来源:Hugging Face 模型卡
在 Hugging Face 查看