state_dict['args'] empty when trying to load

I try to load PyTorch model (specifically wav2vec2), using the following command:

state_dict = torch.load(
arg = state_dict['args']

On loading the model, I’m getting errors, and when I tried to print the arg I found that it was empty.

  cfg = convert_namespace_to_omegaconf(state_dict['args'])
  File "/data/tanmay/Wav2Keyword/fairseq/dataclass/", 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/", 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/", line 95, in _format_and_raise
  File "/data/tanmay/py_ven_38/lib/python3.8/site-packages/omegaconf/", line 694, in format_and_raise
    _raise(ex, cause)
  File "/data/tanmay/py_ven_38/lib/python3.8/site-packages/omegaconf/", 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]]

What is the issue, and how can I resolve it?


PyTorch version: 1.10.1+cu102
Is debug build: False
CUDA used to build PyTorch: 10.2
ROCM used to build PyTorch: N/A

OS: Ubuntu 16.04.7 LTS (x86_64)
GCC version: (Ubuntu 5.5.0-12ubuntu1~16.04) 5.5.0 20171010
Clang version: Could not collect
CMake version: version 3.5.2
Libc version: glibc-2.23

Python version: 3.8.9 (default, Apr 3 2021, 01:02:10) [GCC 5.4.0 20160609] (64-bit runtime)
Python platform: Linux-4.4.0-21-generic-x86_64-with-glibc2.17
Is CUDA available: True
CUDA runtime version: 12.0.76
GPU models and configuration: GPU 0: Tesla V100-SXM2-32GB
Nvidia driver version: 525.60.13
cuDNN version: /usr/lib/x86_64-linux-gnu/
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] numpy==1.23.5
[pip3] torch==1.10.1
[pip3] torchaudio==0.10.1
[pip3] torchvision==0.11.2+rocm4.2
[conda] Could not collect


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

could you try printing the state_dict variable?

state_dict has args key but it’s empty.
It is used for omegaconf

state_dict = torch.load(
cfg = convert_namespace_to_omegaconf(state_dict['args'])

state_dict contains a long list of model parameters.
But state_dict has args key but it’s empty.

How did you create the state_dict as the ones from e.g. torchvision.models do not contain the 'args' key:

model = models.resnet18()
sd = model.state_dict()
# KeyError: 'args'

so I assume you have created a custom dict with this key?
If so, check which object is assigned to it as it seems to be unexpectedly empty.

I use a wav2vec2 pre-trained model based on PyTorch.
To be specific, I use this model from here

While loading this model, I’m getting error