ValueError: malformed node or string

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

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

On loading the model, I’m getting errors.

  Traceback (most recent call last):
  File "/content/Wav2Keyword/", line 39, in <module>
    cfg = convert_namespace_to_omegaconf(state_dict['args'])
  File "/content/Wav2Keyword/fairseq/dataclass/", line 337, in convert_namespace_to_omegaconf
    overrides, deletes = override_module_args(args)
  File "/content/Wav2Keyword/fairseq/dataclass/", line 280, in override_module_args
    _override_attr(k, FairseqConfig.__dataclass_fields__[k].type, args)
  File "/content/Wav2Keyword/fairseq/dataclass/", line 226, in _override_attr
    val = ast.literal_eval(val)
  File "/usr/lib/python3.9/", line 105, in literal_eval
    return _convert(node_or_string)
  File "/usr/lib/python3.9/", line 104, in _convert
    return _convert_signed_num(node)
  File "/usr/lib/python3.9/", line 78, in _convert_signed_num
    return _convert_num(node)
  File "/usr/lib/python3.9/", line 69, in _convert_num
  File "/usr/lib/python3.9/", 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?


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

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

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.