question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Saving wav2vec2 model results in serialization error

See original GitHub issue

Hi,

I am trying to save the compiled model using the code below:

w2v = torch.load(model_path)
model = Wav2VecCtc.build_model(args, target_dict)
model.load_state_dict(w2v["model"], strict=True)
torch.save(model, 'test_again.pt' )

But whenever I execute this code, the model is built successfully but it throws an error:

Screenshot 2021-04-24 at 3 11 36 AM

This error I did not encounter in non hydra version of fairseq. Can you please let me know what can be done??

Thanks!

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
minghao-wucommented, Jun 21, 2021

@villmow @harveenchadha Hi there,

Thank you very much for your solution, but it still doesn’t work on my code.

I insert your snippt into line 460 at fairseq/fairseq/dataclass/utils.py and my function look like this now:

def merge_with_parent(dc: FairseqDataclass, cfg: FairseqDataclass):
    cfg = OmegaConf.merge(
        OmegaConf.structured(
            dc
        ),
        OmegaConf.create(
            OmegaConf.to_yaml(cfg, resolve=True)
        )
    )
    merged_cfg = OmegaConf.merge(dc, cfg)
    merged_cfg.__dict__["_parent"] = cfg.__dict__["_parent"]
    OmegaConf.set_struct(merged_cfg, True)
    return merged_cfg

Is this the right way to use your snippt?

I am training my custom task using multiple GPUs and encountered a similar error.

More details can be found at https://github.com/pytorch/fairseq/issues/3634

Thanks again.

3reactions
villmowcommented, Apr 30, 2021

I receive the same error when training a model with fairseq-hydra-train on multiple GPUs. Single GPU works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Saving wav2vec2 model results in serialization error #3503
Hi, I am trying to save the compiled model using the code below: w2v = torch.load(model_path) model = Wav2VecCtc.build_model(args, ...
Read more >
Issues saving and loading wav2vec2 models fine tuned using ...
After training some toy models, I realized that I couldn't load from the checkpoints or save and reload the model in the same...
Read more >
Running out of memory with pytorch - Stack Overflow
After each model finishes their job, DataParallel collects and merges the results before returning it to you.
Read more >
Saving and loading models for inference in PyTorch
Saving the model's state_dict with the torch.save() function will give you ... The disadvantage of this approach is that the serialized data is...
Read more >
Wav2Vec2.0 on the Edge: Performance Evaluation | DeepAI
02/12/22 - Wav2Vec2.0 is a state-of-the-art model which learns speech ... The python based modules are optimized, serialized and saved in ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found