NVIDIA / NVIDIA/apex

Should amp.initialize be called on model not having it's weights updated

Open
#898 0 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

I'm performing training where I have 2 copies of a model

  • The main model, the one on which the gradients are used to make weight updates
  • A second model which is used in calculating the loss function, but does not have it's weights updated.

My crude version of my code looks something like this

stock_model = copy.deepcopy(model)
model, optimizer = amp.initialize(model, optimizer, opt_level=args.fp16_opt_level)
.
.
for _ in range(num_epochs):
    for x in dataloader:
        out = model(x)
        with torch.no_grad():
            out_stock = model(x)
        loss = loss_fn(out, out_stock)

        with amp.scale_loss(loss, optimizer) as scaled_loss:
            scaled_loss.backward()
        
        optimizer.step()
        model.zero_grad()

As you can see, stock_model is used in the loss calculation, but it's weights aren't updated. Should it be sent to amp.initialize as well?

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

Start at the amp.initialize and amp.scale_loss entry points mentioned in the issue, and trace how each model is handled during mixed-precision training. Confirm whether the non-updated stock_model also requires initialization, and document the expected setup or behavior for this two-model loss calculation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Bug
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.