forked from acids-ircam/RAVE
-
Notifications
You must be signed in to change notification settings - Fork 1
/
train_rave.py
144 lines (120 loc) · 3.95 KB
/
train_rave.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import torch
from torch.utils.data import DataLoader, random_split
from rave.model import RAVE
from rave.core import random_phase_mangle, EMAModelCheckPoint
from rave.core import search_for_run
from udls import SimpleDataset, simple_audio_preprocess
from effortless_config import Config
import pytorch_lightning as pl
from os import environ, path
import numpy as np
import GPUtil as gpu
from udls.transforms import Compose, RandomApply, Dequantize, RandomCrop
import wandb
if __name__ == "__main__":
class args(Config):
DATA_SIZE = 16
CAPACITY = 32
LATENT_SIZE = 128
RATIOS = [4, 4, 2, 2, 2]
TAYLOR_DEGREES = 0
BIAS = True
NO_LATENCY = False
MIN_KL = 1e-4
MAX_KL = 1e-1
CROPPED_LATENT_SIZE = 0
FEATURE_MATCH = True
LOUD_STRIDE = 1
USE_NOISE = True
NOISE_RATIOS = [4, 4, 4]
NOISE_BANDS = 5
D_CAPACITY = 16
D_MULTIPLIER = 4
D_N_LAYERS = 4
WARMUP = 1000000
MODE = "hinge"
CKPT = None
PREPROCESSED = None
WAV = None
SR = 48000
N_SIGNAL = 65536
MAX_STEPS = 2000000
N_GPUS = 1
BATCH = 8
NAME = None
args.parse_args()
assert args.NAME is not None
model = RAVE(data_size=args.DATA_SIZE,
capacity=args.CAPACITY,
latent_size=args.LATENT_SIZE,
ratios=args.RATIOS,
bias=args.BIAS,
loud_stride=args.LOUD_STRIDE,
use_noise=args.USE_NOISE,
noise_ratios=args.NOISE_RATIOS,
noise_bands=args.NOISE_BANDS,
d_capacity=args.D_CAPACITY,
d_multiplier=args.D_MULTIPLIER,
d_n_layers=args.D_N_LAYERS,
warmup=args.WARMUP,
mode=args.MODE,
no_latency=args.NO_LATENCY,
sr=args.SR,
min_kl=args.MIN_KL,
max_kl=args.MAX_KL,
cropped_latent_size=args.CROPPED_LATENT_SIZE,
feature_match=args.FEATURE_MATCH,
taylor_degrees=args.TAYLOR_DEGREES)
x = torch.zeros(args.BATCH, 2**14)
model.validation_step(x, 0)
dataset = SimpleDataset(
args.PREPROCESSED,
args.WAV,
extension="*.wav,*.aif,*.flac",
preprocess_function=simple_audio_preprocess(args.SR,
2 * args.N_SIGNAL),
split_set="full",
transforms=Compose([
RandomCrop(args.N_SIGNAL),
# RandomApply(
# lambda x: random_phase_mangle(x, 20, 2000, .99, args.SR),
# p=.8,
# ),
Dequantize(16),
lambda x: x.astype(np.float32),
]),
)
val = (2 * len(dataset)) // 100
train = len(dataset) - val
train, val = random_split(
dataset,
[train, val],
generator=torch.Generator().manual_seed(42),
)
train = DataLoader(train, args.BATCH, True, drop_last=True, num_workers=8)
val = DataLoader(val, args.BATCH, False, num_workers=8)
# CHECKPOINT CALLBACKS
# validation_checkpoint = pl.callbacks.ModelCheckpoint(
# monitor="validation",
# filename="best",
# )
last_checkpoint = pl.callbacks.ModelCheckpoint(every_n_train_steps=100000)
val_check = {}
if len(train) >= 10000:
val_check["val_check_interval"] = 10000
else:
nepoch = 10000 // len(train)
val_check["check_val_every_n_epoch"] = nepoch
wandb_logger = pl.loggers.WandbLogger(project=args.NAME)
wandb_logger.watch(model)
trainer = pl.Trainer(
logger=wandb_logger,
gpus=args.N_GPUS,
strategy='ddp',
callbacks=[last_checkpoint],
resume_from_checkpoint=search_for_run(args.CKPT),
max_epochs=100000,
max_steps=args.MAX_STEPS,
**val_check,
)
trainer.fit(model, train, val)