state_dict['args'] empty when trying to load

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

state_dict = torch.load(model_name.pt)
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/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

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

Versions

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
CUDA_MODULE_LOADING set to:
GPU models and configuration: GPU 0: Tesla V100-SXM2-32GB
Nvidia driver version: 525.60.13
cuDNN version: /usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.3
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

Thanks

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(model.pt)
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()
sd["args"]
# 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