lllyasviel / lllyasviel/sd-forge-layerdiffuse

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

Open
#10 1 comment 2 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.