BlenderNeko / ComfyUI_TiledKSampler

Tiled samplers for ComfyUI
GNU General Public License v3.0
297 stars 17 forks source link

Fix handling of conditioning masks #40

Open keilladraconis opened 4 months ago

keilladraconis commented 4 months ago

Allow me to preface: I don't know a thing about PyTorch, Diffusion, Arrays, Tensors, or any of this nonsense. I'm just a girl who wants to mask and tile. 😷

First problem. In slice_cond the branches that handle areas expect cond to be a tuple. cond is not a tuple. Removed the indexing which clears the error in #36

Second problem, the tensor is not the size the sampler expects it to be later on in the process. I did a lots of debugger and eventually glazed that mask tensors are 3-dimensional with no color information, while other tensors are 4-dimensional. But some functions here are turning a nice mask tensor into a full-color tensor.

See, comfy.sample.prepare_mask fluffs up the tensor from a typical mask tensor of mask X x-pos X y-pos to a mask X rgba X x-pos X y-pos size. Not a problem for a while until it is.

So I lifted that function and did a little squeeze to remove the baby dimension that gets injected when the reshape interpolates the tensor into the size which interpolate can handle (for whatever reason it requires a 4-dimensional array or it dies (pytorch is a dumpster fire of raccoons who are also on fire)).

Is this correct? I don't know. Is it right? Who knows. Does it stop the crashes when your condies have maskeys? Yes. It stops those.

Someone with maths please just take this PR and make it beautiful. And write some tests.

Also I don't know squat about Python.