openai / jukebox

Code for the paper "Jukebox: A Generative Model for Music"
https://openai.com/blog/jukebox/
Other
7.83k stars 1.42k forks source link

Jukebox Upsampling by Parts - 4 parts version - Colab Notebook #163

Closed leonardog27 closed 3 years ago

leonardog27 commented 4 years ago

Include cell codes after this section:

Set this False if you are on a local machine that has enough memory (this allows you to do the

lyrics alignment visualization during the upsampling stage). For a hosted runtime,

we'll need to go ahead and delete the top_prior if you are using the 5b_lyrics model.

if True: 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]

as follows:

import math

frac025 = 0.25 frac050 = 0.5 # these are the points, 0.0-1.0, where you want to split the zs frac075 = 0.75 orig_len_zs_2 = len(zs[2][0]) new_len_zs_025 = math.floor( orig_len_zs_2 frac025 ) new_len_zs_050 = math.floor( orig_len_zs_2 frac050 ) new_len_zs_075 = math.floor( orig_len_zs_2 * frac075 )

zs_part1 = [ t.zeros(hps.n_samples, 0, dtype=t.long, device='cuda'), t.zeros(hps.n_samples, 0, dtype=t.long, device='cuda'), zs[2][:,0:new_len_zs_025].clone() ]

zs_part2 = [ t.zeros(hps.n_samples, 0, dtype=t.long, device='cuda'), t.zeros(hps.n_samples, 0, dtype=t.long, device='cuda'), zs[2][:,new_len_zs_025:new_len_zs_050].clone() ]

zs_part3 = [ t.zeros(hps.n_samples, 0, dtype=t.long, device='cuda'), t.zeros(hps.n_samples, 0, dtype=t.long, device='cuda'), zs[2][:,new_len_zs_050:new_len_zs_075:].clone() ]

zs_part4 = [ t.zeros(hps.n_samples, 0, dtype=t.long, device='cuda'), t.zeros(hps.n_samples, 0, dtype=t.long, device='cuda'), zs[2][:,new_len_zs_075].clone() ]

on separated sesions run each of the following 4 code sections. After finishing each of them rename the folders or make them in separated folders in different colab notebooks GPUs

top_prior_raw_to_tokens = 32 hps.sample_length = zs[2].shape[1] top_prior_raw_to_tokens zs = upsample(zs_part1, labels, sampling_kwargs, [upsamplers, top_prior], hps)

top_prior_raw_to_tokens = 32 hps.sample_length = zs[2].shape[1] top_prior_raw_to_tokens zs = upsample(zs_part2, labels, sampling_kwargs, [upsamplers, top_prior], hps)

top_prior_raw_to_tokens = 32 hps.sample_length = zs[2].shape[1] top_prior_raw_to_tokens zs = upsample(zs_part3, labels, sampling_kwargs, [upsamplers, top_prior], hps)

top_prior_raw_to_tokens = 32 hps.sample_length = zs[2].shape[1] top_prior_raw_to_tokens zs = upsample(zs_part4, labels, sampling_kwargs, [upsamplers, top_prior], hps)

leonardog27 commented 4 years ago

top_prior_raw_to_tokens = 32 hps.sample_length = zs[2].shape[1] top_prior_raw_to_tokens zs = upsample(zs_part4, labels, sampling_kwargs, [upsamplers, top_prior], hps)

The following error message appear at the moment to upsample PART 4, please help ?

Sampling level 1 Sampling 8192 tokens for [0,8192]. Conditioning on 0 tokens IndexError Traceback (most recent call last) in () 1 top_prior_raw_to_tokens = 32 2 hps.sample_length = zs[2].shape[1] top_prior_raw_to_tokens ----> 3 zs = upsample(zs_part4, labels, sampling_kwargs, [upsamplers, top_prior], hps)

