'unsupported tensor layout: Mkldnn'

username: Shisho_Sama
cooked: <p>Hello everyone,<br>
Hope you are having a great day.<br>
I’m trying to run RetinaFace using MKLDNN. However, when I try to do so, I face with these errors :</p>
<pre><code class="lang-auto">(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 &lt;module&gt;
    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 &lt;module&gt;
    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',).

</code></pre>
<p>For the full error list please have a look here : <a href="https://paste.ee/p/PoKMG" rel="nofollow noopener">https://paste.ee/p/PoKMG</a></p>
<p>What is happening here? how should I fix this ?<br>
Thanks a lot in advance</p>

username: ptrblck
cooked: <p>I assume you’ve transformed your parameters to the mkl layout before storing the <code>state_dict</code>?<br>
If so, could you try to load the <code>state_dict</code> and transform the parameters back to a dense representation via:</p>
<pre><code class="lang-python">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)
</code></pre>
<p>Could you also please create an <a href="https://github.com/pytorch/pytorch/issues">issue</a>?</p>

username: Shisho_Sama
cooked: <p>Thanks, it doesnt have any effect.<br>
Basically the paramters are converted into <code>mkldnn</code>, prior to instantiating a network and converting it to mkldnn as well.<br>
if I simply dont do this, I get the error :</p>
<blockquote>
<p><strong>RuntimeError</strong> : Input type (Mkldnntorch.FloatTensor) and weight type (torch.FloatTensor) should be the same</p>
</blockquote>
<p>then in order to fix this, I convert the parameters in advance, and then I face the errors I mentioned in my original question.</p>

username: Shisho_Sama
cooked: <p><a href="https://github.com/pytorch/pytorch/issues/32697" rel="nofollow noopener">Here</a>’s the issue for this problem.<br>
Actually catching the exception, revealed more errors .</p>