harp-dev commited on
Commit
b6ff557
·
verified ·
1 Parent(s): bbac552

Select the device rather than hard-coding CUDA

Browse files
Files changed (1) hide show
  1. stable_audio_runtime.py +7 -1
stable_audio_runtime.py CHANGED
@@ -6,6 +6,7 @@ import sys
6
  import tempfile
7
  import threading
8
  from pathlib import Path
 
9
 
10
  MODEL_REPO = "stabilityai/stable-audio-3-small-music"
11
  MODEL_REVISION = "0fef1392cd842149a2b6d445e181c97608faac06"
@@ -72,7 +73,12 @@ def _load_model():
72
  finally:
73
  pretrained.hf_hub_download = original_download
74
 
75
- model = model.to("cuda").to(torch.float16)
 
 
 
 
 
76
  model.eval().requires_grad_(False)
77
  _MODEL = model
78
  _MODEL_CONFIG = config
 
6
  import tempfile
7
  import threading
8
  from pathlib import Path
9
+ import torch
10
 
11
  MODEL_REPO = "stabilityai/stable-audio-3-small-music"
12
  MODEL_REVISION = "0fef1392cd842149a2b6d445e181c97608faac06"
 
73
  finally:
74
  pretrained.hf_hub_download = original_download
75
 
76
+ device = "cuda" if torch.cuda.is_available() else "cpu"
77
+ model = model.to(device)
78
+ if device == "cuda":
79
+ # Half precision is a GPU optimization, and CPU kernels for
80
+ # float16 are either missing or slower than float32
81
+ model = model.to(torch.float16)
82
  model.eval().requires_grad_(False)
83
  _MODEL = model
84
  _MODEL_CONFIG = config