Nodes/ComfyUI_MS_Diffusion/MSdiffusion_Sampler
ComfyUI Node

MSdiffusion_Sampler

Brackets, Boxes, and the Sampler That Puts Your Subjects Where You Want Them

By smthemex·Created 2 years ago·Updated 2 years ago· 58
MSdiffusion_Sampler
  • image
  • model
  • control_image
  • image
prompta [dog] wearing a pink sunglass
negative_prompt(worst quality, low quality, normal quality, lowres),
seed0
steps20
cfg7.0
scale0.8
mask_threshold0.5
start_step5
controlnet_scale0.8
width768
height768
batch_size1
drop_grounding_tokensfalse
guidance_list0., 0.25, 0.4, 0.75;0.6, 0.25, 1., 0.75

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 - the MSDIF_DICT from 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 normalized x0, y0, x1, y1 coordinates. The default 0., 0.25, 0.4, 0.75;0.6, 0.25, 1., 0.75 is two boxes for a two-object image (left half, right half). With multiple objects and a nonzero mask_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 optional control_image is 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.

CategoryMSdiffusion

Inputs (17)

NameTypeDefaultDescription
imageIMAGE
modelMSDIF_DICT
promptSTRINGa [dog] wearing a pink sunglass
negative_promptSTRING(worst quality, low quality, normal quality, lowres),
seedINT00–2147483647
stepsINT201–100
cfgFLOAT7.00.1–10
scaleFLOAT0.80–1
mask_thresholdFLOAT0.50–1
start_stepINT51–1024
controlnet_scaleFLOAT0.80–1
widthINT768256–2048
heightINT768256–2048
batch_sizeINT11–100
drop_grounding_tokensBOOLEANfalse
guidance_listSTRING0., 0.25, 0.4, 0.75;0.6, 0.25, 1., 0.75
control_imageoptIMAGE

Outputs (1)

NameTypeDescription
imageIMAGE