-
Notifications
You must be signed in to change notification settings - Fork 27.4k
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
Inappropriate reduce operation of "num_input_tokens_seen" is prone to get training stuck. #28791
Comments
Patched transformer with above hotfix, it seems the error still happened. Could you help have a look ? thanks. |
I also encountered the same problem in the first place, and that's why I added a statement to assign the device using |
Thank you @YouliangHUANG for the issue as well as the suggestion to fix it. It makes sense, it would be great if you want to open a PR with the suggested fix. |
See huggingface#28791 for more details.
@YouliangHUANG
After applied the fix, same error happened (transformers==4.37.2):
|
it works now after force set the device as 'cuda', so it seems that original error is caused by the allgather op not supported in cpu device ? |
@thincal Please check your backend type, and refer to https://pytorch.org/docs/stable/distributed.html for more details. |
Yes, it's the nccl backend used, which doesn't support cpu device. |
so what change is solving this problem ? |
|
OK, that's great. But it seems that the device should be decided according to the ddp backend ? |
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread. Please note that issues that do not follow the contributing guidelines are likely to be ignored. |
fix the behavior of collecting 'num_input_tokens_seen' See #28791 for more details.
…9099) fix the behavior of collecting 'num_input_tokens_seen' See huggingface#28791 for more details.
fix the behavior of collecting 'num_input_tokens_seen' See #28791 for more details.
System Info
Trivial
Who can help?
@pacman100
Information
Tasks
examples
folder (such as GLUE/SQuAD, ...)Reproduction
See src/transformers/trainer.py line 1870
self.state.num_input_tokens_seen += self.accelerator.gather(inputs[main_input_name]).numel()
The length of "inputs[main_input_name]" is not guaranteed to be the same when using ddp, which may make the training process hang. Besides, in a distributed setup, it costs a lot to gather the WHOLE input tensors on different workers. It is better to call .numel() first and then .gather().
Ref: Stuck when using model.generate() and acclerator.gather() in the distributed setting
Expected behavior
Fix:
input_device = inputs[main_input_name].device
self.state.num_input_tokens_seen += torch.sum(self.accelerator.gather(torch.tensor(inputs[main_input_name].numel(), device=input_device, dtype=torch.int64))).item()
The text was updated successfully, but these errors were encountered: