Should amp.initialize be called on model not having it's weights updated
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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