kohya-ss / kohya-ss/sd-scripts

⛔[SD3 branch] Huber+SNR RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!

Open
#2,102 13 comments 2 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
7.2k
Forks
1.2k
Avg merge
11m
Merged PRs (30d)
2

Description

Pytorch 2.7.0, CUDA 12.8

What: RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! when using Huber + SNR

Where: train_util.py, line 6025

Fix:

From
`alphas_cumprod = torch.index_select(noise_scheduler.alphas_cumprod, 0, timesteps.cpu())
`
To
`alphas_cumprod = torch.index_select(noise_scheduler.alphas_cumprod, 0, timesteps.to(noise_scheduler.alphas_cumprod.device))
`

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at train_util.py line 6025 and reproduce the Huber + SNR path with PyTorch 2.7.0 and CUDA 12.8. Check the tensor devices used by the alphas_cumprod lookup, then verify that the RuntimeError no longer occurs when the lookup indices and source tensor use the same device.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.