MCPcopy Create free account
hub / github.com/modelscope/modelscope / get_device

Function get_device

modelscope/utils/device.py:108–119  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

106
107
108def 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)

Callers

nothing calls this directly

Calls 1

deviceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…