Comfy-Org / Comfy-Org/ComfyUI

Performance degradation when loading loras

Open
#5,696 0 comments 0 reactions 0 assignees View on GitHub
Potential Bug
Dominant language
Python
Stars
133k
Forks
15.7k
Avg merge
1d 6h
Merged PRs (30d)
155

Description

### Expected Behavior

n/a

### Actual Behavior

n/a

### Steps to Reproduce

- Use the default workflow and add some `Load LoRA` node to it.
- Monitor CPU usage and execution time.

### Debug Logs

```powershell
n/a
```

### Other

Recently I found a increase in CPU usage when loading lora, especially when applying three or more loras.
After some `git bisect` debugging I'm sure the reason is this [commit 67158994a4356d0ec54aaf3bbc5619c6c119f540](https://github.com/comfyanonymous/ComfyUI/commit/67158994a4356d0ec54aaf3bbc5619c6c119f540)

Before
![image](https://github.com/user-attachments/assets/30d8d0bb-e2a0-4bec-976c-dd9831a5a773)

After, with same workload
![image](https://github.com/user-attachments/assets/d6732f28-2392-4747-bfbd-29c3889b67ea)

Tracing result shows a lot of cpu seconds are consumed by this line
https://github.com/comfyanonymous/ComfyUI/blob/67158994a4356d0ec54aaf3bbc5619c6c119f540/comfy/model_management.py#L851

and before this commit, the `cast_to_device` function was basically calling `Tensor.to()` which I think will be faster than the `copy_` method.

This regression significantly affects workloads with multiple LoRAs, especially on systems where CPU resources are already constrained.

Edit: I'm using `--gpu-only` option, just in case it's related

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.