RuntimeError: 0 <= device && device < device_num INTERNAL ASSERT FAILED at /pytorch/c10/cuda/CUDACachingAllocator.cpp:879, please report a bug to PyTorch. Invalid device argument.

  • The computer was able to run the code on the GPU

  • I did a computer restart

  • The computer cannot run the code and is recording the following error


RuntimeError Traceback (most recent call last)
in
6 torch.cuda.empty_cache ()
7
----> 8 print (torch.cuda.memory_allocated (0))

~ / anaconda3 / lib / python3.7 / site-packages / torch / cuda / memory.py in memory_allocated (device)
276 details about GPU memory management.
277 “” "
-> 278 return memory_stats (device = device) [“allocated_bytes.all.current”]
279
280

~ / anaconda3 / lib / python3.7 / site-packages / torch / cuda / memory.py in memory_stats (device)
157 result.append ((prefix, obj))
158
-> 159 stats = memory_stats_as_nested_dict (device = device)
160 _recurse_add_to_result ("", stats)
161 result.sort ()

~ / anaconda3 / lib / python3.7 / site-packages / torch / cuda / memory.py in memory_stats_as_nested_dict (device)
167 "Returns the result of: func: ~ torch.cuda.memory_stats as a nested dictionary. “” "
168 device = _get_device_index (device, optional = True)
-> 169 return torch._C._cuda_memoryStats (device)
170
171

RuntimeError: 0 <= device && device <device_num INTERNAL ASSERT FAILED at /pytorch/c10/cuda/CUDACachingAllocator.cpp:879, please report a bug to PyTorch. Invalid device argument.

Hi,

Could you give more context about what you where doing when it happened?
Also could you run your code again with TORCH_SHOW_CPP_STACKTRACES=1 env variable to get more informations where the error comes from?