Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Egs ljspeach autocast & GradScaler function deprecated #1821

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions egs/ljspeech/TTS/vits/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from lhotse.cut import Cut
from lhotse.utils import fix_random_seed
from tokenizer import Tokenizer
from torch.cuda.amp import GradScaler, autocast
from torch.amp import GradScaler, autocast
from torch.nn.parallel import DistributedDataParallel as DDP
from torch.optim import Optimizer
from torch.utils.tensorboard import SummaryWriter
Expand Down Expand Up @@ -396,7 +396,7 @@ def save_bad_model(suffix: str = ""):
loss_info["samples"] = batch_size

try:
with autocast(enabled=params.use_fp16):
with autocast('cuda',enabled=params.use_fp16):
# forward discriminator
loss_d, stats_d = model(
text=tokens,
Expand All @@ -414,7 +414,7 @@ def save_bad_model(suffix: str = ""):
scaler.scale(loss_d).backward()
scaler.step(optimizer_d)

with autocast(enabled=params.use_fp16):
with autocast('cuda',enabled=params.use_fp16):
# forward generator
loss_g, stats_g = model(
text=tokens,
Expand Down Expand Up @@ -673,7 +673,7 @@ def scan_pessimistic_batches_for_oom(
)
try:
# for discriminator
with autocast(enabled=params.use_fp16):
with autocast('cuda',enabled=params.use_fp16):
loss_d, stats_d = model(
text=tokens,
text_lengths=tokens_lens,
Expand All @@ -686,7 +686,7 @@ def scan_pessimistic_batches_for_oom(
optimizer_d.zero_grad()
loss_d.backward()
# for generator
with autocast(enabled=params.use_fp16):
with autocast('cuda',enabled=params.use_fp16):
loss_g, stats_g = model(
text=tokens,
text_lengths=tokens_lens,
Expand Down Expand Up @@ -838,7 +838,7 @@ def remove_short_and_long_utt(c: Cut):
params=params,
)

scaler = GradScaler(enabled=params.use_fp16, init_scale=1.0)
scaler = GradScaler('cuda',enabled=params.use_fp16, init_scale=1.0)
if checkpoints and "grad_scaler" in checkpoints:
logging.info("Loading grad scaler state dict")
scaler.load_state_dict(checkpoints["grad_scaler"])
Expand Down
6 changes: 3 additions & 3 deletions egs/ljspeech/TTS/vits/vits.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
KLDivergenceLoss,
MelSpectrogramLoss,
)
from torch.cuda.amp import autocast
from torch.amp import autocast
from utils import get_segments

AVAILABLE_GENERATERS = {
Expand Down Expand Up @@ -410,7 +410,7 @@ def _forward_generator(
p = self.discriminator(speech_)

# calculate losses
with autocast(enabled=False):
with autocast('cuda',enabled=False):
if not return_sample:
mel_loss = self.mel_loss(speech_hat_, speech_)
else:
Expand Down Expand Up @@ -518,7 +518,7 @@ def _forward_discrminator(
p = self.discriminator(speech_)

# calculate losses
with autocast(enabled=False):
with autocast('cuda',enabled=False):
real_loss, fake_loss = self.discriminator_adv_loss(p_hat, p)
loss = real_loss + fake_loss

Expand Down
Loading