Skip to content
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

Use on Directml, "torch.median()" problem. #10

Open
MythicalChu opened this issue Mar 2, 2024 · 1 comment
Open

Use on Directml, "torch.median()" problem. #10

MythicalChu opened this issue Mar 2, 2024 · 1 comment

Comments

@MythicalChu
Copy link

I was having an error on the line 'y = y.clip(0, 1).movedim(1, -1)' stating that there was only 1 dimension and expected [-1,0], so I tracked the problem with prints and eventually discovered that:

on \lib_layerdiffusion\models.py, line 236-237,

result = torch.stack(result, dim=0)
returned a normal tensor as it should, but the next line:

median = torch.median(result, dim=0).values
returned an empty tensor. Even assigning torch.median(result, dim=0) to a var and pulling the .values later didn't work.

So, it seems torch.median doesn't work on Directml. I managed to circle around the problem by:

result = torch.stack(result, dim=0).to("cpu")
and then casting it back right after:

return median.to(self.load_device)

This fixes the problem for Directml users and it didn't seem to effect performance. I'm not entirely sure if the problem is really for all Direcml users, let's see if anyone else complains too.

@MythicalChu MythicalChu changed the title Use on Directml, "torch.mean()" problem. Use on Directml, "torch.median()" problem. Mar 2, 2024
@KungFuFurniture
Copy link

I was having an error on the line 'y = y.clip(0, 1).movedim(1, -1)' stating that there was only 1 dimension and expected [-1,0], so I tracked the problem with prints and eventually discovered that:

on \lib_layerdiffusion\models.py, line 236-237,

result = torch.stack(result, dim=0) returned a normal tensor as it should, but the next line:

median = torch.median(result, dim=0).values returned an empty tensor. Even assigning torch.median(result, dim=0) to a var and pulling the .values later didn't work.

So, it seems torch.median doesn't work on Directml. I managed to circle around the problem by:

result = torch.stack(result, dim=0).to("cpu") and then casting it back right after:

return median.to(self.load_device)

This fixes the problem for Directml users and it didn't seem to effect performance. I'm not entirely sure if the problem is really for all Direcml users, let's see if anyone else complains too.

Excellent. This fixed it for me. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants