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

Fix batch size 1 by specifying squeeze dims #166

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Sobsz
Copy link

@Sobsz Sobsz commented Dec 19, 2023

Fixes #104 (as far as I can tell).

@yl4579
Copy link
Owner

yl4579 commented Dec 22, 2023

Thanks for your fix, but what does .squeeze(0) do? Doesn’t it squeeze over the batch dimensions and cause issues?

@Sobsz
Copy link
Author

Sobsz commented Dec 22, 2023

...hm. I'll be honest, I don't remember my reasoning behind it; I just know it doesn't break.

Looking at the relevant code again, it seems if len(sp) <= 1: makes it return early anyway if the first dimension is squeezable. Perhaps the .squeeze(0)s should be removed entirely (maybe along with the early return?).

@yl4579
Copy link
Owner

yl4579 commented Dec 22, 2023

So does it mean it's probably just redundant? Does it still work with batch size greater than 1? Also it would be great if you could implement gradient accumulate for the accelerate version of fine-tuning with 1 GPU but someone else could do it too. Sorry I am too busy to test the code nor adding new stuff.

@GUUser91
Copy link

GUUser91 commented Feb 5, 2024

@Sobsz
I tried your branch and I tried to finetune a model but I got the ZeroDivisionError: division by zero error message after 1 epoch. Batch size is set to 1.
Error Message IMG_20240205_142707_323

@Sobsz
Copy link
Author

Sobsz commented Feb 5, 2024

Seems like the testing iterations are failing silently because of the except: continue at lines 673-674. (That, or your validation list is empty...?) Try replacing the continue with raise and see what error you get.

@GUUser91
Copy link

GUUser91 commented Feb 6, 2024

@Sobsz
Now I get the dimension out of range (expected to be in range of [-1, 0], but got 1) error message. I'm using the rocm5.7 nightly pytorch build if it helps.
Error Range Message IMG_20240205_174637_769

@GUUser91
Copy link

GUUser91 commented Feb 6, 2024

@Sobsz
Here's a more clear version

Traceback (most recent call last):
File "/run/media/user/e1745494-af46-4749-9e1a-89d2b2289699/StyleTTS2/train_finetune.py", line 707, in
main()
File "/run/media/user/e1745494-af46-4749-9e1a-89d2b2289699/StyleTTS2/venv/lib/python3.10/site-packages/click/core.py", line 1157, in call
return self.main(*args, **kwargs)
File "/run/media/user/e1745494-af46-4749-9e1a-89d2b2289699/StyleTTS2/venv/lib/python3.10/site-packages/click/core.py", line 1078, in main
rv = self.invoke(ctx)
File "/run/media/user/e1745494-af46-4749-9e1a-89d2b2289699/StyleTTS2/venv/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/run/media/user/e1745494-af46-4749-9e1a-89d2b2289699/StyleTTS2/venv/lib/python3.10/site-packages/click/core.py", line 783, in invoke
return __callback(*args, **kwargs)
File "/run/media/user/e1745494-af46-4749-9e1a-89d2b2289699/StyleTTS2/train_finetune.py", line 614, in main
d, p = model.predictor(d_en, s,
File "/run/media/user/e1745494-af46-4749-9e1a-89d2b2289699/StyleTTS2/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/run/media/user/e1745494-af46-4749-9e1a-89d2b2289699/StyleTTS2/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1520, in _call_impl
return forward_call(*args, **kwargs)
File "/run/media/user/e1745494-af46-4749-9e1a-89d2b2289699/StyleTTS2/venv/lib/python3.10/site-packages/torch/nn/parallel/data_parallel.py", line 183, in forward
return self.module(*inputs[0], **module_kwargs[0])
File "/run/media/user/e1745494-af46-4749-9e1a-89d2b2289699/StyleTTS2/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/run/media/user/e1745494-af46-4749-9e1a-89d2b2289699/StyleTTS2/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1520, in _call_impl
return forward_call(*args, **kwargs)
File "/run/media/user/e1745494-af46-4749-9e1a-89d2b2289699/StyleTTS2/models.py", line 469, in forward
d = self.text_encoder(texts, style, text_lengths, m)
File "/run/media/user/e1745494-af46-4749-9e1a-89d2b2289699/StyleTTS2/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/run/media/user/e1745494-af46-4749-9e1a-89d2b2289699/StyleTTS2/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1520, in _call_impl
return forward_call(*args, **kwargs)
File "/run/media/user/e1745494-af46-4749-9e1a-89d2b2289699/StyleTTS2/models.py", line 550, in forward
x = block(x.transpose(-1, -2), style).transpose(-1, -2)
File "/run/media/user/e1745494-af46-4749-9e1a-89d2b2289699/StyleTTS2/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/run/media/user/e1745494-af46-4749-9e1a-89d2b2289699/StyleTTS2/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1520, in _call_impl
return forward_call(*args, **kwargs)
File "/run/media/user/e1745494-af46-4749-9e1a-89d2b2289699/StyleTTS2/models.py", line 431, in forward
h = h.view(h.size(0), h.size(1), 1)
IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)

Copy link

@korakoe korakoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validation losses have a range mismatch, something likely has to be done here, as we cant't just not have validation loss

@korakoe
Copy link

korakoe commented Mar 18, 2024

turns out that this also breaks higher batch sizes

@brthor
Copy link

brthor commented Apr 12, 2024

.squeeze(0) is going to squeeze the wrong dimension when batch size > 1, need to use .squeeze(dim=1) in most of these places (from manually stepping through with a debugger).

@korakoe
Copy link

korakoe commented May 8, 2024

.squeeze(0) is going to squeeze the wrong dimension when batch size > 1, need to use .squeeze(dim=1) in most of these places (from manually stepping through with a debugger).

@brthor can all of them be changed to dim=1 or do some need to remain 0? if so which ones?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug during finetuning training
6 participants