()
| 106 | |
| 107 | |
| 108 | def get_device(): |
| 109 | import torch |
| 110 | from torch import distributed as dist |
| 111 | if torch.cuda.is_available(): |
| 112 | if dist.is_available() and dist.is_initialized( |
| 113 | ) and 'LOCAL_RANK' in os.environ: |
| 114 | device_id = f"cuda:{os.environ['LOCAL_RANK']}" |
| 115 | else: |
| 116 | device_id = 'cuda:0' |
| 117 | else: |
| 118 | device_id = 'cpu' |
| 119 | return torch.device(device_id) |
nothing calls this directly
no test coverage detected
searching dependent graphs…