Spaces:
Running on Zero
Running on Zero
Load on the CPU in the background and move to the GPU inside process_fn.
Browse files
app.py
CHANGED
|
@@ -46,17 +46,13 @@ def load_model():
|
|
| 46 |
vocoder_checkpoint_path = os.path.join(model_dir, "pretrained/vocoder")
|
| 47 |
|
| 48 |
print("Initializing AnyAccomp InferencePipeline...", flush=True)
|
| 49 |
-
#
|
| 50 |
-
#
|
| 51 |
-
# CPU and the modules move afterwards
|
| 52 |
pipeline = Sing2SongInferencePipeline(
|
| 53 |
checkpoint_path, cfg_path,
|
| 54 |
vocoder_checkpoint_path, vocoder_cfg_path,
|
| 55 |
device="cpu",
|
| 56 |
)
|
| 57 |
-
for module in (pipeline.model, pipeline.coco_model, pipeline.vocoder):
|
| 58 |
-
module.to(DEVICE)
|
| 59 |
-
pipeline.device = DEVICE
|
| 60 |
pipeline.sample_rate = 24000
|
| 61 |
inference_pipeline = pipeline
|
| 62 |
print("Model loaded successfully.", flush=True)
|
|
@@ -104,6 +100,11 @@ def process_fn(vocal_filepath, n_timesteps): # add , cfg_scale to re-enable
|
|
| 104 |
if inference_pipeline is None:
|
| 105 |
raise gr.Error(f"Model failed to load: {model_error}")
|
| 106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
if vocal_filepath is None:
|
| 108 |
raise gr.Error("Please upload a vocal audio file.")
|
| 109 |
|
|
|
|
| 46 |
vocoder_checkpoint_path = os.path.join(model_dir, "pretrained/vocoder")
|
| 47 |
|
| 48 |
print("Initializing AnyAccomp InferencePipeline...", flush=True)
|
| 49 |
+
# ZeroGPU does not intercept CUDA calls made from a background thread, so
|
| 50 |
+
# the pipeline loads on the CPU here and process_fn moves it to the GPU
|
|
|
|
| 51 |
pipeline = Sing2SongInferencePipeline(
|
| 52 |
checkpoint_path, cfg_path,
|
| 53 |
vocoder_checkpoint_path, vocoder_cfg_path,
|
| 54 |
device="cpu",
|
| 55 |
)
|
|
|
|
|
|
|
|
|
|
| 56 |
pipeline.sample_rate = 24000
|
| 57 |
inference_pipeline = pipeline
|
| 58 |
print("Model loaded successfully.", flush=True)
|
|
|
|
| 100 |
if inference_pipeline is None:
|
| 101 |
raise gr.Error(f"Model failed to load: {model_error}")
|
| 102 |
|
| 103 |
+
pipeline = inference_pipeline
|
| 104 |
+
for module in (pipeline.model, pipeline.coco_model, pipeline.vocoder):
|
| 105 |
+
module.to(DEVICE)
|
| 106 |
+
inference_pipeline.device = DEVICE
|
| 107 |
+
|
| 108 |
if vocal_filepath is None:
|
| 109 |
raise gr.Error("Please upload a vocal audio file.")
|
| 110 |
|