lllyasviel / lllyasviel/sd-forge-layerdiffuse
Use on Directml, "torch.median()" problem.
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.1k
- Forks
- 352
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in lib_layerdiffusion/models.py at lines 236-237 and reproduce the torch.median behavior on DirectML. Compare the stacked tensor and median result on DirectML and CPU, then verify that the selected device is preserved afterward. Done means the affected path no longer produces an empty tensor for DirectML users.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100