Spaces:
Sleeping
Sleeping
Download utils/logging_utils.py from Raja-65/new-language_model: direct link, hf CLI and curl.
- Browser
- Download file 658 Bytes
-
https://huggingface.co/spaces/Raja-65/new-language_model/resolve/main/utils/logging_utils.py
- Command line
-
hf download hf://spaces/Raja-65/new-language_model/utils/logging_utils.py
-
curl -L -o logging_utils.py https://huggingface.co/spaces/Raja-65/new-language_model/resolve/main/utils/logging_utils.py
658 Bytes
| import inspect | |
| import logging | |
| import os | |
| def _process_index() -> int: | |
| """Return torch.distributed rank, falling back to env vars or 0.""" | |
| try: | |
| import torch.distributed as dist | |
| if dist.is_available() and dist.is_initialized(): | |
| return dist.get_rank() | |
| except Exception: | |
| pass | |
| return int(os.environ.get("RANK", "0")) | |
| def log_for_0(msg, *args, level=logging.INFO): | |
| """Log only on the first process (rank == 0).""" | |
| if _process_index() != 0: | |
| return | |
| caller_module = inspect.currentframe().f_back.f_globals.get("__name__", __name__) | |
| logging.getLogger(caller_module).log(level, msg, *args) | |