Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ API and command-line option may change frequently.***
- [Mage-Flow-Edit](./docs/models/mage_flow.md#image-editing)
- [LLaDA-Image Edit](./docs/models/llada_image.md#image-editing)
- [Fibo 2.0 Dev / Edit Turbo](./docs/models/fibo2.md#fibo-20-edit-turbo)
- [MOSS-Image Edit](./docs/models/moss_image.md#moss-image-edit)
- Video Models
- [Wan2.1/Wan2.2](./docs/models/wan.md)
- [MiniMax-H3](./docs/models/minimax_h3.md)
Expand Down
2 changes: 1 addition & 1 deletion docs/dgl-builtins.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Optional parameters are marked with `?`. Default values follow `=`. See [DGL syn
| `photomaker::encode_images` | `photomaker: photomaker`, `images: list<tensor>`, `id_embedding?: tensor` | `tensor` |
| `photomaker::encode_prompt` | `encoder: text_encoder`, `text: string`, `tokens: tensor`, `width?: int = 1024`, `height?: int = 1024`, `clip_skip?: int = -1` | `dict`<br>`condition: dict`<br>`condition.concat: tensor`<br>`condition.crossattn: tensor`<br>`condition.extra_crossattn: list<tensor>`<br>`condition.image_embed_indices: list<tensor>`<br>`condition.image_embeds: list<tensor>`<br>`condition.input_ids: tensor`<br>`condition.position_ids: tensor`<br>`condition.ref_audios: list<tensor>`<br>`condition.ref_images: list<tensor>`<br>`condition.reference_blocks: list<dict>`<br>`condition.reference_blocks.audio: int`<br>`condition.reference_blocks.kind: string`<br>`condition.reference_blocks.video: int`<br>`condition.t5_ids: tensor`<br>`condition.t5_weights: tensor`<br>`condition.token_types: tensor`<br>`condition.vector: tensor`<br>`condition.vinput_mask: tensor`<br>`mask: tensor`<br>`plain: dict`<br>`plain.concat: tensor`<br>`plain.crossattn: tensor`<br>`plain.extra_crossattn: list<tensor>`<br>`plain.image_embed_indices: list<tensor>`<br>`plain.image_embeds: list<tensor>`<br>`plain.input_ids: tensor`<br>`plain.position_ids: tensor`<br>`plain.ref_audios: list<tensor>`<br>`plain.ref_images: list<tensor>`<br>`plain.reference_blocks: list<dict>`<br>`plain.reference_blocks.audio: int`<br>`plain.reference_blocks.kind: string`<br>`plain.reference_blocks.video: int`<br>`plain.t5_ids: tensor`<br>`plain.t5_weights: tensor`<br>`plain.token_types: tensor`<br>`plain.vector: tensor`<br>`plain.vinput_mask: tensor` |
| `photomaker::load` (resource) | `path: string`, `family?: string = "auto"`, `wtype?: string = "auto"`, `conv_scale?: number = 0`, `linear_scale?: number = 0`, `attn_scale?: number = 0`, `backend?: string = ""`, `params_backend?: string = ""`, `split_mode?: string = ""`, `model_args?: string = ""`, `tensor_type_rules?: string = ""`, `flash_attn_mode?: string = "auto"`, `conv_direct_mode?: string = "auto"`, `sage_attn?: bool = false` | `photomaker` |
| `predictor` | `model: denoiser`, `condition: dict`, `prediction?: string = "auto"`, `concat?: tensor`, `ref_latents?: list<tensor>`, `ref_audios?: list<tensor>`, `reference_blocks?: list<dict>`, `keyframe_indices?: list<int>`, `ref_index_mode?: string = "fixed"`, `force_ref_timestep_zero?: bool = false`, `guidance?: number = 3.5`, `skip_layers?: list<int>`, `vace_context?: tensor`, `vace_strength?: number = 1`, `audio_embedding?: tensor`, `video_positions?: tensor`, `audio_length?: int = 0`, `fps?: number = 24`, `video_sigma_shift?: number = 12`, `audio_sigma_shift?: number = 3`, `circular_x?: bool = false`, `circular_y?: bool = false`, `transform?: fn`, `transform_args?: dict` | `predictor` |
| `predictor` | `model: denoiser`, `condition: dict`, `prediction?: string = "auto"`, `concat?: tensor`, `ref_latents?: list<tensor>`, `ref_audios?: list<tensor>`, `reference_blocks?: list<dict>`, `keyframe_indices?: list<int>`, `ref_index_mode?: string = "fixed"`, `force_ref_timestep_zero?: bool = false`, `ref_rope_anchor?: string = "default"`, `guidance?: number = 3.5`, `skip_layers?: list<int>`, `vace_context?: tensor`, `vace_strength?: number = 1`, `audio_embedding?: tensor`, `video_positions?: tensor`, `audio_length?: int = 0`, `fps?: number = 24`, `video_sigma_shift?: number = 12`, `audio_sigma_shift?: number = 3`, `circular_x?: bool = false`, `circular_y?: bool = false`, `transform?: fn`, `transform_args?: dict` | `predictor` |
| `preview` | `decoder?: vae`, `circular_x?: bool = false`, `circular_y?: bool = false` | `sampling_observer` |
| `pulid::apply` | `condition: dict`, `pulid: pulid`, `embedding: tensor`, `strength?: number = 1`, `start_sigma?: number`, `end_sigma?: number` | same type as `condition`<br>`pulid: pulid_bindings` |
| `pulid::load` (resource) | `path: string`, `family?: string = "auto"`, `wtype?: string = "auto"`, `conv_scale?: number = 0`, `linear_scale?: number = 0`, `attn_scale?: number = 0`, `backend?: string = ""`, `params_backend?: string = ""`, `split_mode?: string = ""`, `model_args?: string = ""`, `tensor_type_rules?: string = ""`, `flash_attn_mode?: string = "auto"`, `conv_direct_mode?: string = "auto"`, `sage_attn?: bool = false` | `pulid` |
Expand Down
4 changes: 4 additions & 0 deletions docs/dgl.md
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,10 @@ pixels to `encode_prompt` and prepared latents to `predictor` explicitly.
`predictor(ref_index_mode="increase")` selects reference position indexing;
the default is `"fixed"`. Use `"decrease"` for layered references and set
`force_ref_timestep_zero=true` when required by the checkpoint.
For MOSS-Image, `ref_rope_anchor` aligns reference tokens with the start of the
image (`"image_start"`) or text (`"text_start"`) along the RoPE sequence axis.
`"default"` uses the model's alignment. See the
[MOSS-Image editing examples](models/moss_image.md#dgl).

`prediction` belongs to `predictor`, for example
`pos = predictor(dit, condition, prediction="eps")`. `load_dit` and its
Expand Down
2 changes: 1 addition & 1 deletion docs/dgl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ and [NumPy tensor files](../dgl.md#tensor-files).
| [Ming-Image](../models/ming_image.md) | [0.1 Design text to image](ming_image/ming-image-0-1-design-txt2img.dgl) |
| [MiniMax-H3-Image](../models/minimax_h3_image.md) | [Text to image](minimax_h3_image/minimax-h3-image-txt2img.dgl) · [Image editing](minimax_h3_image/minimax-h3-image-edit.dgl) |
| [MiniT2I](../models/minit2i.md) | [CUDA](minit2i/minit2i-cuda-txt2img.dgl) · [Metal](minit2i/minit2i-metal-txt2img.dgl) (`--threads 8`) |
| [MOSS-Image](../models/moss_image.md) | [Base: text to image](moss_image/moss-image-base-txt2img.dgl) · [SFT: text to image](moss_image/moss-image-sft-txt2img.dgl) · [Inline images](moss_image/moss-image-sft-inline-images.dgl) |
| [MOSS-Image](../models/moss_image.md) | [Base: text to image](moss_image/moss-image-base-txt2img.dgl) · [SFT: text to image](moss_image/moss-image-sft-txt2img.dgl) · [Inline images](moss_image/moss-image-sft-inline-images.dgl) · [Image editing (HQ)](moss_image/moss-image-edit.dgl) · [Image editing (chinoll)](moss_image/moss-image-edit-chinoll.dgl) |
| [Ovis-Image](../models/ovis_image.md) | [Text to image](ovis_image/ovis-image-txt2img.dgl) |
| [P-H3-Image](../models/p_h3_image.md) | [Text to image](p_h3_image/p-h3-image-txt2img.dgl) · [Image editing](p_h3_image/p-h3-image-edit.dgl) |
| [PiD](../models/pid.md) | [512 to 2048 pixels](pid/pid-flux1-512-to-2048-txt2img.dgl) |
Expand Down
63 changes: 63 additions & 0 deletions docs/dgl/moss_image/moss-image-edit-chinoll.dgl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# version: 0.0.0
# docs/models/moss_image.md — chinoll/Moss-Image-Edit

var {
model_path = "../models/diffusion_models/moss_image_sft_int8_convrot_attn.safetensors"
text_path = "../models/text_encoders/Qwen3.5-9B-Q4_K_M.gguf"
tokenizer_path = "../models/tokenizers/tokenizer_qwen3.5.json"
vae_path = "../models/vae/flux2_ae.safetensors"
lora_path = "../models/loras/moss/moss-edit-lora.safetensors"
lora_weight = 1.0

reference_paths = ["../assets/flux/flux1-dev-q8_0.png"]
output_path = "output.png"

prompt = "change 'flux.cpp' to 'moss.cpp'"
negative_prompt = ""

seed = 42
rng_type = "cuda"
width = 512
height = 512

steps = 20
cfg_scale = 3.0
method = "euler"
scheduler = "discrete"
}

fn encode_reference(path, vae, rng) {
image = image::to_f32(image::load(path), channels = 3)
shape = tensor::shape(image)
long_edge = shape[0] + shape[1] - math::min(shape[0], shape[1])
scale = math::min(1024, long_edge) / long_edge
rounded = [math::round(shape[0] * scale / 16) * 16, math::round(shape[1] * scale / 16) * 16]
size = tensor::maximum(tensor::vector(rounded, dtype = "i64"), tensor::full([2], 16, dtype = "i64"))
pixels = tensor::interpolate(image, size = size, mode = "bilinear")
return vae_to_dit_latents(vae, vae_encode(vae, pixels, rng = rng))
}

fn main() {
base_model = load_dit(model_path, family = "moss_image")
model = apply_lora(base_model, load_lora(lora_path), weight = lora_weight, mode = "auto")
text = load_text_encoder(text_path, family = "moss_image", tokenizer = tokenizer_path)
vae = load_vae(vae_path, family = "moss_image")

encode_rng = make_rng(rng_type, seed = seed)
references = map(reference_paths, process = encode_reference, vae = vae, rng = encode_rng)
base = tensor::zeros(latent_shape(vae, width = width, height = height))
positive = encode_prompt(text, prompt, width = width, height = height)
negative = encode_prompt(text, negative_prompt, width = width, height = height)
pos = predictor(model, positive, ref_latents = references,
ref_index_mode = "increase", ref_rope_anchor = "text_start", force_ref_timestep_zero = true)
neg = predictor(model, negative, ref_latents = references,
ref_index_mode = "increase", ref_rope_anchor = "text_start", force_ref_timestep_zero = true)
guided = cfg(pos, neg, scale = cfg_scale)
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler)
rng = make_rng(rng_type, seed = seed)
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
image::save(output_path, image)
return {image = image, latent = latent}
}
69 changes: 69 additions & 0 deletions docs/dgl/moss_image/moss-image-edit.dgl
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# version: 0.0.0
# docs/models/moss_image.md — MOSS-Image-Edit-HQ

var {
model_path = "../models/diffusion_models/moss_image_sft_int8_convrot_attn.safetensors"
text_path = "../models/text_encoders/Qwen3.5-9B-Q4_K_M.gguf"
vision_path = "../models/text_encoders/Qwen3.5-9B-mmproj-BF16.gguf"
tokenizer_path = "../models/tokenizers/tokenizer_qwen3.5.json"
vae_path = "../models/vae/flux2_ae.safetensors"
lora_path = "../models/loras/moss/armV5-moss-edit-lora.safetensors"
lora_weight = 1.0

reference_paths = ["../assets/flux/flux1-dev-q8_0.png"]
output_path = "output.png"

prompt = "change 'flux.cpp' to 'moss.cpp'"
negative_prompt = ""

seed = 42
rng_type = "cuda"
width = 512
height = 512

steps = 20
cfg_scale = 3.0
method = "euler"
scheduler = "discrete"
}

fn load_reference(path) {
return image::to_f32(image::load(path), channels = 3)
}

fn encode_reference(image, vae, rng) {
shape = tensor::shape(image)
long_edge = shape[0] + shape[1] - math::min(shape[0], shape[1])
scale = math::min(1024, long_edge) / long_edge
rounded = [math::round(shape[0] * scale / 16) * 16, math::round(shape[1] * scale / 16) * 16]
size = tensor::maximum(tensor::vector(rounded, dtype = "i64"), tensor::full([2], 16, dtype = "i64"))
pixels = tensor::interpolate(image, size = size, mode = "bilinear")
return vae_to_dit_latents(vae, vae_encode(vae, pixels, rng = rng))
}

fn main() {
base_model = load_dit(model_path, family = "moss_image")
model = apply_lora(base_model, load_lora(lora_path), weight = lora_weight, mode = "auto")
text = load_text_encoder(text_path, family = "moss_image",
tokenizer = tokenizer_path, vision_path = vision_path)
vae = load_vae(vae_path, family = "moss_image")

encode_rng = make_rng(rng_type, seed = seed)
images = map(reference_paths, process = load_reference)
references = map(images, process = encode_reference, vae = vae, rng = encode_rng)
base = tensor::zeros(latent_shape(vae, width = width, height = height))
positive = encode_prompt(text, prompt, width = width, height = height, media = images)
negative = encode_prompt(text, negative_prompt, width = width, height = height, media = images)
pos = predictor(model, positive, ref_latents = references,
ref_index_mode = "increase", ref_rope_anchor = "image_start", force_ref_timestep_zero = true)
neg = predictor(model, negative, ref_latents = references,
ref_index_mode = "increase", ref_rope_anchor = "image_start", force_ref_timestep_zero = true, skip_layers = [22])
guided = cfg(pos, neg, scale = cfg_scale)
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler)
rng = make_rng(rng_type, seed = seed)
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
image::save(output_path, image)
return {image = image, latent = latent}
}
1 change: 1 addition & 0 deletions docs/guides/edit.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ that do not support image guidance report an error.
| Fibo 2.0 | Shared center crops for VAE and vision encoding; multiple references use aspect-ratio buckets |
| [Anima Edit](../models/anima.md) | Matching community editing LoRA; VAE reference latents |
| [Krea2 Edit](../models/krea2.md) | Matching community editing LoRA; vision inputs and VAE reference latents |
| [MOSS-Image Edit](../models/moss_image.md#moss-image-edit) | HQ LoRA with VAE reference latents and optional vision conditioning |
| LLaDA-Image | Reference pixels go to the text encoder's native image components and reference latents to the diffusion model |
| MiniMax-H3 | Aspect-preserving references aligned to the model grid |

Expand Down
61 changes: 56 additions & 5 deletions docs/models/moss_image.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# MOSS-Image

MOSS-Image uses a 5B diffusion transformer, the FLUX.2 VAE, and Qwen3.5 9B as the LLM text encoder. Both Base and SFT are supported. Prompt enhancement is not included.
Image editing requires a matching LoRA.

## Model files

Expand All @@ -10,13 +11,15 @@ MOSS-Image uses a 5B diffusion transformer, the FLUX.2 VAE, and Qwen3.5 9B as th
| vae | [Safetensors](https://huggingface.co/Comfy-Org/MOSS-Image/tree/main/vae) | `--vae` | Use matching VAE |
| Qwen3.5 9B | [GGUF](https://huggingface.co/unsloth/Qwen3.5-9B-GGUF/tree/main) | `--llm` | Use matching text encoder |
| `tokenizer.json` | [Download](https://huggingface.co/OpenMOSS-Team/MOSS-Image-Base/tree/main/tokenizer) | `--tokenizer` | Required; match text encoder |
| Qwen3.5 9B vision projector | [GGUF](https://huggingface.co/unsloth/Qwen3.5-9B-GGUF/blob/main/mmproj-BF16.gguf) | `--llm_vision` | Required for vision inputs when the encoder uses separate vision weights |
| MOSS-Image-Edit-HQ LoRA | [`armV5-moss-edit-lora.safetensors`](https://huggingface.co/akhaliq/MOSS-Image-Edit-HQ/blob/main/armV5-moss-edit-lora.safetensors) | `--lora-model-dir` | HQ editing with SFT |
| chinoll Moss-Image-Edit LoRA | [`adapter_model.safetensors`](https://huggingface.co/chinoll/Moss-Image-Edit/blob/main/adapter_model.safetensors) | — | Editing with Base or SFT in DGL |

Pass the external `tokenizer.json` with `--tokenizer`; Qwen3.5 uses a different vocabulary from the embedded Qwen tokenizer.

For [inline prompt images](../guides/prompt_images.md), use a matching Qwen3.5
vision projector. Pass it with `--llm_vision` in the CLI or `vision_path` on
`load_text_encoder` in dgl. See the
[DGL example](../dgl/moss_image/moss-image-sft-inline-images.dgl).
[Inline prompt images](../guides/prompt_images.md) require Qwen3.5 vision
weights. HQ editing also uses them when available. Pass a separate projector
with `--llm_vision` in the CLI or `vision_path` on `load_text_encoder` in DGL.

## Usage

Expand All @@ -43,6 +46,8 @@ Select optional components when required by your checkpoint or task.
| [Base: text to image](../dgl/moss_image/moss-image-base-txt2img.dgl) | MOSS-Image Base. |
| [SFT: text to image](../dgl/moss_image/moss-image-sft-txt2img.dgl) | MOSS-Image SFT. |
| [Inline images](../dgl/moss_image/moss-image-sft-inline-images.dgl) | Insert named images into the prompt. |
| [Image editing (HQ)](../dgl/moss_image/moss-image-edit.dgl) | SFT with the armV5 LoRA and a Qwen3.5 vision projector. |
| [Image editing (chinoll)](../dgl/moss_image/moss-image-edit-chinoll.dgl) | Base or SFT with the chinoll LoRA. |

#### Run a script

Expand Down Expand Up @@ -140,4 +145,50 @@ CLI examples use the [shared path and shell conventions](README.md#example-conve

<img src="../../assets/moss/sft.png" />

Use dimensions divisible by 16. The default discrete scheduler uses the upstream time shift of 5. Use `--flow-shift` to override it. The CLI and C API set `skip_layers = [22]` on the negative predictor when translating requests to DGL, matching the upstream pipeline. Handwritten DGL scripts specify this zero-based layer index explicitly, as shown in the examples.
#### MOSS-Image Edit

The CLI uses the HQ workflow with SFT. Save the LoRA as
`models/loras/moss/armV5-moss-edit-lora.safetensors` or adjust the LoRA tag below.
Pass `-r` for each reference image.

**Windows (PowerShell)**

```powershell
.\bin\Release\sd-cli.exe `
--diffusion-model ..\models\diffusion_models\moss_image_sft_int8_convrot_attn.safetensors `
--llm ..\models\text_encoders\Qwen3.5-9B-Q4_K_M.gguf `
--llm_vision ..\models\text_encoders\Qwen3.5-9B-mmproj-BF16.gguf `
--vae ..\models\vae\flux2_ae.safetensors `
--tokenizer ..\models\tokenizers\tokenizer_qwen3.5.json `
--lora-model-dir ..\models\loras `
-r ..\assets\flux\flux1-dev-q8_0.png `
-p "change 'flux.cpp' to 'moss.cpp'<lora:moss/armV5-moss-edit-lora:1.0>" `
--cfg-scale 3.0 `
-v
```

**Linux/macOS**

```sh
./bin/sd-cli \
--diffusion-model ../models/diffusion_models/moss_image_sft_int8_convrot_attn.safetensors \
--llm ../models/text_encoders/Qwen3.5-9B-Q4_K_M.gguf \
--llm_vision ../models/text_encoders/Qwen3.5-9B-mmproj-BF16.gguf \
--vae ../models/vae/flux2_ae.safetensors \
--tokenizer ../models/tokenizers/tokenizer_qwen3.5.json \
--lora-model-dir ../models/loras \
-r ../assets/flux/flux1-dev-q8_0.png \
-p "change 'flux.cpp' to 'moss.cpp'<lora:moss/armV5-moss-edit-lora:1.0>" \
--cfg-scale 3.0 \
-v
```

## Notes and limitations

Use output dimensions divisible by 16. The editing examples cap the reference
long edge at 1024 pixels. The discrete scheduler defaults to a flow shift of 5.
Use `--flow-shift` to override it. Prompt weights use `(phrase:1.2)` syntax.

For text-to-image and HQ editing, the CLI and C API set `skip_layers = [22]` on
the negative predictor. The corresponding DGL examples set the same zero-based
layer index.
Loading
Loading