Skip to content

Commit 97fb420

Browse files
authored
Merge pull request ArkanDash#67 from onxlmao/fix/grad-norm-g-bug
Fix UnboundLocalError: grad_norm_g undefined during gradient accumulation
2 parents 8c9a2b2 + f997f38 commit 97fb420

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

  • advanced_rvc_inference/rvc/train/training

advanced_rvc_inference/rvc/train/training/train.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,9 @@ def train_and_evaluate(rank, epoch, hps, nets, optims, scaler, train_loader, wri
831831
# Optimization: scale loss by accumulation steps for correct gradient averaging
832832
loss_gen_all_scaled = loss_gen_all * loss_scale_factor
833833

834+
# Initialize grad_norm_g so it's always defined (needed for gradient accumulation)
835+
grad_norm_g = 0.0
836+
834837
# Optimization: set_to_none=True is faster than zeroing gradients
835838
optim_g.zero_grad(set_to_none=True)
836839
if autocast_enabled:

0 commit comments

Comments
 (0)