Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import torchaudio
|
3 |
from einops import rearrange
|
4 |
import gradio as gr
|
5 |
-
import spaces
|
6 |
-
import os
|
7 |
-
import uuid
|
8 |
|
9 |
# Importing the model-related functions
|
10 |
from stable_audio_tools import get_pretrained_model
|
@@ -18,7 +43,7 @@ def load_model():
|
|
18 |
return model, model_config
|
19 |
|
20 |
# Function to set up, generate, and process the audio
|
21 |
-
@spaces.GPU(duration=
|
22 |
def generate_audio(prompt, seconds_total=30, steps=100, cfg_scale=7):
|
23 |
print(f"Prompt received: {prompt}")
|
24 |
print(f"Settings: Duration={seconds_total}s, Steps={steps}, CFG Scale={cfg_scale}")
|
@@ -37,7 +62,7 @@ def generate_audio(prompt, seconds_total=30, steps=100, cfg_scale=7):
|
|
37 |
|
38 |
print(f"Sample rate: {sample_rate}, Sample size: {sample_size}")
|
39 |
|
40 |
-
model = model.to(device)
|
41 |
print("Model moved to device.")
|
42 |
|
43 |
# Set up text and timing conditioning
|
|
|
1 |
+
|
2 |
+
import spaces
|
3 |
+
import os
|
4 |
+
import uuid
|
5 |
+
|
6 |
+
os.putenv('PYTORCH_NVML_BASED_CUDA_CHECK','1')
|
7 |
+
os.putenv('TORCH_LINALG_PREFER_CUSOLVER','1')
|
8 |
+
alloc_conf_parts = [
|
9 |
+
'expandable_segments:True',
|
10 |
+
'pinned_use_background_threads:True' # Specific to pinned memory.
|
11 |
+
]
|
12 |
+
os.environ['PYTORCH_CUDA_ALLOC_CONF'] = ','.join(alloc_conf_parts)
|
13 |
+
os.environ["SAFETENSORS_FAST_GPU"] = "1"
|
14 |
+
os.putenv('HF_HUB_ENABLE_HF_TRANSFER','1')
|
15 |
+
|
16 |
import torch
|
17 |
+
|
18 |
+
|
19 |
+
torch.backends.cuda.matmul.allow_tf32 = False
|
20 |
+
torch.backends.cuda.matmul.allow_bf16_reduced_precision_reduction = False
|
21 |
+
torch.backends.cuda.matmul.allow_fp16_reduced_precision_reduction = False
|
22 |
+
torch.backends.cudnn.allow_tf32 = False
|
23 |
+
torch.backends.cudnn.deterministic = False
|
24 |
+
torch.backends.cudnn.benchmark = False
|
25 |
+
torch.backends.cuda.preferred_blas_library="cublas"
|
26 |
+
torch.backends.cuda.preferred_linalg_library="cusolver"
|
27 |
+
torch.set_float32_matmul_precision("highest")
|
28 |
+
|
29 |
+
|
30 |
import torchaudio
|
31 |
from einops import rearrange
|
32 |
import gradio as gr
|
|
|
|
|
|
|
33 |
|
34 |
# Importing the model-related functions
|
35 |
from stable_audio_tools import get_pretrained_model
|
|
|
43 |
return model, model_config
|
44 |
|
45 |
# Function to set up, generate, and process the audio
|
46 |
+
@spaces.GPU(duration=60) # Allocate GPU only when this function is called
|
47 |
def generate_audio(prompt, seconds_total=30, steps=100, cfg_scale=7):
|
48 |
print(f"Prompt received: {prompt}")
|
49 |
print(f"Settings: Duration={seconds_total}s, Steps={steps}, CFG Scale={cfg_scale}")
|
|
|
62 |
|
63 |
print(f"Sample rate: {sample_rate}, Sample size: {sample_size}")
|
64 |
|
65 |
+
model = model.to(device,torch.bfloat16)
|
66 |
print("Model moved to device.")
|
67 |
|
68 |
# Set up text and timing conditioning
|