ValueError: malformed node or string

Hi,
I try to load the 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.

  Traceback (most recent call last):
  File "/content/Wav2Keyword/downstream_kws.py", line 39, in <module>
    cfg = convert_namespace_to_omegaconf(state_dict['args'])
  File "/content/Wav2Keyword/fairseq/dataclass/utils.py", line 337, in convert_namespace_to_omegaconf
    overrides, deletes = override_module_args(args)
  File "/content/Wav2Keyword/fairseq/dataclass/utils.py", line 280, in override_module_args
    _override_attr(k, FairseqConfig.__dataclass_fields__[k].type, args)
  File "/content/Wav2Keyword/fairseq/dataclass/utils.py", line 226, in _override_attr
    val = ast.literal_eval(val)
  File "/usr/lib/python3.9/ast.py", line 105, in literal_eval
    return _convert(node_or_string)
  File "/usr/lib/python3.9/ast.py", line 104, in _convert
    return _convert_signed_num(node)
  File "/usr/lib/python3.9/ast.py", line 78, in _convert_signed_num
    return _convert_num(node)
  File "/usr/lib/python3.9/ast.py", line 69, in _convert_num
    _raise_malformed_node(node)
  File "/usr/lib/python3.9/ast.py", line 66, in _raise_malformed_node
    raise ValueError(f'malformed node or string: {node!r}')
ValueError: malformed node or string: <ast.Name object at 0x7f50b3c82d60>

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

Thanks

Hi, the model checkpoint seems from fairseq, can you try using the load function in fairseq?

cp_path = '/path/to/wav2vec.pt'
model, cfg, task = fairseq.checkpoint_utils.load_model_ensemble_and_task([cp_path])
model = model[0]
model.eval()

Hi, basically i am trying to run this repository from GitHub

In this while running the python file, I got this error. Don’t know why this error occur.

Yes i am using the fairseq pretrained model.