'unsupported tensor layout: Mkldnn'

Hello everyone,
Hope you are having a great day.
I’m trying to run RetinaFace using MKLDNN. However, when I try to do so, I face with these errors :

(base) user@F3S-s3user:/mnt/d/Codes/Pytorch_Retinaface_MKLDN$ cd /mnt/d/Codes/Pytorch_Retinaface_MKLDN ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /home/user/anaconda3/bin/python /home/user/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles/ptvsd_launcher.py --default --nodebug --client --host localhost --port 52342 /mnt/d/Codes/Pytorch_Retinaface_MKLDN/test_detect_align_MKLDNN.py 
Loading pretrained model from ./weights/mobilenet0.25_Final.pth
remove prefix 'module.'
Traceback (most recent call last):
  File "/home/user/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles/ptvsd_launcher.py", line 43, in <module>
    main(ptvsdArgs)
  File "/home/user/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles/lib/python/old_ptvsd/ptvsd/__main__.py", line 432, in main
    run()
  File "/home/user/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles/lib/python/old_ptvsd/ptvsd/__main__.py", line 316, in run_file
    runpy.run_path(target, run_name='__main__')
  File "/home/user/anaconda3/lib/python3.7/runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "/home/user/anaconda3/lib/python3.7/runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/home/user/anaconda3/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/mnt/d/Codes/Pytorch_Retinaface_MKLDN/test_detect_align_MKLDNN.py", line 318, in <module>
    model_weights=model.weight )
  File "/mnt/d/Codes/Pytorch_Retinaface_MKLDN/test_detect_align_MKLDNN.py", line 87, in detect
    net = load_model(net, trained_model, cpu)
  File "/mnt/d/Codes/Pytorch_Retinaface_MKLDN/test_detect_align_MKLDNN.py", line 60, in load_model
    model.load_state_dict(pretrained_dict, strict=False)
  File "/home/user/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 831, in load_state_dict
    self.__class__.__name__, "\n\t".join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for RetinaFace:
        While copying the parameter named "body.stage1.0.0.weight", whose dimensions in the model are torch.Size([8, 3, 3, 3]) and whose dimensions in the checkpoint are torch.Size([8, 3, 3, 3]), an exception occured: ('unsupported tensor layout: Mkldnn',).
        While copying the parameter named "body.stage1.0.1.running_var", whose dimensions in the model are torch.Size([8]) and whose dimensions in the checkpoint are torch.Size([8]), an exception occured: ('unsupported tensor layout: Mkldnn',).
        While copying the parameter named "body.stage1.0.1.running_mean", whose dimensions in the model are torch.Size([8]) and whose dimensions in the checkpoint are torch.Size([8]), an exception occured: ('unsupported tensor layout: Mkldnn',).
        While copying the parameter named "body.stage1.0.1.weight", whose dimensions in the model are torch.Size([8]) and whose dimensions in the checkpoint are torch.Size([8]), an exception occured: ('unsupported tensor layout: Mkldnn',).
        While copying the parameter named "body.stage1.0.1.bias", whose dimensions in the model are torch.Size([8]) and whose dimensions in the checkpoint are torch.Size([8]), an exception occured: ('unsupported tensor layout: Mkldnn',).
        While copying the parameter named "body.stage1.1.0.weight", whose dimensions in the model are torch.Size([8, 1, 3, 3]) and whose dimensions in the checkpoint are torch.Size([8, 1, 3, 3]), an exception occured: ('unsupported tensor layout: Mkldnn',).
        While copying the parameter named "body.stage1.1.1.running_var", whose dimensions in the model are torch.Size([8]) and whose dimensions in the checkpoint are torch.Size([8]), an exception occured: ('unsupported tensor layout: Mkldnn',).
        While copying the parameter named "body.stage1.1.1.running_mean", whose dimensions in the model are torch.Size([8]) and whose dimensions in the checkpoint are torch.Size([8]), an exception occured: ('unsupported tensor layout: Mkldnn',).
        While copying the parameter named "body.stage1.1.1.weight", whose dimensions in the model are torch.Size([8]) and whose dimensions in the checkpoint are torch.Size([8]), an exception occured: ('unsupported tensor layout: Mkldnn',).
        While copying the parameter named "body.stage1.1.1.bias", whose dimensions in the model are torch.Size([8]) and whose dimensions in the checkpoint are torch.Size([8]), an exception occured: ('unsupported tensor layout: Mkldnn',).
        While copying the parameter named "body.stage1.1.3.weight", whose dimensions in the model are torch.Size([16, 8, 1, 1]) and whose dimensions in the checkpoint are torch.Size([16, 8, 1, 1]), an exception occured: ('unsupported tensor layout: Mkldnn',).
        While copying the parameter named "body.stage1.1.4.running_var", whose dimensions in the model are torch.Size([16]) and whose dimensions in the checkpoint are torch.Size([16]), an exception occured: ('unsupported tensor layout: Mkldnn',).
        While copying the parameter named "body.stage1.1.4.running_mean", whose dimensions in the model are torch.Size([16]) and whose dimensions in the checkpoint are torch.Size([16]), an exception occured: ('unsupported tensor layout: Mkldnn',).
        While copying the parameter named "body.stage1.1.4.weight", whose dimensions in the model are torch.Size([16]) and whose dimensions in the checkpoint are torch.Size([16]), an exception occured: ('unsupported tensor layout: Mkldnn',).
        While copying the parameter named "body.stage1.1.4.bias", whose dimensions in the model are torch.Size([16]) and whose dimensions in the checkpoint are torch.Size([16]), an exception occured: ('unsupported tensor layout: Mkldnn',).
        While copying the parameter named "body.stage1.2.0.weight", whose dimensions in the model are torch.Size([16, 1, 3, 3]) and whose dimensions in the checkpoint are torch.Size([16, 1, 3, 3]), an exception occured: ('unsupported tensor layout: Mkldnn',).
        While copying the parameter named "body.stage1.2.1.running_var", whose dimensions in the model are torch.Size([16]) and whose dimensions in the checkpoint are torch.Size([16]), an exception occured: ('unsupported tensor layout: Mkldnn',).
        While copying the parameter named "body.stage1.2.1.running_mean", whose dimensions in the model are torch.Size([16]) and whose dimensions in the checkpoint are torch.Size([16]), an exception occured: ('unsupported tensor layout: Mkldnn',).
        While copying the parameter named "body.stage1.2.1.weight", whose dimensions in the model are torch.Size([16]) and whose dimensions in the checkpoint are torch.Size([16]), an exception occured: ('unsupported tensor layout: Mkldnn',).
        While copying the parameter named "body.stage1.2.1.bias", whose dimensions in the model are torch.Size([16]) and whose dimensions in the checkpoint are torch.Size([16]), an exception occured: ('unsupported tensor layout: Mkldnn',).
        While copying the parameter named "body.stage1.2.3.weight", whose dimensions in the model are torch.Size([32, 16, 1, 1]) and whose dimensions in the checkpoint are torch.Size([32, 16, 1, 1]), an exception occured: ('unsupported tensor layout: Mkldnn',).
        While copying the parameter named "body.stage1.2.4.running_var", whose dimensions in the model are torch.Size([32]) and whose dimensions in the checkpoint are torch.Size([32]), an exception occured: ('unsupported tensor layout: Mkldnn',).
        While copying the parameter named "body.stage1.2.4.running_mean", whose dimensions in the model are torch.Size([32]) and whose dimensions in the checkpoint are torch.Size([32]), an exception occured: ('unsupported tensor layout: Mkldnn',).
        While copying the parameter named "body.stage1.2.4.weight", whose dimensions in the model are torch.Size([32]) and whose dimensions in the checkpoint are torch.Size([32]), an exception occured: ('unsupported tensor layout: Mkldnn',).
        While copying the parameter named "body.stage1.2.4.bias", whose dimensions in the model are torch.Size([32]) and whose dimensions in the checkpoint are torch.Size([32]), an exception occured: ('unsupported tensor layout: Mkldnn',).

For the full error list please have a look here : https://paste.ee/p/PoKMG

What is happening here? how should I fix this ?
Thanks a lot in advance

I assume you’ve transformed your parameters to the mkl layout before storing the state_dict?
If so, could you try to load the state_dict and transform the parameters back to a dense representation via:

state_dict = torch.load(...)
for key in state_dict:
    state_dict[key] = state_dict[key].to_dense()
model = MyModel(...)
model.load_state_dict(state_dict)

Could you also please create an issue?

Thanks, it doesnt have any effect.
Basically the paramters are converted into mkldnn, prior to instantiating a network and converting it to mkldnn as well.
if I simply dont do this, I get the error :

RuntimeError : Input type (Mkldnntorch.FloatTensor) and weight type (torch.FloatTensor) should be the same

then in order to fix this, I convert the parameters in advance, and then I face the errors I mentioned in my original question.

Here’s the issue for this problem.
Actually catching the exception, revealed more errors .