CompVis / latent-diffusion

High-Resolution Image Synthesis with Latent Diffusion Models
MIT License
11.85k stars 1.53k forks source link

Errors when attempting to generate image using torch `cpu()` #118

Open salamanders opened 2 years ago

salamanders commented 2 years ago

I'm attempting to run the demo on a machine that doesn't have a CUDA compatible GPU. I got as far as the sample command:

python scripts/txt2img.py --prompt "a virus monster is playing guitar, oil on canvas" --ddim_eta 0.0 --n_samples 4 --n_iter 4 --scale 5.0 --ddim_steps 50

I noticed that at this location, it only uses model.cuda() but later in the file has

device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
model = model.to(device)

Is this intentional, or can the demo be run on a CPU-only output?

salamanders commented 2 years ago

Error log even when attempting to use the model.to in the first call:

(ldm) USERNAME@YELLOW:/mnt/FAST/latent-diffusion$ python scripts/txt2img.py --prompt "a virus monster is playing guitar, oil on canvas" --ddim_eta 0.0 --n_samples 4 --n_iter 4 --scale 5.0  --ddim_steps 50
Loading model from models/ldm/text2img-large/model.ckpt
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 872.30 M params.
making attention of type 'vanilla' with 512 in_channels
Working with z of shape (1, 4, 32, 32) = 4096 dimensions.
making attention of type 'vanilla' with 512 in_channels
Traceback (most recent call last):
  File "scripts/txt2img.py", line 136, in <module>
    uc = model.get_learned_conditioning(opt.n_samples * [""])
  File "/mnt/FAST/latent-diffusion/ldm/models/diffusion/ddpm.py", line 554, in get_learned_conditioning
    c = self.cond_stage_model.encode(c)
  File "/mnt/FAST/latent-diffusion/ldm/modules/encoders/modules.py", line 103, in encode
    return self(text)
  File "/home/USERNAME/miniconda3/envs/ldm/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl
    return forward_call(*input, **kwargs)
  File "/mnt/FAST/latent-diffusion/ldm/modules/encoders/modules.py", line 95, in forward
    tokens = self.tknz_fn(text)#.to(self.device)
  File "/home/USERNAME/miniconda3/envs/ldm/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl
    return forward_call(*input, **kwargs)
  File "/mnt/FAST/latent-diffusion/ldm/modules/encoders/modules.py", line 66, in forward
    tokens = batch_encoding["input_ids"].to(self.device)
  File "/home/USERNAME/miniconda3/envs/ldm/lib/python3.8/site-packages/torch/cuda/__init__.py", line 217, in _lazy_init
    torch._C._cuda_init()
RuntimeError: No CUDA GPUs are available
salamanders commented 2 years ago

export CUDA_VISIBLE_DEVICES=0 - same error.

salamanders commented 2 years ago

Sounds like I'm not the first, found https://github.com/crowsonkb/latent-diffusion/pull/1#issuecomment-1090810668