DeepSpeed icon indicating copy to clipboard operation
DeepSpeed copied to clipboard

TypeError: _upsample_flops_compute() takes 1 positional argument but 5 were given

Open pikaliov opened this issue 1 year ago • 1 comments

Describe the bug I use script for standalone profiler models from deepspeed. Some of models used from repos: cvnets and timm. So for 2 of them I couldnt get info cause of errors.

This is error for efficientformer_v2 model: https://github.com/huggingface/pytorch-image-models/blob/e7ef8335bf7322516e8bce199baefccf26a330b2/timm/models/efficientformer_v2.py

https://imgur.com/a/oatJ1M9

TypeError: _upsample_flops_compute() takes 1 positional argument but 5 were given

There is point to error.

deepspeed/profiling/flops_profiler/profiler.py

def wrapFunc(func, funcFlopCompute):
    oldFunc = func
    name = func.__str__
    old_functions[name] = oldFunc

    def newFunc(*args, **kwds):
        flops, macs = funcFlopCompute(*args, **kwds)
        if module_flop_count:
            module_flop_count[-1].append((name, flops))
        if module_mac_count and macs:
            module_mac_count[-1].append((name, macs))
        return oldFunc(*args, **kwds)

    newFunc.__str__ = func.__str__

    return newFunc

def _patch_functionals():
   ....
   # upsample
   F.upsample = wrapFunc(F.upsample, _upsample_flops_compute)
   F.interpolate = wrapFunc(F.interpolate, _upsample_flops_compute)
   ...

System info Google Collab

  • GPU: Tesla T4
  • Deepspped version: 0.8.3
  • Python version: 3.9.16

pikaliov avatar Mar 26 '23 17:03 pikaliov

The library has this wrapper for interpolate (and upsample),   F.interpolate = wrapFunc(F.interpolate, _upsample_flops_compute)

And in the def, they take input as position only and rest as variable kwargs: def _upsample_flops_compute(input, **kwargs):

So, you can solve this by specifying the names of other inputs arguments from second onwards.

gauravmunjal13 avatar Apr 19 '23 14:04 gauravmunjal13

Hi @gauravmunjal13 , thanks for pointing out this issue. It shall be fixed by https://github.com/microsoft/DeepSpeed/pull/3782

cli99 avatar Jun 21 '23 17:06 cli99