NVIDIA / NVIDIA/apex

How to export fp32 master weights with opt_level O2

Open
#665 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
9k
Forks
1.5k
Avg merge
2d 4h
Merged PRs (30d)
3

Description

My model is training with opt_level O2, but it will be used in fp32 mode. How can I save the state_dict of model?

For now, I just use

model, optimizer = amp.initialize(model, optimizer, opt_level="O2"
# train the model
torch.save(model.state_dict(), "model.pth")
# use the model in float32 mode

Should I do something to save the fp32 master weights rather than the model.state_dict() which has fp16 weights?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files or tests are named. Start with the Apex AMP entry point amp.initialize at opt_level="O2" and the model.state_dict() call, then check the project's guidance for checkpointing and fp32 master weights. Done means a documented, verified procedure for exporting weights that can be loaded for fp32 use.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.