Instructions to use facebook/musicgen-stereo-medium with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use facebook/musicgen-stereo-medium with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-to-audio", model="facebook/musicgen-stereo-medium")# Load model directly from transformers import AutoProcessor, AutoModelForTextToWaveform processor = AutoProcessor.from_pretrained("facebook/musicgen-stereo-medium") model = AutoModelForTextToWaveform.from_pretrained("facebook/musicgen-stereo-medium", device_map="auto") - Audiocraft
How to use facebook/musicgen-stereo-medium with Audiocraft:
from audiocraft.models import MusicGen model = MusicGen.get_pretrained("facebook/musicgen-stereo-medium") descriptions = ['happy rock', 'energetic EDM', 'sad jazz'] wav = model.generate(descriptions) # generates 3 samples. - Notebooks
- Google Colab
- Kaggle
Update README.md
#4
by reach-vb - opened
README.md
CHANGED
|
@@ -63,22 +63,23 @@ Try out MusicGen yourself!
|
|
| 63 |
|
| 64 |
## 🤗 Transformers Usage
|
| 65 |
|
| 66 |
-
You can run MusicGen locally with the 🤗 Transformers library from
|
| 67 |
|
| 68 |
1. First install the 🤗 [Transformers library](https://github.com/huggingface/transformers) and scipy:
|
| 69 |
|
| 70 |
```
|
| 71 |
pip install --upgrade pip
|
| 72 |
-
pip install --upgrade transformers scipy
|
| 73 |
```
|
| 74 |
|
| 75 |
2. Run inference via the `Text-to-Audio` (TTA) pipeline. You can infer the MusicGen model via the TTA pipeline in just a few lines of code!
|
| 76 |
|
| 77 |
```python
|
| 78 |
-
from transformers import pipeline
|
| 79 |
import scipy
|
|
|
|
|
|
|
| 80 |
|
| 81 |
-
synthesiser = pipeline("text-to-audio", "facebook/musicgen-stereo-medium")
|
| 82 |
|
| 83 |
music = synthesiser("lo-fi music with a soothing melody", forward_params={"do_sample": True})
|
| 84 |
|
|
@@ -91,13 +92,13 @@ scipy.io.wavfile.write("musicgen_out.wav", rate=music["sampling_rate"], music=au
|
|
| 91 |
from transformers import AutoProcessor, MusicgenForConditionalGeneration
|
| 92 |
|
| 93 |
processor = AutoProcessor.from_pretrained("facebook/musicgen-stereo-medium")
|
| 94 |
-
model = MusicgenForConditionalGeneration.from_pretrained("facebook/musicgen-stereo-medium")
|
| 95 |
|
| 96 |
inputs = processor(
|
| 97 |
text=["80s pop track with bassy drums and synth", "90s rock song with loud guitars and heavy drums"],
|
| 98 |
padding=True,
|
| 99 |
return_tensors="pt",
|
| 100 |
-
)
|
| 101 |
|
| 102 |
audio_values = model.generate(**inputs, max_new_tokens=256)
|
| 103 |
```
|
|
|
|
| 63 |
|
| 64 |
## 🤗 Transformers Usage
|
| 65 |
|
| 66 |
+
You can run MusicGen Stereo models locally with the 🤗 Transformers library from `main` onward.
|
| 67 |
|
| 68 |
1. First install the 🤗 [Transformers library](https://github.com/huggingface/transformers) and scipy:
|
| 69 |
|
| 70 |
```
|
| 71 |
pip install --upgrade pip
|
| 72 |
+
pip install --upgrade git+https://github.com/huggingface/transformers.git scipy
|
| 73 |
```
|
| 74 |
|
| 75 |
2. Run inference via the `Text-to-Audio` (TTA) pipeline. You can infer the MusicGen model via the TTA pipeline in just a few lines of code!
|
| 76 |
|
| 77 |
```python
|
|
|
|
| 78 |
import scipy
|
| 79 |
+
import torch
|
| 80 |
+
from transformers import pipeline
|
| 81 |
|
| 82 |
+
synthesiser = pipeline("text-to-audio", "facebook/musicgen-stereo-medium", torch_dtype=torch.float16, device="cuda")
|
| 83 |
|
| 84 |
music = synthesiser("lo-fi music with a soothing melody", forward_params={"do_sample": True})
|
| 85 |
|
|
|
|
| 92 |
from transformers import AutoProcessor, MusicgenForConditionalGeneration
|
| 93 |
|
| 94 |
processor = AutoProcessor.from_pretrained("facebook/musicgen-stereo-medium")
|
| 95 |
+
model = MusicgenForConditionalGeneration.from_pretrained("facebook/musicgen-stereo-medium").to("cuda")
|
| 96 |
|
| 97 |
inputs = processor(
|
| 98 |
text=["80s pop track with bassy drums and synth", "90s rock song with loud guitars and heavy drums"],
|
| 99 |
padding=True,
|
| 100 |
return_tensors="pt",
|
| 101 |
+
).to("cuda")
|
| 102 |
|
| 103 |
audio_values = model.generate(**inputs, max_new_tokens=256)
|
| 104 |
```
|