state_dict['args'] empty when trying to load

csetanmayjain: <p>Hi,<br>
I try to load PyTorch model (specifically wav2vec2), using the following command:</p>
<pre><code class="lang-auto">state_dict = torch.load(model_name.pt)
arg = state_dict['args']
</code></pre>
<p>On loading the model, I’m getting errors, and when I tried to print the <code>arg</code> I found that it was empty.</p>
<pre><code class="lang-auto">  cfg = convert_namespace_to_omegaconf(state_dict['args'])
  File "/data/tanmay/Wav2Keyword/fairseq/dataclass/utils.py", line 371, in convert_namespace_to_omegaconf
    if cfg.model is None and getattr(args, "arch", None):
  File "/data/tanmay/py_ven_38/lib/python3.8/site-packages/omegaconf/dictconfig.py", line 305, in __getattr__
    self._format_and_raise(key=key, value=None, cause=e)
  File "/data/tanmay/py_ven_38/lib/python3.8/site-packages/omegaconf/base.py", line 95, in _format_and_raise
    format_and_raise(
  File "/data/tanmay/py_ven_38/lib/python3.8/site-packages/omegaconf/_utils.py", line 694, in format_and_raise
    _raise(ex, cause)
  File "/data/tanmay/py_ven_38/lib/python3.8/site-packages/omegaconf/_utils.py", line 610, in _raise
    raise ex  # set end OC_CAUSE=1 for full backtrace
omegaconf.errors.MissingMandatoryValue: Missing mandatory value: model
        full_key: model
        reference_type=Optional[Dict[Union[str, Enum], Any]]
        object_type=dict
</code></pre>
<p>What is the issue, and how can I resolve it?</p>
<h3>
<a name="versions-1" class="anchor" href="#versions-1"></a>Versions</h3>
<p>PyTorch version: 1.10.1+cu102<br>
Is debug build: False<br>
CUDA used to build PyTorch: 10.2<br>
ROCM used to build PyTorch: N/A</p>
<p>OS: Ubuntu 16.04.7 LTS (x86_64)<br>
GCC version: (Ubuntu 5.5.0-12ubuntu1~16.04) 5.5.0 20171010<br>
Clang version: Could not collect<br>
CMake version: version 3.5.2<br>
Libc version: glibc-2.23</p>
<p>Python version: 3.8.9 (default, Apr  3 2021, 01:02:10)  [GCC 5.4.0 20160609] (64-bit runtime)<br>
Python platform: Linux-4.4.0-21-generic-x86_64-with-glibc2.17<br>
Is CUDA available: True<br>
CUDA runtime version: 12.0.76<br>
CUDA_MODULE_LOADING set to:<br>
GPU models and configuration: GPU 0: Tesla V100-SXM2-32GB<br>
Nvidia driver version: 525.60.13<br>
cuDNN version: /usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.3<br>
HIP runtime version: N/A<br>
MIOpen runtime version: N/A<br>
Is XNNPACK available: True</p>
<p>Versions of relevant libraries:<br>
[pip3] numpy==1.23.5<br>
[pip3] torch==1.10.1<br>
[pip3] torchaudio==0.10.1<br>
[pip3] torchvision==0.11.2+rocm4.2<br>
[conda] Could not collect</p>
<p>Thanks</p>

ptrblck: <p>Could you check which <code>.keys()</code> the <code>state_dict</code> contains and could you also explain what <code>'args'</code> should return as it seems to be needed by <code>omegaconf</code>?</p>

gug: <p>could you try printing the <code>state_dict</code> variable?</p>

csetanmayjain: <p><code>state_dict</code> has <code>args</code> key but it’s empty.<br>
It is used for <code>omegaconf</code></p>
<p><code>state_dict = torch.load(model.pt)</code><br>
<code>cfg = convert_namespace_to_omegaconf(state_dict['args'])</code></p>

csetanmayjain: <p><code>state_dict</code> contains a long list of model parameters.<br>
But <code>state_dict</code> has <code>args</code> key but it’s empty.</p>

ptrblck: <p>How did you create the <code>state_dict</code> as the ones from e.g. <code>torchvision.models</code> do not contain the <code>'args'</code> key:</p>
<pre><code class="lang-python">model = models.resnet18()
sd = model.state_dict()
sd["args"]
# KeyError: 'args'
</code></pre>
<p>so I assume you have created a custom <code>dict</code> with this key?<br>
If so, check which object is assigned to it as it seems to be unexpectedly empty.</p>

csetanmayjain: <p>I use a wav2vec2 pre-trained model based on PyTorch.<br>
To be specific, I use this <a href="https://storage.googleapis.com/vakyansh-open-models/models/english/en-IN/enm_700.pt" rel="noopener nofollow ugc">model</a> from <a href="https://github.com/Open-Speech-EkStep/vakyansh-models#:~:text=hindi_ts-,Indian%20English,english_ts,-Kannada" rel="noopener nofollow ugc">here</a></p>
<p>While loading this model, I’m getting error</p>