Code Monkey home page Code Monkey logo

Comments (15)

stevenhillis avatar stevenhillis commented on July 30, 2024 2

Got another error when using mixed precision:

Traceback (most recent call last):
  File "train_first.py", line 444, in <module>
    main()
  File "/root/miniconda3/lib/python3.8/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/root/miniconda3/lib/python3.8/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/root/miniconda3/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/root/miniconda3/lib/python3.8/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "train_first.py", line 305, in main
    optimizer.step('pitch_extractor')
  File "/root/autodl-tmp/StyleTTS2/optimizers.py", line 32, in step
    _ = [self._step(key, scaler) for key in keys]
  File "/root/autodl-tmp/StyleTTS2/optimizers.py", line 32, in <listcomp>
    _ = [self._step(key, scaler) for key in keys]
  File "/root/autodl-tmp/StyleTTS2/optimizers.py", line 39, in _step
    self.optimizers[key].step()
  File "/root/miniconda3/lib/python3.8/site-packages/accelerate/optimizer.py", line 133, in step
    self.scaler.step(self.optimizer, closure)
  File "/root/miniconda3/lib/python3.8/site-packages/torch/cuda/amp/grad_scaler.py", line 336, in step
    assert len(optimizer_state["found_inf_per_device"]) > 0, "No inf checks were recorded for this optimizer."
AssertionError: No inf checks were recorded for this optimizer.

What seems to be the problem? Thanks!

I have traced this to

optimizer.step('pitch_extractor')
. The pitch extractor's optimizer is being called to step, but the pitch extractor itself is only ever called in a no_grad context, so there are no gradients. The assertion is in torch's grad_scaler code, which is why it only shows up in mixed_precision.

It does make me wonder, @yl4579 , if this is expected? Were the parameters of the pitch_extractor expected to get updated?

from styletts2.

yl4579 avatar yl4579 commented on July 30, 2024

I used 4 A100 with a batch size of 32 for the paper, and the checkpoint I shared was trained with 4 L40 with a batch size of 16. You can either decrease the batch size to 4 (as you only have one GPU), or you can decrease the max_len, which now is equivalent to 5 seconds. You definitely don't need that long clip for training.

from styletts2.

yl4579 avatar yl4579 commented on July 30, 2024

Also for the first stage, you can try mixed precision, and it doesn't seem to decrease the reconstruction quality in my experience. It results in much faster training and half of the RAM use. All you need is accelerate launch --mixed_precision=fp16 train_first.py --config_path ./Configs/config.yml. This is the stage that takes the most time anyway so using mixed precision is always good practice.

from styletts2.

godspirit00 avatar godspirit00 commented on July 30, 2024

Also for the first stage, you can try mixed precision, and it doesn't seem to decrease the reconstruction quality in my experience. It results in much faster training and half of the RAM use. All you need is accelerate launch --mixed_precision=fp16 train_first.py --config_path ./Configs/config.yml. This is the stage that takes the most time anyway so using mixed precision is always good practice.

Thanks! I'll give a try!

from styletts2.

godspirit00 avatar godspirit00 commented on July 30, 2024

Got another error when using mixed precision:

Traceback (most recent call last):
  File "train_first.py", line 444, in <module>
    main()
  File "/root/miniconda3/lib/python3.8/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/root/miniconda3/lib/python3.8/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/root/miniconda3/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/root/miniconda3/lib/python3.8/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "train_first.py", line 305, in main
    optimizer.step('pitch_extractor')
  File "/root/autodl-tmp/StyleTTS2/optimizers.py", line 32, in step
    _ = [self._step(key, scaler) for key in keys]
  File "/root/autodl-tmp/StyleTTS2/optimizers.py", line 32, in <listcomp>
    _ = [self._step(key, scaler) for key in keys]
  File "/root/autodl-tmp/StyleTTS2/optimizers.py", line 39, in _step
    self.optimizers[key].step()
  File "/root/miniconda3/lib/python3.8/site-packages/accelerate/optimizer.py", line 133, in step
    self.scaler.step(self.optimizer, closure)
  File "/root/miniconda3/lib/python3.8/site-packages/torch/cuda/amp/grad_scaler.py", line 336, in step
    assert len(optimizer_state["found_inf_per_device"]) > 0, "No inf checks were recorded for this optimizer."