4 frames /usr/local/lib/python3.6/dist-packages/jukebox/sample.py in upsample(zs, labels, sampling_kwargs, priors, hps) 137 def upsample(zs, labels, sampling_kwargs, priors, hps): 138 sample_levels = list(range(len(priors) - 1)) --> 139 zs = _sample(zs, labels, sampling_kwargs, priors, sample_levels, hps) 140 return zs 141

/usr/local/lib/python3.6/dist-packages/jukebox/sample.py in _sample(zs, labels, sampling_kwargs, priors, sample_levels, hps) 100 total_length = hps.sample_length//prior.raw_to_tokens 101 hop_length = int(hps.hop_fraction[level]*prior.n_ctx) --> 102 zs = sample_level(zs, labels[level], sampling_kwargs[level], level, prior, total_length, hop_length, hps) 103 104 prior.cpu()

/usr/local/lib/python3.6/dist-packages/jukebox/sample.py in sample_level(zs, labels, sampling_kwargs, level, prior, total_length, hop_length, hps) 83 if total_length >= prior.n_ctx: 84 for start in get_starts(total_length, prior.n_ctx, hop_length): ---> 85 zs = sample_single_window(zs, labels, sampling_kwargs, level, prior, start, hps) 86 else: 87 zs = sample_partial_window(zs, labels, sampling_kwargs, level, prior, total_length, hps)

/usr/local/lib/python3.6/dist-packages/jukebox/sample.py in sample_single_window(zs, labels, sampling_kwargs, level, prior, start, hps) 51 52 # get z_conds from level above ---> 53 z_conds = prior.get_z_conds(zs, start, end) 54 55 # set y offset, sample_length and lyrics tokens

/usr/local/lib/python3.6/dist-packages/jukebox/prior/prior.py in get_z_conds(self, zs, start, end) 159 if self.level != self.levels - 1: 160 assert start % self.cond_downsample == end % self.cond_downsample == 0 --> 161 z_cond = zs[self.level + 1][:,start//self.cond_downsample:end//self.cond_downsample] 162 assert z_cond.shape[1] == self.n_ctx//self.cond_downsample 163 z_conds = [z_cond]

IndexError: too many indices for tensor of dimension 1

It was prevoiuslly runned: frac025 = 0.25 frac050 = 0.5 # these are the points, 0.0-1.0, where you want to split the zs frac075 = 0.75 orig_len_zs_2 = len(zs[2][0]) new_len_zs_025 = math.floor( orig_len_zs_2 frac025 ) new_len_zs_050 = math.floor( orig_len_zs_2 frac050 ) new_len_zs_075 = math.floor( orig_len_zs_2 * frac075 )

zs_part1 = [ t.zeros(hps.n_samples, 0, dtype=t.long, device='cuda'), t.zeros(hps.n_samples, 0, dtype=t.long, device='cuda'), zs[2][:,0:new_len_zs_025].clone() ]

zs_part2 = [ t.zeros(hps.n_samples, 0, dtype=t.long, device='cuda'), t.zeros(hps.n_samples, 0, dtype=t.long, device='cuda'), zs[2][:,new_len_zs_025:new_len_zs_050].clone() ]

zs_part3 = [ t.zeros(hps.n_samples, 0, dtype=t.long, device='cuda'), t.zeros(hps.n_samples, 0, dtype=t.long, device='cuda'), zs[2][:,new_len_zs_050:new_len_zs_075:].clone() ]

zs_part4 = [ t.zeros(hps.n_samples, 0, dtype=t.long, device='cuda'), t.zeros(hps.n_samples, 0, dtype=t.long, device='cuda'), zs[2][:,new_len_zs_075].clone() ]

camjac251 commented 3 years ago

Do you have a notebook with these changes already? It'd be easier for users to run

leonardog27 commented 3 years ago

Do you have a notebook with these changes already? It'd be easier for users to run

There is a improved notebook colab available at Jukebox Community on discord that allow many more modes better that just Upsampling by parts . Go please to Code discussion section it is pinned there. https://discord.com/invite/6At7WwM