deepspeedai / deepspeedai/DeepSpeed

Flops profiler does not account for overloaded operators

Open
#3,087 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
43.1k
Forks
5k
Avg merge
4d 15h
Merged PRs (30d)
112

Description

I was getting some weird results with my profiling results, and dug a bit deeper to find out that overloaded python operators (e.g. *, +) were not getting properly evaluated by the get_model_profile method. The following is a simple script to reproduce my results.

import torch
from deepspeed.profiling.flops_profiler.profiler import get_model_profile
from torch import nn


class SimpleAdder(nn.Module):
    def forward(self, x):
        return x + x


class SimpleAdder2(nn.Module):
    def forward(self, x):
        return torch.add(x, x)


flops, macs, params = get_model_profile(SimpleAdder(), input_shape=(1, 2, 10), print_profile=False)
print(flops)

flops, macs, params = get_model_profile(SimpleAdder2(), input_shape=(1, 2, 10), print_profile=False)
print(flops)

Output

0
20 # this is what I would expect

Due to the improved readability of using the overloaded operators, it is likely that many different models (especially those with residual blocks) suffer from a similar problem.

Contributor guide

Open the contributing guide

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 SimpleAdder and SimpleAdder2 reproducer and trace get_model_profile in deepspeed.profiling.flops_profiler.profiler. Compare how overloaded Python operators and torch.add are evaluated, then verify that both examples report the expected FLOPs and that existing profiler behavior remains intact.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.