MSdiffusion_Sampler
Brackets, Boxes, and the Sampler That Puts Your Subjects Where You Want Them
- image
- model
- control_image
- image
This is where MS-Diffusion actually happens. MSdiffusion_Sampler takes the model bundle from MSdiffusion_Model_Loader, takes your reference images, and produces one composed image - with each subject placed where you said it should go, not just hoping the prompt does the work. The secret ingredient is the square brackets.
The contract: [brackets] and one image per object
MS-Diffusion's whole trick is multi-subject personalization, and it's enforced by a hard rule the README states plainly: object names must be enclosed in [ ], and as many objects as you have, that many images you must feed in. Prompt a [dog] and [aunt] needs two reference images. a [dog] wearing sunglasses needs one. Get the count wrong and the node raises an error - it doesn't silently cope.
Two more bracket rules from the source, both worth memorizing:
- Each bracket phrase must be a single word. A space inside the brackets (
[brown dog]) raises an error. - The brackets are stripped before the prompt reaches the text encoder, so write the rest of the sentence normally.
What each input actually does
image- your reference images as a batch. Feed the sampler one image directly for a single object, or chain MS_Object_img_Batch in front of it for several.model- theMSDIF_DICTfrom the loader. Nothing else fits.scale(default 0.8) - how strongly the reference images influence the result. Think of it as the pack's IP-Adapter weight: high values hug the reference, low values let the prompt wander. It's a 0–1 slider.mask_threshold(default 0.5) - the "layout guidance" dial. Set it to 0 and MS-Diffusion skips the attention masking entirely, generating with no positional constraint. Keep it and the pseudo-attention mask forces each subject's image tokens to attend to its own box.guidance_list- the layout boxes, in normalizedx0, y0, x1, y1coordinates. The default0., 0.25, 0.4, 0.75;0.6, 0.25, 1., 0.75is two boxes for a two-object image (left half, right half). With multiple objects and a nonzeromask_threshold, you need exactly one box row per object.start_step(default 5) - when during denoising the layout grounding kicks in. This is the ControlNet start/end-step idea applied to grounding: let composition form early, then enforce boxes.controlnet_scale+control_image- only relevant if you loaded a ControlNet in the loader. The optionalcontrol_imageis required then, and this scale weights it.seed,steps,cfg,width,height,batch_size- the usual suspects. Non-square outputs are center-cropped back to your exact width/height, so output size always matches what you asked.
The output is a plain IMAGE - wire it to a preview or Save Image like any other sampler.
Gotchas
It's called a sampler, but it is not a KSampler. There's no latent in/out, no model+conditioning inputs in the ComfyUI sense, and no scheduler knob - the scheduler was fixed at the loader. You can't drop this into a standard sampling graph; it's a self-contained pipeline that happens to emit a tensor. Also, IS_CHANGED always triggers, so the node re-runs on every queue rather than caching. Fine for experiments, mildly annoying for big batch runs.
Installing
Same pack as the loader:
cd ComfyUI/custom_nodes
git clone https://github.com/smthemex/ComfyUI_MS_Diffusion
cd ComfyUI_MS_Diffusion && pip install -r requirements.txt
or one-click via ComfyUI Manager ("ComfyUI_MS_Diffusion"), then restart. Remember the requirements file is thin - pip install diffusers transformers omegaconf safetensors if imports fail. If you get an error about brackets or object/image count mismatches, that's the contract talking: check your prompt and your reference batch before blaming the node.
Inputs (17)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| model | MSDIF_DICT | — | |
| prompt | STRING | a [dog] wearing a pink sunglass | — |
| negative_prompt | STRING | (worst quality, low quality, normal quality, lowres), | — |
| seed | INT | 00–2147483647 | — |
| steps | INT | 201–100 | — |
| cfg | FLOAT | 7.00.1–10 | — |
| scale | FLOAT | 0.80–1 | — |
| mask_threshold | FLOAT | 0.50–1 | — |
| start_step | INT | 51–1024 | — |
| controlnet_scale | FLOAT | 0.80–1 | — |
| width | INT | 768256–2048 | — |
| height | INT | 768256–2048 | — |
| batch_size | INT | 11–100 | — |
| drop_grounding_tokens | BOOLEAN | false | — |
| guidance_list | STRING | 0., 0.25, 0.4, 0.75;0.6, 0.25, 1., 0.75 | — |
| control_imageopt | IMAGE | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |