Train SoundStorm on pre-encoded codebook IDs
mainIf you already have pre-encoded codebook IDs (e.g., from a SoundStream model), you can train the SoundStorm model directly on these codes.
- Initialize a
ConformerWrapperwith the appropriatecodebook_sizeandnum_quantizers. - Initialize
SoundStormwith the conformer and specify the number ofsteps(e.g., 18) and aschedule(e.g., 'cosine'). - Pass the codes of shape
(batch, seq, num_residual_vq)to the model to compute loss.
import torch
from soundstorm_pytorch import SoundStorm, ConformerWrapper
conformer = ConformerWrapper(
codebook_size = 1024,
num_quantizers = 12,
conformer = dict(
dim = 512,
depth = 2
),
)
model = SoundStorm(
conformer,
steps = 18, # 18 steps, as in original maskgit paper
schedule = 'cosine' # currently the best schedule is cosine
)
# codes shape: (batch, seq, num residual VQ)
codes = torch.randint(0, 1024, (2, 1024, 12))
loss, _ = model(codes)
loss.backward()
# Generation
generated = model.generate(1024, batch_size = 2) # (2, 1024)