mmyolo icon indicating copy to clipboard operation
mmyolo copied to clipboard

fix fx tracer to support alpha in RepVGGBlock

Open twmht opened this issue 10 months ago • 1 comments

Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily get feedback. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.

Motivation

Can't fx.trace with PPYOLOECSPResNet when use_alpha=True

minimal reproducible script.

from mmrazor.models.task_modules.tracer.channel_analyzer import ChannelAnalyzer
from mmrazor.implementations.pruning.group_fisher import GroupFisherChannelMutator
from mmyolo.models.backbones import PPYOLOECSPResNet
from torch.fx import symbolic_trace

normalization_type='act'
analyzer=ChannelAnalyzer(tracer_type='FxTracer')
mutator=GroupFisherChannelMutator(channel_unit_cfg=dict(type='GroupFisherChannelUnit', default_args=dict(normalization_type=normalization_type)), parse_cfg=dict(type='ChannelAnalyzer', tracer_type='FxTracer'))
#  model=ResNet(depth=18)
deepen_factor = 0.33
widen_factor = 0.5
model=PPYOLOECSPResNet(
        deepen_factor=deepen_factor,
        widen_factor=widen_factor,
        block_cfg=dict(
            type='PPYOLOEBasicBlock', shortcut=True, use_alpha=True),
        norm_cfg=dict(type='BN', momentum=0.1, eps=1e-5),
        act_cfg=dict(type='SiLU', inplace=True),
        attention_cfg=dict(
            type='EffectiveSELayer', act_cfg=dict(type='HSigmoid')),
        use_large_stem=True)
print(model)
module=symbolic_trace(model)

Modification

don't use traced tensor in the control flow

BC-breaking (Optional)

Does the modification introduce changes that break the backward compatibility of the downstream repos? If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR.

Use cases (Optional)

If this PR introduces a new feature, it is better to list some use cases here and update the documentation.

Checklist

  1. Pre-commit or other linting tools are used to fix potential lint issues.
  2. The modification is covered by complete unit tests. If not, please add more unit tests to ensure the correctness.
  3. If the modification has a potential influence on downstream projects, this PR should be tested with downstream projects, like MMDetection or MMClassification.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

twmht avatar Aug 29 '23 03:08 twmht

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar Aug 29 '23 03:08 CLAassistant