-
Notifications
You must be signed in to change notification settings - Fork 6.6k
[core] Handle progress bar and logging in distributed environments #12806
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
f207108
97e3805
8df3fbc
94d671d
2529fdf
8193f38
91c73bb
086a770
9cf5edd
4c09694
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # Copyright 2025 The HuggingFace Inc. team. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
|
|
||
| try: | ||
| import torch | ||
| except ImportError: | ||
| torch = None | ||
|
|
||
|
|
||
| def is_torch_dist_rank_zero() -> bool: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this robust to different distributed setups such as
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we can control external dependencies much i.e., the logs from |
||
| if torch is None: | ||
| return True | ||
|
|
||
| dist_module = getattr(torch, "distributed", None) | ||
| if dist_module is None or not dist_module.is_available(): | ||
| return True | ||
|
|
||
| if not dist_module.is_initialized(): | ||
| return True | ||
|
|
||
| try: | ||
| return dist_module.get_rank() == 0 | ||
| except (RuntimeError, ValueError): | ||
| return True | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To not introduce circular import problem.