NVIDIA / NVIDIA/apex

amp opt_level=O0/O2/O3 results different after calling O1 in the same program

Open
#896 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

Hello,
I'm testing the speedup with amp with matmul operation on tesla v100(gcp). This is my code

class Matmul(torch.nn.Module):
    def __init__(self, n):
        super(Matmul, self).__init__()
        self.a = torch.randn(n, n).cuda()
        self.b = torch.randn(n, n).cuda()
    
    def forward(self):
        return torch.matmul(self.a, self.b)
    
def get_speed(n, num, use_amp=False, amp_opt_level='O1'):
    matmul = Matmul(n).cuda()
    if use_amp:
        from apex import amp
        matmul = amp.initialize(matmul, opt_level=amp_opt_level)
    else:
        amp = None
    start_time = time.time()
    for i in range(num):
        matmul()
    print('Finished in {:.3f} s.'.format(time.time() - start_time))
    matmul = None

I ran all these in one jupyter notebook: when I use opt_level=O0/O2/O3 before O1 I got
image
image

(no speedup)

I got 4x speedup with O1:
image

I got the same results when running them separately in the terminal.

However, when I use opt_level=O0/O2/O3 after O1 their speeds changed:
image

image

Is there any reason for that? Which result is correct?

Thank you.

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 with the provided get_speed benchmark and the amp.initialize entry point, running the opt_level cases in the reported orders in both the Jupyter notebook and terminal. Compare the timing results and determine which behavior is expected, documenting the cause and the correct result.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.