File size: 1,253 Bytes
ac2764c 9ac1f4d ac2764c 271afe2 ac2764c 4e1ae22 ac2764c 9ac1f4d ac2764c 271afe2 ac2764c 4e1ae22 ac2764c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
## FP32
```python
# !pip install git+https://github.com/huggingface/diffusers.git
from diffusers import DiffusionPipeline
import scipy
model_id = "harmonai/maestro-150k"
pipeline = DiffusionPipeline.from_pretrained(model_id)
pipeline = pipeline.to("cuda")
audios = pipeline(audio_length_in_s=4.0).audios
# To save locally
for audio in audios:
scipy.io.wavfile.write("maestro_test.wav", pipe.unet.sample_rate, audio.transpose())
# To dislay in google colab
import IPython.display as ipd
for audio in audios:
display(ipd.Audio(audio[0, 1:], rate=pipe.unet.sample_rate))
```
## FP16
Faster at a small loss of quality
```python
# !pip install git+https://github.com/huggingface/diffusers.git
from diffusers import DiffusionPipeline
import scipy
import torch
model_id = "harmonai/maestro-150k"
pipeline = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
pipeline = pipeline.to("cuda")
audios = pipeline(audio_length_in_s=4.0).audios
# To save locally
for audio in audios:
scipy.io.wavfile.write("maestro_test.wav", pipe.unet.sample_rate, audio.transpose())
# To dislay in google colab
import IPython.display as ipd
for audio in audios:
display(ipd.Audio(audio[0, 1:], rate=pipe.unet.sample_rate))
``` |