Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions torchinfo/torchinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,18 +473,21 @@ def get_device(
If input_data is given, the device should not be changed
(to allow for multi-device models, etc.)

Otherwise gets device of first parameter of model and returns it if it is on cuda,
otherwise returns cuda if available or cpu if not.
Otherwise gets device of first parameter of model and returns it,
otherwise returns current accelerator if it is available,
otherwise returns cpu.
"""
if input_data is None:
try:
model_parameter = next(model.parameters())
except StopIteration:
model_parameter = None

if model_parameter is not None and model_parameter.is_cuda:
if model_parameter is not None and model_parameter.device:
return model_parameter.device
return torch.device("cuda" if torch.cuda.is_available() else "cpu")
if torch.accelerator.is_available():
return torch.accelerator.current_accelerator()
return torch.device("cpu")
return None


Expand Down
Loading