Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

torchinfo.summary should not change the device of model #287

Open
gitxw opened this issue Dec 5, 2023 · 2 comments
Open

torchinfo.summary should not change the device of model #287

gitxw opened this issue Dec 5, 2023 · 2 comments

Comments

@gitxw
Copy link

gitxw commented Dec 5, 2023

Describe the bug
torchinfo.summary should not change the device of model

To Reproduce
model = model.cpu()
torchinfo.summary(model)
why model was changed to cuda after calling torchinfo.summary() if I have a GraphicCard, It was Unexpected. I just want to dump the structure of my model.

Expected behavior
torchinfo.summary should keep the status of model, not change it.
the param "device" of the function torchinfo.summary is not necessary.

Desktop (please complete the following information):

  • OS: Windows11
@1-ashraful-islam
Copy link

1-ashraful-islam commented Jun 3, 2024

Had same issue using torchinfo.summary Current workaround seems to be passing device as additional argument.

Code example:

use_cuda = torch.cuda.is_available()
use_mps = torch.backends.mps.is_available()

if use_cuda:
    device = torch.device("cuda")
elif use_mps:
    device = torch.device("mps")
else:
    device = torch.device("cpu")

print(f"Using device (CUDA/MPS/CPU): {device}")

# initialize the model
model = ConvModel().to(device)

# print model info
print(summary(model, input_size=(batch_size, 1, 28, 28), device = device))

Device: Mac with apple silicon

@EbaraKoji
Copy link

I encountered the same problem on my M1 Mac.

The culprit seems to be get_device() function called in the summary().
This function does not consider mps device and device is set as cpu even when model parameters' device is mps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants