NVIDIA / NVIDIA/apex

O1 opt_level patches pytorch calls outside wrapped modules.

Open
#501 1 comment 5 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

If you initialize some (but not all) modules with AMP opt level O1, all pytorch calls are now patched, even those outside wrapped modules. I'm not sure if this is intentional or a bug, but the behavior was definitely unexpected.

(to be clear, I know that O1 patches torch functions, but the fact that it patches torch functions outside modules passed to amp.initialize() was the surprise)

Example

import torch as th
from apex import amp

f = th.nn.Conv2d(3, 3, 3, 1, 1).cuda()
g = th.nn.Conv2d(3, 3, 3, 1, 1).cuda()
x = th.zeros(1, 3, 32, 32).cuda()
print(f(x).dtype, g(x).dtype)

f, = amp.initialize([f], opt_level="O1")
print(f(x).dtype, g(x).dtype)

prints torch.float16 torch.float16 even though g was not wrapped.

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 by reproducing the provided example with AMP opt level O1, comparing the dtypes of calls through f and the unwrapped g. Trace the O1 initialization and patching behavior to determine whether calls outside modules passed to amp.initialize() should be affected. Done means the behavior is clarified and covered by an appropriate regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.