EfficientNet-PyTorch icon indicating copy to clipboard operation
EfficientNet-PyTorch copied to clipboard

Consider if user has GPU/CPU while calling `torch.load()`

Open BRO3886 opened this issue 4 years ago • 3 comments

https://github.com/lukemelas/EfficientNet-PyTorch/blob/7e8b0d312162f335785fb5dcfa1df29a75a1783a/efficientnet_pytorch/utils.py#L598

if torch.cuda.is_available():
    device = torch.device("cuda")
else:
    device = torch.device("cpu")
state_dict = torch.load(weights_path, map_location=device) 

BRO3886 avatar May 22 '21 05:05 BRO3886

I wonder if I can load the model parameters to GPU correctly by simply write:

model = EfficientNet.from_pretrained('efficientnet-b3')
model.cuda()

OctoberKat avatar Jun 09 '21 08:06 OctoberKat

Actually, this might cause more problems than the benefits of the possible ease of use. Consider the case where one uses torch.nn.DistributedDataParallel, there is no way to ensure that torch.device("cuda") will return the appropriate gpu when there are multiple nodes.

ekurtulus avatar Jun 21 '21 12:06 ekurtulus

Not sure, don't have much experience in ML stuff. I don't have a PC with a CUDA compatible GPU. This package did not run on my machine but when I added the above code-block to the package and modified it's source it ran fine. That's why I suggested adding that block.

BRO3886 avatar Jun 21 '21 14:06 BRO3886