Nodes/ComfyUi-MpiNodes/Mpi Round To Multiple
ComfyUI Node

Mpi Round To Multiple

Snap a stray number to a resolution your model accepts

By MadPonyInteractive·Created 11 months ago·Updated 5 days ago· 3
Mpi Round To Multiple
    • rounded_value
    value1024
    multiple_of64
    roundfalse

    Diffusion models are picky about resolution. SD and SDXL want dimensions divisible by 8, Flux by 16 or so, video models by 32 - and a dimension that doesn't divide cleanly either throws, silently shifts the image, or wastes the sampler's time. MpiRoundToMultiple is the three-widget answer to that: you hand it a number and it snaps it to the nearest multiple of a base. value in, rounded_value out.

    You reach for this constantly in real workflows - after a resize, after reading an image's dimensions, any time a number that must be divisible by something flows into a resolution slot. It's the kind of boring math node that doesn't feel important until a workflow fails on a 1026×768 you absolutely did not intend to type.

    How it works

    Straightforward floor/ceil arithmetic, and this is where you need to read the label on the boolean:

    • multiple_of is the base (default 64, range 1–1024).
    • round is labelled up when checked and down when not - it's a floor/ceil choice, not "round to nearest". Default is down.

    So with value = 1000, multiple_of = 64, unchecking round floors to 960, checking it ceilings to 1024. There's no "nearest" mode; if you want closest, you pick the direction that errs on the side you can live with. When sizing for a model, rounding down keeps you inside the model's supported resolution (a 1000 → 960 won't overflow a 1024 cap), while rounding up is what you want when you need to fill the frame and don't want a ragged edge.

    One defensive detail in the source: if multiple_of is 0 it returns the value unchanged rather than dividing by zero. You can't even set 0 through the widget (min is 1), so that's just the function being polite.

    Install

    Part of the ComfyUi-MpiNodes pack. Install via ComfyUI Manager (search "MpiNodes" or publisher "mad-pony-interactive"), or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/MadPonyInteractive/ComfyUi-MpiNodes
    

    then restart ComfyUI. No dependencies, no models.

    Where people get burned

    The round semantics. Everyone assumes "round" means nearest, but the widget's label is literally "up"/"down" - floor/ceil. If you're feeding this into a video model's resolution and you let it floor, expect a slightly under-size frame that the model then pads; if you ceil, expect it to crop or squeeze. Neither is wrong, but picking one without knowing which you picked is how you get inconsistent results. Also worth knowing: this handles one number. The moment you're rounding both width and height, its sibling MpiRoundToMultipleRes does both sides in one node - feed this one's output into that one's multiple_of only if you enjoy extra nodes.

    CategoryMpiNodes/Logic

    Inputs (3)

    NameTypeDefaultDescription
    valueINT10240–18446744073709550000
    multiple_ofINT641–1024
    roundBOOLEANfalse

    Outputs (1)

    NameTypeDescription
    rounded_valueINT