Nodes/Bobs_Latent_Optimizer/Bobs Latent Optimizer (Advanced)
ComfyUI Node

Bobs Latent Optimizer (Advanced)

A continuous-megapixel latent, with tiles

By BobsBlazed·Created 2 years ago·Updated about a month ago· 54
Bobs Latent Optimizer (Advanced)
    • latent
    • tile_width
    • tile_height
    • upscale_by
    • width
    • height
    aspect_ratio1:1
    mp_size_float1.00
    upscale_by2.00
    model_typeFLUX
    batch_size1
    max_tile_size2048
    length1

    The standard BobsLatentNode gives you a nice dropdown of megapixel presets - 1, 1.5, 2, all the usual suspects. The Advanced variant exists for the one case where a preset is wrong: you want a specific area that falls between the presets. Instead of a list, it takes a continuous float, mp_size_float, from 0.01 up to 4.0. Type 0.85 if that's the exact area your workflow needs. Same family, same outputs, one different dial - but that dial is the whole point of this node.

    Everything else about the pack applies here: it's a pure sizing utility from BobsBlazed/Bobs_Latent_Optimizer, no API, no key, no model downloads, no Python dependencies beyond what ComfyUI already ships. You swap this in wherever you'd use the standard node but want finer control.

    How it works

    Same engine as the standard node. mp_size_float is your target area in megapixels - and here's the detail that trips people up: the node counts a megapixel as 1024×1024 pixels, not 1,000,000. So 1.0 gives you a 1024×1024 area, 4.0 is a 2048×2048 area. The float is multiplied against that base area, then split into width and height along your aspect_ratio, then rounded to the alignment step for the chosen model_type - 64 for FLUX and the SD-family models, finer for QWEN and the WAN family. The empty latent comes out with the right channel count (16 for FLUX, 4 for SDXL-style) and the correct VAE downscale, so the pixel dimensions are honest about the tensor you're feeding the KSampler.

    The tiling half is identical to the standard node: upscale_by isn't an actual upscale, it's a forward estimate of your final output size. The node derives tile_width and tile_height for the tiled upscaler you run after VAE decode, targeting a 2×2 grid and subdividing further only if a tile would blow past 2048×2048, with tile edges aligned to a multiple of 8. If your upscale stage still OOMs at the default cap, your levers are to shrink mp_size_float or drop upscale_by - the tile grid follows from both.

    The inputs that matter

    • mp_size_float - the reason this node exists. A precise megapixel target; anything between 0.01 and 4.0, defaults to 1.0.
    • aspect_ratio - same as the standard node; 1:1, 16:9, 3:2, decimal forms like 1.5:1 all parse.
    • upscale_by - feeds the tile math only. Set it to the factor you'll actually use downstream.
    • model_type - FLUX, SDXL, SD3, QWEN, or WAN; FLUX default.
    • batch_size - stack multiple latents if you're batching.

    Outputs

    Four: latent into your KSampler, tile_width and tile_height into your tiled upscaler (Ultimate SD Upscale, tiled VAE decode, whatever you use), and upscale_by passed through for nodes that take a scale factor directly. The layout is exactly the standard node's - the only difference is how you express the target size.

    Installing it

    Same pack, same story. Via ComfyUI Manager, search Bobs_Latent_Optimizer and install, or:

    cd ComfyUI/custom_nodes/
    git clone https://github.com/BobsBlazed/Bobs_Latent_Optimizer.git
    

    Restart ComfyUI and both nodes appear under latent/generate - Advanced included. No requirements to pip, no models to fetch.

    Common pitfalls

    • Expecting upscale_by to upscale. It's a hint for tile sizing, not a transformation. Wire a real tiled upscaler after VAE decode if you want the output bigger.
    • Misreading the megapixel. 1 MP here is 1024×1024, so 2.0 is roughly a 1920×1080 area - not two million flat pixels.
    • Overshooting the base latent. A 4.0 MP FLUX latent is a heavy first pass by itself. The tile outputs keep the upscale stage VRAM-friendly; they don't shrink the base generation.

    Reach for the Advanced node when you're matching a resolution another workflow handed you (a LoRA trained at 1536×1536, a video's native size) and the presets just won't land. For everyday 1-MP generation, the standard node does the same job with less typing.

    Categorylatent/generate

    Inputs (7)

    NameTypeDefaultDescription
    aspect_ratioSTRING1:1Aspect ratio of the base image, e.g. '1:1', '16:9', '3:2'.
    mp_size_floatFLOAT1.000.01–16Target area in megapixels, where 1.0 = 1048576 pixels (1024x1024). 4.0 is a 2048x2048 area.
    upscale_byFLOAT2.001–10Upscale factor for the FINAL output image. Used only to compute the tile dimensions; the generated latent is NOT upscaled.
    model_typeCOMBOFLUXModel family. Sets latent channels, VAE downscale and pixel alignment. Video families (WAN, WAN22, HUNYUAN_VIDEO, HUNYUAN_VIDEO_15, COSMOS, COGVIDEOX, MOCHI, LTXV, SEEDVR2, HUNYUAN_IMAGE_REFINER) produce a 5-D latent and use the `length` input. See the README for the full table.
    batch_sizeINT11–64Number of latents in the batch.
    max_tile_sizeoptINT2048256–8192Largest tile edge allowed before the tile grid is subdivided further. Lower this if your upscaler runs out of VRAM.
    lengthoptINT11–4096Number of video frames. Only used by video model families; ignored (with a warning) for image models.

    Outputs (6)

    NameTypeDescription
    latentLATENTEmpty latent batch sized for the selected model.
    tile_widthINTSuggested tile width for a tiled upscaler operating on the upscaled pixel output.
    tile_heightINTSuggested tile height for a tiled upscaler operating on the upscaled pixel output.
    upscale_byFLOATThe upscale factor, passed through unchanged for convenience.
    widthINTBase image width in pixels.
    heightINTBase image height in pixels.