Download code/2.py from rcell233/magvits_data: direct link, hf CLI and curl.
- Browser
- Download file 1.32 kB
-
https://huggingface.co/datasets/rcell233/magvits_data/resolve/main/code/2.py
- Command line
-
hf download hf://datasets/rcell233/magvits_data/code/2.py
-
curl -L -o 2.py https://huggingface.co/datasets/rcell233/magvits_data/resolve/main/code/2.py
1.32 kB
| import torch | |
| from audio_diffusion_pytorch import DiffusionModel, UNetV0, VDiffusion, VSampler | |
| from module.models_s1 import DiT | |
| latent_dim = 4 | |
| cond_channels = 192 | |
| net =DiT(latent_dim, cond_channels) | |
| model = DiffusionModel( | |
| net=net, # The model type used for diffusion (U-Net V0 in this case) | |
| in_channels=2, # U-Net: number of input/output (audio) channels | |
| channels=[8, 32], # U-Net: channels at each layer | |
| factors=[1, 4,], # U-Net: downsampling and upsampling factors at each layer | |
| items=[1, 2], # U-Net: number of repeating items at each layer | |
| attentions=[0, 0, ], # U-Net: attention enabled/disabled at each layer | |
| attention_heads=8, # U-Net: number of attention heads per attention item | |
| attention_features=64, # U-Net: number of attention features per attention item | |
| diffusion_t=VDiffusion, # The diffusion method used | |
| sampler_t=VSampler, # The diffusion sampler used | |
| ) | |
| print('n params:', sum(p.numel() for p in model.parameters())/1e6, 'M') | |
| audio = torch.randn(2, 4, 111) | |
| cond = torch.randn(2, 192, 111) | |
| loss = model(audio, cond=cond) | |
| loss.backward() | |
| print(loss) | |
| # # Turn noise into new audio sample with diffusion | |
| noise = torch.randn(2, 4, 111) | |
| sample = model.sample(noise, num_steps=10,cond=cond, show_progress=True) # Suggested num_steps 10-100 | |
| print(sample.shape) |