12 Jukebox
In [ ]:
!nvidia-smi -LGPU 0: Tesla P100-PCIE-16GB (UUID: GPU-b5edb265-6667-6ca9-3c2c-ca0858b7cc5e)
In [ ]:
!pip install git+https://github.com/openai/jukebox.gitLooking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/
Collecting git+https://github.com/openai/jukebox.git
Cloning https://github.com/openai/jukebox.git to /tmp/pip-req-build-4n_g9hoi
Running command git clone -q https://github.com/openai/jukebox.git /tmp/pip-req-build-4n_g9hoi
Collecting fire==0.1.3
Downloading fire-0.1.3.tar.gz (33 kB)
Collecting tqdm==4.45.0
Downloading tqdm-4.45.0-py2.py3-none-any.whl (60 kB)
|████████████████████████████████| 60 kB 6.3 MB/s
[?25hCollecting soundfile==0.10.3.post1
Downloading SoundFile-0.10.3.post1-py2.py3-none-any.whl (21 kB)
Collecting unidecode==1.1.1
Downloading Unidecode-1.1.1-py2.py3-none-any.whl (238 kB)
|████████████████████████████████| 238 kB 44.8 MB/s
[?25hCollecting numba==0.48.0
Downloading numba-0.48.0-1-cp37-cp37m-manylinux2014_x86_64.whl (3.5 MB)
|████████████████████████████████| 3.5 MB 56.0 MB/s
[?25hCollecting librosa==0.7.2
Downloading librosa-0.7.2.tar.gz (1.6 MB)
|████████████████████████████████| 1.6 MB 54.1 MB/s
[?25hCollecting mpi4py>=3.0.0
Downloading mpi4py-3.1.4.tar.gz (2.5 MB)
|████████████████████████████████| 2.5 MB 34.4 MB/s
[?25h Installing build dependencies ... [?25l[?25hdone
Getting requirements to build wheel ... [?25l[?25hdone
Preparing wheel metadata ... [?25l[?25hdone
Requirement already satisfied: six in /usr/local/lib/python3.7/dist-packages (from fire==0.1.3->jukebox==1.0) (1.15.0)
Requirement already satisfied: audioread>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from librosa==0.7.2->jukebox==1.0) (3.0.0)
Requirement already satisfied: numpy>=1.15.0 in /usr/local/lib/python3.7/dist-packages (from librosa==0.7.2->jukebox==1.0) (1.21.6)
Requirement already satisfied: scipy>=1.0.0 in /usr/local/lib/python3.7/dist-packages (from librosa==0.7.2->jukebox==1.0) (1.7.3)
Requirement already satisfied: scikit-learn!=0.19.0,>=0.14.0 in /usr/local/lib/python3.7/dist-packages (from librosa==0.7.2->jukebox==1.0) (1.0.2)
Requirement already satisfied: joblib>=0.12 in /usr/local/lib/python3.7/dist-packages (from librosa==0.7.2->jukebox==1.0) (1.2.0)
Requirement already satisfied: decorator>=3.0.0 in /usr/local/lib/python3.7/dist-packages (from librosa==0.7.2->jukebox==1.0) (4.4.2)
Requirement already satisfied: resampy>=0.2.2 in /usr/local/lib/python3.7/dist-packages (from librosa==0.7.2->jukebox==1.0) (0.4.2)
Collecting llvmlite<0.32.0,>=0.31.0dev0
Downloading llvmlite-0.31.0-cp37-cp37m-manylinux1_x86_64.whl (20.2 MB)
|████████████████████████████████| 20.2 MB 35.6 MB/s
[?25hRequirement already satisfied: setuptools in /usr/local/lib/python3.7/dist-packages (from numba==0.48.0->jukebox==1.0) (57.4.0)
Requirement already satisfied: cffi>=1.0 in /usr/local/lib/python3.7/dist-packages (from soundfile==0.10.3.post1->jukebox==1.0) (1.15.1)
Requirement already satisfied: pycparser in /usr/local/lib/python3.7/dist-packages (from cffi>=1.0->soundfile==0.10.3.post1->jukebox==1.0) (2.21)
Collecting resampy>=0.2.2
Downloading resampy-0.4.1-py3-none-any.whl (3.1 MB)
|████████████████████████████████| 3.1 MB 34.3 MB/s
[?25h Downloading resampy-0.4.0-py3-none-any.whl (3.1 MB)
|████████████████████████████████| 3.1 MB 46.1 MB/s
[?25h Downloading resampy-0.3.1-py3-none-any.whl (3.1 MB)
|████████████████████████████████| 3.1 MB 37.5 MB/s
[?25hRequirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from scikit-learn!=0.19.0,>=0.14.0->librosa==0.7.2->jukebox==1.0) (3.1.0)
Building wheels for collected packages: jukebox, fire, librosa, mpi4py
Building wheel for jukebox (setup.py) ... [?25l[?25hdone
Created wheel for jukebox: filename=jukebox-1.0-py3-none-any.whl size=197916 sha256=4b1307793db96c869c455db5c2edbb9077cab66ed7a7e10aee6fae93b092285d
Stored in directory: /tmp/pip-ephem-wheel-cache-w84oh8tl/wheels/d6/42/39/91f8a32505a445499702ae0f887769e6bb5030c42382d74ae0
Building wheel for fire (setup.py) ... [?25l[?25hdone
Created wheel for fire: filename=fire-0.1.3-py2.py3-none-any.whl size=49719 sha256=4b69a61292fb9e091d25b957cd1c6b9edf68dab1120acba5821f70dfb56cfd69
Stored in directory: /root/.cache/pip/wheels/dd/c5/df/d9bf8223023d31343b65f1cc57d2dc005610ebbcd2b4a5d1e7
Building wheel for librosa (setup.py) ... [?25l[?25hdone
Created wheel for librosa: filename=librosa-0.7.2-py3-none-any.whl size=1612900 sha256=be0cb6f25da199d49a278883a9a907da0a23fd52f7bece6510ab969db0e61e0b
Stored in directory: /root/.cache/pip/wheels/18/9e/42/3224f85730f92fa2925f0b4fb6ef7f9c5431a64dfc77b95b39
Building wheel for mpi4py (PEP 517) ... [?25l[?25hdone
Created wheel for mpi4py: filename=mpi4py-3.1.4-cp37-cp37m-linux_x86_64.whl size=2185749 sha256=4c838901a689d0a4f773c7700bb671c3ed29f619e25a63d9779f610c193e5ae2
Stored in directory: /root/.cache/pip/wheels/99/54/29/187b5768bbb7beeab6753bc30acf56f35bc8ca9c214a31e173
Successfully built jukebox fire librosa mpi4py
Installing collected packages: llvmlite, numba, soundfile, resampy, unidecode, tqdm, mpi4py, librosa, fire, jukebox
Attempting uninstall: llvmlite
Found existing installation: llvmlite 0.39.1
Uninstalling llvmlite-0.39.1:
Successfully uninstalled llvmlite-0.39.1
Attempting uninstall: numba
Found existing installation: numba 0.56.4
Uninstalling numba-0.56.4:
Successfully uninstalled numba-0.56.4
… [output troncato]In [ ]:
from google.colab import drive
drive.mount('/content/drive')Mounted at /content/drive
In [ ]:
import jukebox
import torch as t
import librosa
import os
from IPython.display import Audio
from jukebox.make_models import make_vqvae, make_prior, MODELS, make_model
from jukebox.hparams import Hyperparams, setup_hparams
from jukebox.sample import sample_single_window, _sample, \
sample_partial_window, upsample, \
load_prompts
from jukebox.utils.dist_utils import setup_dist_from_mpi
from jukebox.utils.torch_utils import empty_cache
rank, local_rank, device = setup_dist_from_mpi()Using cuda True
In [ ]:
model = "5b_lyrics"
hps = Hyperparams()
hps.sr = 44100
hps.n_samples = 3
# cartella di drive in cui salvare i risultati
hps.name = '/content/drive/My Drive/Colab Notebooks/Jukebox/'
chunk_size = 16
max_batch_size = 3
hps.levels = 3
hps.hop_fraction = [.5,.5,.125]
vqvae, *priors = MODELS[model]
vqvae = make_vqvae(setup_hparams(vqvae, dict(sample_length = 1048576)), device)
top_prior = make_prior(setup_hparams(priors[-1], dict()), vqvae, device)
continuation = NoneDownloading from azure Running wget -O /root/.cache/jukebox/models/5b/vqvae.pth.tar https://openaipublic.azureedge.net/jukebox/models/5b/vqvae.pth.tar Restored from /root/.cache/jukebox/models/5b/vqvae.pth.tar 0: Loading vqvae in eval mode Loading artist IDs from /usr/local/lib/python3.7/dist-packages/jukebox/data/ids/v2_artist_ids.txt Loading artist IDs from /usr/local/lib/python3.7/dist-packages/jukebox/data/ids/v2_genre_ids.txt Level:2, Cond downsample:None, Raw to tokens:128, Sample length:1048576 0: Converting to fp16 params Downloading from azure Running wget -O /root/.cache/jukebox/models/5b_lyrics/prior_level_2.pth.tar https://openaipublic.azureedge.net/jukebox/models/5b_lyrics/prior_level_2.pth.tar Restored from /root/.cache/jukebox/models/5b_lyrics/prior_level_2.pth.tar 0: Loading prior in eval mode
In [ ]:
sample_length_in_seconds = 60
hps.sample_length = (int(sample_length_in_seconds*hps.sr)//top_prior.raw_to_tokens)*top_prior.raw_to_tokens
assert hps.sample_length >= top_prior.n_ctx*top_prior.raw_to_tokens, f'Please choose a larger sampling rate'In [ ]:
metas = [dict(artist = "nina simone",
genre = "jazz",
total_length = hps.sample_length,
offset = 0,
lyrics = """I look for summer all year round, and suddenly here it is, she left for the beaches and I'm just up here in town, I hear whistling over the rooftops an airplane that takes off""",
),
] * hps.n_samples
labels = [None, None, top_prior.labeller.get_batch_labels(metas, 'cuda')]In [ ]:
sampling_temperature = .98
lower_batch_size = 16
max_batch_size = 3
lower_level_chunk_size = 32
chunk_size = 16
sampling_kwargs = [dict(temp=.99, fp16=True, max_batch_size=lower_batch_size,
chunk_size=lower_level_chunk_size),
dict(temp=0.99, fp16=True, max_batch_size=lower_batch_size,
chunk_size=lower_level_chunk_size),
dict(temp=sampling_temperature, fp16=True,
max_batch_size=max_batch_size, chunk_size=chunk_size)]In [ ]:
if continuation:
zs = top_prior.encode(x, start_level=0, end_level=len(priors), bs_chunks=x.shape[0])
else:
zs = [t.zeros(hps.n_samples,0,dtype=t.long, device='cuda') for _ in range(len(priors))]
zs = _sample(zs, labels, sampling_kwargs, [None, None, top_prior], [2], hps)Sampling level 2 Sampling 8192 tokens for [0,8192]. Conditioning on 0 tokens Ancestral sampling 3 samples with temp=0.98, top_k=0, top_p=0.0 8192/8192 [15:34<00:00, 8.76it/s] Sampling 8192 tokens for [1024,9216]. Conditioning on 7168 tokens Primed sampling 3 samples with temp=0.98, top_k=0, top_p=0.0 448/448 [01:37<00:00, 4.58it/s] 1024/1024 [02:07<00:00, 8.01it/s] Sampling 8192 tokens for [2048,10240]. Conditioning on 7168 tokens Primed sampling 3 samples with temp=0.98, top_k=0, top_p=0.0 448/448 [01:37<00:00, 4.59it/s] 1024/1024 [02:07<00:00, 8.01it/s] Sampling 8192 tokens for [3072,11264]. Conditioning on 7168 tokens Primed sampling 3 samples with temp=0.98, top_k=0, top_p=0.0 448/448 [01:37<00:00, 4.59it/s] 1024/1024 [02:07<00:00, 8.02it/s] Sampling 8192 tokens for [4096,12288]. Conditioning on 7168 tokens Primed sampling 3 samples with temp=0.98, top_k=0, top_p=0.0 448/448 [01:37<00:00, 4.59it/s] 1024/1024 [02:07<00:00, 8.01it/s] Sampling 8192 tokens for [5120,13312]. Conditioning on 7168 tokens Primed sampling 3 samples with temp=0.98, top_k=0, top_p=0.0 448/448 [01:37<00:00, 4.59it/s] 1024/1024 [02:07<00:00, 8.01it/s] Sampling 8192 tokens for [6144,14336]. Conditioning on 7168 tokens Primed sampling 3 samples with temp=0.98, top_k=0, top_p=0.0 448/448 [01:37<00:00, 4.59it/s] 1024/1024 [02:07<00:00, 8.01it/s] Sampling 8192 tokens for [7168,15360]. Conditioning on 7168 tokens Primed sampling 3 samples with temp=0.98, top_k=0, top_p=0.0 448/448 [01:37<00:00, 4.59it/s] 1024/1024 [02:07<00:00, 8.01it/s] Sampling 8192 tokens for [8192,16384]. Conditioning on 7168 tokens Primed sampling 3 samples with temp=0.98, top_k=0, top_p=0.0 448/448 [01:37<00:00, 4.59it/s] 1024/1024 [02:07<00:00, 8.00it/s] Sampling 8192 tokens for [9216,17408]. Conditioning on 7168 tokens Primed sampling 3 samples with temp=0.98, top_k=0, top_p=0.0 448/448 [01:37<00:00, 4.59it/s] 1024/1024 [02:07<00:00, 8.01it/s] Sampling 8192 tokens for [10240,18432]. Conditioning on 7168 tokens Primed sampling 3 samples with temp=0.98, top_k=0, top_p=0.0 448/448 [01:37<00:00, 4.59it/s] 1024/1024 [02:07<00:00, 8.01it/s] Sampling 8192 tokens for [11264,19456]. Conditioning on 7168 tokens Primed sampling 3 samples with temp=0.98, top_k=0, top_p=0.0 448/448 [01:37<00:00, 4.59it/s] 1024/1024 [02:07<00:00, 8.00it/s] Sampling 8192 tokens for [12288,20480]. Conditioning on 7168 tokens Primed sampling 3 samples with temp=0.98, top_k=0, top_p=0.0 448/448 [01:37<00:00, 4.59it/s] 1024/1024 [02:07<00:00, 8.01it/s] Sampling 8192 tokens for [12479,20671]. Conditioning on 8001 tokens Primed sampling 3 samples with temp=0.98, top_k=0, top_p=0.0 501/501 [01:52<00:00, 4.44it/s] 191/191 [00:24<00:00, 7.86it/s]
In [ ]:
Audio(f'{hps.name}/level_2/item_0.wav')Output hidden; open in https://colab.research.google.com to view.
In [ ]:
if False:
del top_prior
empty_cache()
top_prior=None
upsamplers = [make_prior(setup_hparams(prior, dict()), vqvae, 'cpu') for prior in priors[:-1]]
labels[:2] = [prior.labeller.get_batch_labels(metas, 'cuda') for prior in upsamplers]Conditioning on 1 above level(s) Checkpointing convs Checkpointing convs Loading artist IDs from /usr/local/lib/python3.7/dist-packages/jukebox/data/ids/v2_artist_ids.txt Loading artist IDs from /usr/local/lib/python3.7/dist-packages/jukebox/data/ids/v2_genre_ids.txt Level:0, Cond downsample:4, Raw to tokens:8, Sample length:65536 Downloading from azure Running wget -O /root/.cache/jukebox/models/5b/prior_level_0.pth.tar https://openaipublic.azureedge.net/jukebox/models/5b/prior_level_0.pth.tar Restored from /root/.cache/jukebox/models/5b/prior_level_0.pth.tar 0: Loading prior in eval mode Conditioning on 1 above level(s) Checkpointing convs Checkpointing convs Loading artist IDs from /usr/local/lib/python3.7/dist-packages/jukebox/data/ids/v2_artist_ids.txt Loading artist IDs from /usr/local/lib/python3.7/dist-packages/jukebox/data/ids/v2_genre_ids.txt Level:1, Cond downsample:4, Raw to tokens:32, Sample length:262144 Downloading from azure Running wget -O /root/.cache/jukebox/models/5b/prior_level_1.pth.tar https://openaipublic.azureedge.net/jukebox/models/5b/prior_level_1.pth.tar Restored from /root/.cache/jukebox/models/5b/prior_level_1.pth.tar 0: Loading prior in eval mode
In [ ]:
zs = upsample(zs, labels, sampling_kwargs, [*upsamplers, top_prior], hps)In [ ]:
Audio(f'{hps.name}/level_0/item_0.wav')