MCPcopy
hub / github.com/InternLM/InternLM / get_current_device

Function get_current_device

internlm/utils/common.py:91–99  ·  view source on GitHub ↗

Returns currently selected device (gpu/cpu). If cuda available, return gpu, otherwise return cpu.

()

Source from the content-addressed store, hash-verified

89
90
91def get_current_device() -> torch.device:
92 """
93 Returns currently selected device (gpu/cpu).
94 If cuda available, return gpu, otherwise return cpu.
95 """
96 if torch.cuda.is_available():
97 return torch.device(f"cuda:{torch.cuda.current_device()}")
98 else:
99 return torch.device("cpu")
100
101
102def get_batch_size(data):

Callers 14

load_model_checkpointFunction · 0.90
_forward_only_stepMethod · 0.90
forward_backward_stepMethod · 0.90
send_obj_metaFunction · 0.90
recv_obj_metaFunction · 0.90
__init__Method · 0.90
initialize_trainerFunction · 0.90
forwardMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected