DirectML: RuntimeError: don't know how to restore data location of torch.FloatStorage

I am trying to train Yolov5 using DML and after tweaks in the code to let it use the DML device, I have this error when it tries to load the weights on the GPU:

 File "D:\Documenti\models\GTA_code\dml\lib\site-packages\torch\serialization.py", line 592, in load
    return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
  File "D:\Documenti\models\GTA_code\dml\lib\site-packages\torch\serialization.py", line 851, in _load
    result = unpickler.load()
  File "D:\Documenti\models\GTA_code\dml\lib\site-packages\torch\serialization.py", line 843, in persistent_load
    load_tensor(data_type, size, key, _maybe_decode_ascii(location))
  File "D:\Documenti\models\GTA_code\dml\lib\site-packages\torch\serialization.py", line 832, in load_tensor
    loaded_storages[key] = restore_location(storage, location)
  File "D:\Documenti\models\GTA_code\dml\lib\site-packages\torch\serialization.py", line 812, in restore_location
    return default_restore_location(storage, str(map_location))
  File "D:\Documenti\models\GTA_code\dml\lib\site-packages\torch\serialization.py", line 178, in default_restore_location
    raise RuntimeError("don't know how to restore data location of "
RuntimeError: don't know how to restore data location of torch.FloatStorage (tagged with dml)

Loading pretrained weights is not a supported feature…?

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 1
  • Comments: 15 (2 by maintainers)

Most upvoted comments

below code should work for majority of issues related to " dont know how to restore data location of torch.storage._untype storage ( tagged with gpu)

import torch  
import whisper 
devices = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") 
model = whisper.load_model("medium" , device =devices)

Hi, and thanks for posting the issue.

We have not taken a look at yolov5 yet, and as such the operators needed to get yolov5 working end-to-end are spotty. We absolutely intend to support yolov5 in the future, and will update this thread when we expect to have the operator conformance needed to enable it.

Update, I have fixed that problem using: torch.load(weights, map_location={'0':'dml'})

But now, I have this just at the start of the training (I have replaced SiLu with ReLu since is not supported):

libprotobuf FATAL D:\a\_work\1\s\caffe2\dml\dml_command_recorder.cc:361] CHECK failed: ((((HRESULT)((current_command_list_->Close()))) >= 0)) == (true):
val: Scanning 'D:\Projects\python\semantics\project\tests\annotations\multiclass\dataset\valid\labels.cache' images and
  0%|          | 0/11 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "train.py", line 640, in <module>
    main(opt)
  File "train.py", line 537, in main
    train(opt.hyp, opt, device, callbacks)
  File "train.py", line 331, in train
    loss, loss_items = compute_loss(pred, targets.to(device))  # loss scaled by batch_size
  File "D:\Documenti\models\yolov5\utils\loss.py", line 120, in __call__
    tcls, tbox, indices, anchors = self.build_targets(p, targets)  # targets
  File "D:\Documenti\models\yolov5\utils\loss.py", line 199, in build_targets
    j, k = ((gxy % 1 < g) & (gxy > 1)).T
  File "D:\Documenti\models\GTA_code\dml\lib\site-packages\torch\tensor.py", line 591, in __iter__
    return iter(self.unbind(0))
RuntimeError: CHECK failed: ((((HRESULT)((current_command_list_->Close()))) >= 0)) == (true):

If needed, this is yolov5 loss script