Download misc.py from Abhiknack/triposf: direct link, hf CLI and curl.
- Browser
- Download file 702 Bytes
-
https://huggingface.co/spaces/Abhiknack/triposf/resolve/main/misc.py
- Command line
-
hf download hf://spaces/Abhiknack/triposf/misc.py
-
curl -L -o misc.py https://huggingface.co/spaces/Abhiknack/triposf/resolve/main/misc.py
702 Bytes
| import torch | |
| import os | |
| import importlib | |
| def find(cls_string): | |
| module_string = ".".join(cls_string.split(".")[:-1]) | |
| cls_name = cls_string.split(".")[-1] | |
| module = importlib.import_module(module_string, package=None) | |
| cls = getattr(module, cls_name) | |
| return cls | |
| def get_rank(): | |
| # SLURM_PROCID can be set even if SLURM is not managing the multiprocessing, | |
| # therefore LOCAL_RANK needs to be checked first | |
| rank_keys = ("RANK", "LOCAL_RANK", "SLURM_PROCID", "JSM_NAMESPACE_RANK") | |
| for key in rank_keys: | |
| rank = os.environ.get(key) | |
| if rank is not None: | |
| return int(rank) | |
| return 0 | |
| def get_device(): | |
| return torch.device(f"cuda:{get_rank()}") |