AssertionError: No inf checks were recorded for this optimizer.

What seems to be the problem? Thanks!

from styletts2.

yl4579 avatar yl4579 commented on July 30, 2024

@godspirit00 It says the loss is NaN because you are using mixed precision. I think you may have to change the loss here: https://github.com/yl4579/StyleTTS2/blob/main/losses.py#L22 with return F.l1_loss(y_mag, x_mag).

from styletts2.

godspirit00 avatar godspirit00 commented on July 30, 2024

The error persists after changing the line.

Traceback (most recent call last):
  File "train_first.py", line 444, in <module>
    main()
  File "/root/miniconda3/lib/python3.8/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/root/miniconda3/lib/python3.8/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/root/miniconda3/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/root/miniconda3/lib/python3.8/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "train_first.py", line 305, in main
    optimizer.step('pitch_extractor')
  File "/root/autodl-tmp/StyleTTS2/optimizers.py", line 32, in step
    _ = [self._step(key, scaler) for key in keys]
  File "/root/autodl-tmp/StyleTTS2/optimizers.py", line 32, in <listcomp>
    _ = [self._step(key, scaler) for key in keys]
  File "/root/autodl-tmp/StyleTTS2/optimizers.py", line 39, in _step
    self.optimizers[key].step()
  File "/root/miniconda3/lib/python3.8/site-packages/accelerate/optimizer.py", line 133, in step
    self.scaler.step(self.optimizer, closure)
  File "/root/miniconda3/lib/python3.8/site-packages/torch/cuda/amp/grad_scaler.py", line 336, in step
    assert len(optimizer_state["found_inf_per_device"]) > 0, "No inf checks were recorded for this optimizer."
AssertionError: No inf checks were recorded for this optimizer.

It was at Epoch 50.

from styletts2.

yl4579 avatar yl4579 commented on July 30, 2024

Could it be related to the discriminators, or is it a TMA issue? Can you set the TMA epoch to a higher number but set start_ds in train_first.py to True and see if it is a problem of discriminators?

from styletts2.

godspirit00 avatar godspirit00 commented on July 30, 2024

Can you set the TMA epoch to a higher number but set start_ds in train_first.py to True

I tried searching for start_ds in train_first.py, but I can't find it.

from styletts2.

yl4579 avatar yl4579 commented on July 30, 2024

Sorry I mean you just modify the code to train the discriminator but not the aligner. But if it still doesn’t work, probably you have to do it without mixed precision. It is highly sensitive to batch size unfortunately, so it probably only works for large enough batches (like 16 or 32).

from styletts2.

yl4579 avatar yl4579 commented on July 30, 2024

@stevenhillis I think you are correct. The pitch_extractor actually shouldn't be updated. Does removing this line fix this problem of mixed precision?

from styletts2.

stevenhillis avatar stevenhillis commented on July 30, 2024

Good deal. Sure does!

from styletts2.

RillmentGames avatar RillmentGames commented on July 30, 2024

I have traced this to

optimizer.step('pitch_extractor')

I had the same 'inf' crash problem at epoch 50 with mixed precision and Batch=4. I can confirm that this allows the training to continue past 50.

from styletts2.

Moonmore avatar Moonmore commented on July 30, 2024

I used 4 A100 with a batch size of 32 for the paper, and the checkpoint I shared was trained with 4 L40 with a batch size of 16. You can either decrease the batch size to 4 (as you only have one GPU), or you can decrease the max_len, which now is equivalent to 5 seconds. You definitely don't need that long clip for training.

@yl4579 Thanks for your great job.
I used 4 V100 with a batch size of 8 and max len of 200 with my dataset. When I set the batch size to 16, out of memory.
So I should reduce max len?How to balance max len and batch size, and how should I adjust this parameter?
Thanks a lot.

from styletts2.

yl4579 avatar yl4579 commented on July 30, 2024

@Moonmore See #81 for a detailed discussion.

from styletts2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.