ComfyUI_TiledKSampler icon indicating copy to clipboard operation
ComfyUI_TiledKSampler copied to clipboard

Flux support

Open Kruchemundo opened this issue 1 year ago • 4 comments

Hello There, I really like this node, specially effects that can be created with big denoise and random strict with different prompts. But this can't be done with Flux. Do you have plans to make it work for this model? Thank you for your time.

Kruchemundo avatar Aug 18 '24 15:08 Kruchemundo

Have been trying to get this to work with Flux without success yet, I've slashed nearly everything in the code trying to narrow down the issue. Even when no tiling happen at all the denoising appears to go wrong in a weird way. Could be that some parameters (cfg? guidance?) are not sent properly but it uses the ksampler and model obj from comfyui backend so I don't see what is wrong with it.

ntrouve-onera avatar Nov 30 '24 17:11 ntrouve-onera

update : This can work with flux but need a workaround. The problem lies within the noise generation (denoising works fine). The noise added by the node is wrong.

You can work around by using an AdvancedKSampler to add the noise then send the noised latents to the AdvantedTiledKSampler as a "Refiner" with the added noise option = 0. The only problem with this workaround is the the AdvancedKSampler won't add noise for 0 iterations so you need to do at least one iteration with the regular Ksampler (which can be ok if you have enough VRAM because it won't destroy the image) but if will be a problem on lowvram/big images.

The addnoise node (#beta tagged currently on comfyui) doesn't work either it seems to suffer from the same issue as the TiledKsampler node does.

ntrouve-onera avatar Dec 02 '24 09:12 ntrouve-onera

I figure out a workaround. In nodes.py, just update the origional

tile_result = sampler.sample(tile_noise, pos, neg, cfg=cfg, latent_image=tiled_latent, start_step=start_at_step + i * tile_steps, last_step=start_at_step + i*tile_steps + tile_steps, force_full_denoise=force_full_denoise and i+1 == end_at_step - start_at_step, denoise_mask=tiled_mask, callback=callback, disable_pbar=True, seed=noise_seed)

into

if current_step[0] != start_at_step:
    curr_noise = torch.zeros_like(tiled_latent)
else:
    curr_noise = tiled_noise
tile_result = sampler.sample(curr_noise, pos, neg, cfg=cfg, latent_image=tiled_latent, start_step=start_at_step + i * tile_steps, last_step=start_at_step + i*tile_steps + tile_steps, force_full_denoise=force_full_denoise and i+1 == end_at_step - start_at_step, denoise_mask=tiled_mask, callback=callback, disable_pbar=True, seed=noise_seed)

Besides, modify the

tiled_noise = torch.zeros_like(tiled_latent)

into

tiled_noise = tiling.get_slice(noise, tile_h, tile_h_len, tile_w, tile_w_len).to(device)

Then, it can work with Flux using simple and padded tiling strategy.

ybbbbt avatar Mar 05 '25 03:03 ybbbbt

@ybbbbt How to use it in Flux, can you submit a PR to update it?


custom_nodes\ComfyUI_TiledKSampler\tiling.py", line 29, in set_slice
    tensor1[:,:,h:h+h_len,w:w+w_len] = tensor2
    ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: The expanded size of the tensor (51) must match the existing size (9) at non-singleton dimension 3.  Target sizes: [1, 16, 9, 51, 51].  Tensor sizes: [16, 9, 9, 51]


juntaosun avatar Mar 06 '25 08:03 juntaosun