Skip to content

Fix MPS tensor contiguity issue in tiled_scale_multidim for arbitrary image sizes #8352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions comfy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,7 @@ def get_tiled_scale_steps(width, height, tile_x, tile_y, overlap):
@torch.inference_mode()
def tiled_scale_multidim(samples, function, tile=(64, 64), overlap=8, upscale_amount=4, out_channels=3, output_device="cpu", downscale=False, index_formulas=None, pbar=None):
dims = len(tile)
samples = samples.contiguous() # Ensure input tensor is contiguous

if not (isinstance(upscale_amount, (tuple, list))):
upscale_amount = [upscale_amount] * dims
Expand Down Expand Up @@ -936,7 +937,7 @@ def mult_list_upscale(a):

# handle entire input fitting in a single tile
if all(s.shape[d+2] <= tile[d] for d in range(dims)):
output[b:b+1] = function(s).to(output_device)
output[b:b+1] = function(s.contiguous()).to(output_device) # Ensure single tile is contiguous
if pbar is not None:
pbar.update(1)
continue
Expand All @@ -956,7 +957,7 @@ def mult_list_upscale(a):
s_in = s_in.narrow(d + 2, pos, l)
upscaled.append(round(get_pos(d, pos)))

ps = function(s_in).to(output_device)
ps = function(s_in.contiguous()).to(output_device) # Ensure tiled segment is contiguous
mask = torch.ones_like(ps)

for d in range(2, dims + 2):
Expand All @@ -982,7 +983,7 @@ def mult_list_upscale(a):

output[b:b+1] = out/out_div
return output

def tiled_scale(samples, function, tile_x=64, tile_y=64, overlap = 8, upscale_amount = 4, out_channels = 3, output_device="cpu", pbar = None):
return tiled_scale_multidim(samples, function, (tile_y, tile_x), overlap=overlap, upscale_amount=upscale_amount, out_channels=out_channels, output_device=output_device, pbar=pbar)

Expand Down
Loading