huggingface / huggingface/diffusers

Can we allow making everything on gpu/cuda for scheduler?

Abierto
#9,485 14 comentarios 0 reacciones 2 asignados Reclamado por @a-r-r-o-w Ver en GitHub
performance scheduler stale
Lenguaje dominante
Python
Estrellas
34.5k
Forks
7.3k
Merge medio
3 d 3 h
PR fusionados (30 d)
91

Descripción

**What API design would you like to have changed or added to the library? Why?**
Is it possible to allow setting every tensor attribute of scheduler to cuda device?
In https://github.com/huggingface/diffusers/blob/main/src/diffusers/schedulers/scheduling_lcm.py
It looks like that attributes like `scheduler.alphas_cumprod` are tensors on cpu, but the scheduler.set_timesteps() allows setting `scheduler.timesteps` to gpu/cuda device. Isn't this causing device mismatch when indexing scheduler.alphas_cumprod with scheduler.timesteps? Below is the code snippet that the pipline is indexing a cpu tensor(alphas_cumprod) with a gpu tensor(timestep)
![image](https://github.com/user-attachments/assets/42b31655-0b4f-4623-9524-5d55bf7b7f5c)
I simply added following lines to print the timestep and self.alphas_cumprod type and device at the begining of the `scheduler.step()`
```
print("Printing scheduler.step() timestep")
print(type(timestep))
print(isinstance(timestep, torch.Tensor))
print(timestep.device)
print("Printing scheduler.step() self.alphas_cumprod")
print(type(self.alphas_cumprod))
print(isinstance(self.alphas_cumprod, torch.Tensor))
print(self.alphas_cumprod.device)
```
Output when running text-to-image:
```
Printing scheduler.step() timestep

True
cuda:0
Printing scheduler.step() self.alphas_cumprod

True
cpu
```

**What use case would this enable or better enable? Can you give us a code example?**
We are using a modified LCMScheduler (99% same as the original LCMScheduler) for video generations, it's generating frames repeatedly in a loop. for most of the time, this step doesn't cause performance issue. But we did see intermittent high cpu usage and latency for `alpha_prod_t = self.alphas_cumprod[timestep]`. And from torch.profiler and tracing output, it. shows high latency for this specific step. We are wondering if this is the performance bottleneck.
![image](https://github.com/user-attachments/assets/04f5040b-734c-46a6-8171-17a30f221b14)

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.