Created
January 12, 2024 18:58
-
-
Save xmfan/61575069c68a2d42597c539d71e19326 to your computer and use it in GitHub Desktop.
rank-based TORCH_LOGS sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/torch/_logging/_internal.py b/torch/_logging/_internal.py | |
index 7e4552f0f8e..ab75112bc3b 100644 | |
--- a/torch/_logging/_internal.py | |
+++ b/torch/_logging/_internal.py | |
@@ -667,7 +667,16 @@ def _is_valid_module(qname): | |
def _update_log_state_from_env(): | |
global log_state | |
log_setting = os.environ.get(LOG_ENV_VAR, None) | |
- if log_setting is not None: | |
+ | |
+ maybe_rank = os.environ.get("RANK", None) | |
+ rank = None | |
+ if maybe_rank is not None: | |
+ try: | |
+ rank = int(maybe_rank) | |
+ except ValueError: | |
+ rank = None | |
+ | |
+ if log_setting is not None and rank == 0: | |
log_state = _parse_log_settings(log_setting) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment