Torch.jit.save error : RuntimeError: Unable to cast Python instance of type <class 'int'> to C++ type 'std::string'

Shisho_Sama: <p>Hello everyone,<br>
I tried to save my quantized_model using <code>torch.jit.save(torch.jit.script(my_quantized_model),save_path)</code><br>
which resulted in the following error :</p>
<pre><code class="lang-auto">Epoch:249/250 || Iter: 403/403 || Loc: 1.1537 Cla: 1.6551 Landm: 2.8905 || LR: 0.00001000 || Batchtime: 0.1739 s || ETA: 0:00:00
Traceback (most recent call last):
  File "/root/.vscode/extensions/ms-python.python-2020.1.58038/pythonFiles/ptvsd_launcher.py", line 43, in &lt;module&gt;
    main(ptvsdArgs)
  File "/root/.vscode/extensions/ms-python.python-2020.1.58038/pythonFiles/lib/python/old_ptvsd/ptvsd/__main__.py", line 432, in main
    run()
  File "/root/.vscode/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 "/root/anaconda3/lib/python3.7/runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "/root/anaconda3/lib/python3.7/runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/root/anaconda3/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/mnt/s3user/Pytorch_Retinaface_quantized/train.py", line 303, in &lt;module&gt;
    torch.jit.save(torch.jit.script(quantized_model), save_folder + cfg['name'] + '_Final_quantized_jit.pth')
  File "/root/anaconda3/lib/python3.7/site-packages/torch/jit/__init__.py", line 1255, in script
    return torch.jit._recursive.recursive_script(obj)
  File "/root/anaconda3/lib/python3.7/site-packages/torch/jit/_recursive.py", line 534, in recursive_script
    return create_script_module(nn_module, infer_methods_to_compile(nn_module))
  File "/root/anaconda3/lib/python3.7/site-packages/torch/jit/_recursive.py", line 296, in create_script_module
    return create_script_module_impl(nn_module, concrete_type, cpp_module, stubs)
  File "/root/anaconda3/lib/python3.7/site-packages/torch/jit/_recursive.py", line 336, in create_script_module_impl
    script_module = torch.jit.RecursiveScriptModule._construct(cpp_module, init_fn)
  File "/root/anaconda3/lib/python3.7/site-packages/torch/jit/__init__.py", line 1593, in _construct
    init_fn(script_module)
  File "/root/anaconda3/lib/python3.7/site-packages/torch/jit/_recursive.py", line 328, in init_fn
    scripted = recursive_script(orig_value)
  File "/root/anaconda3/lib/python3.7/site-packages/torch/jit/_recursive.py", line 534, in recursive_script
    return create_script_module(nn_module, infer_methods_to_compile(nn_module))
  File "/root/anaconda3/lib/python3.7/site-packages/torch/jit/_recursive.py", line 296, in create_script_module
    return create_script_module_impl(nn_module, concrete_type, cpp_module, stubs)
  File "/root/anaconda3/lib/python3.7/site-packages/torch/jit/_recursive.py", line 336, in create_script_module_impl
    script_module = torch.jit.RecursiveScriptModule._construct(cpp_module, init_fn)
  File "/root/anaconda3/lib/python3.7/site-packages/torch/jit/__init__.py", line 1593, in _construct
    init_fn(script_module)
  File "/root/anaconda3/lib/python3.7/site-packages/torch/jit/_recursive.py", line 316, in init_fn
    cpp_module.setattr(name, orig_value)
RuntimeError: Unable to cast Python instance of type &lt;class 'int'&gt; to C++ type 'std::string'

</code></pre>
<p>What happened? how am I supposed to fix this ?<br>
I’d greatly appreciate if anyone could shed some light on this.<br>
Thank you all in advance</p>