Instructions to use stabilityai/stable-audio-open-1.0 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Stable Audio Tools
How to use stabilityai/stable-audio-open-1.0 with Stable Audio Tools:
import torch import torchaudio from einops import rearrange from stable_audio_tools import get_pretrained_model from stable_audio_tools.inference.generation import generate_diffusion_cond device = "cuda" if torch.cuda.is_available() else "cpu" # Download model model, model_config = get_pretrained_model("stabilityai/stable-audio-open-1.0") sample_rate = model_config["sample_rate"] sample_size = model_config["sample_size"] model = model.to(device) # Set up text and timing conditioning conditioning = [{ "prompt": "128 BPM tech house drum loop", }] # Generate stereo audio output = generate_diffusion_cond( model, conditioning=conditioning, sample_size=sample_size, device=device ) # Rearrange audio batch to a single sequence output = rearrange(output, "b d n -> d (b n)") # Peak normalize, clip, convert to int16, and save to file output = output.to(torch.float32).div(torch.max(torch.abs(output))).clamp(-1, 1).mul(32767).to(torch.int16).cpu() torchaudio.save("output.wav", output, sample_rate) - Notebooks
- Google Colab
- Kaggle
model = model.to(device) gives me problems
Sorry so noob, I been on this few hours:
This part of the code from model card is giving me hassles:
model = model.to(device)
AttributeError: 'dict' object has no attribute 'to'
Claude Opus tells me :
In the official documentation, the line model = model.to(device) assumes that model is a PyTorch model object, which has the to method to move the model to the specified device (CPU or GPU). However, in your case, the loaded checkpoint seems to contain a dictionary.
To resolve this issue, you need to extract the actual model object from the loaded dictionary. Based on the provided model configuration, it appears that the model is a conditional diffusion model.
Here's an updated version of the code that should work:
model.eval()
model = model.to(device)
model.eval()
AttributeError: 'dict' object has no attribute 'eval'
Remove the spaces and run on local using your hf_token
https://huggingface.co/spaces/ameerazam08/stableaudio-open-1.0
OK thank you, will try it out.