Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit fb60f91

Browse files
committed
Enable operators fusion (Conv + BN + ReLu) in FBNet V2
Summary: Pull Request resolved: #592 X-link: facebookresearch/mobile-vision#172 The FBNet V2 consists of several basic blocks of pattern conv(2d) + BatchNorm + ReLU. These operators can be fused into one operator, greatly speeding up the computation in GPU. This diff / PR adds option to build an FBNet V2 backbone in fused manner, i.e. it looks up recursively the blocks and sub-blocks for the known patterns, and fuse them using `mobile_cv.arch.utils.fuse_utils` Differential Revision: D47395999 fbshipit-source-id: b3da40ade8b36238dc9920c59a638357d861f283
1 parent e4fa6d6 commit fb60f91

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

d2go/modeling/backbone/fbnet_cfg.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ def add_fbnet_v2_default_configs(_C):
6666
# https://github.com/rbgirshick/yacs/blob/master/yacs/config.py#L410
6767
_C.MODEL.FBNET_V2.NORM_ARGS = []
6868

69+
# Set up operators fusion option in the backbone's blocks
70+
_C.MODEL.FBNET_V2.FUSE_OPS = False
71+
6972
_C.MODEL.VT_FPN = CN()
7073

7174
_C.MODEL.VT_FPN.IN_FEATURES = ["res2", "res3", "res4", "res5"]

d2go/modeling/backbone/fbnet_v2.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,16 @@ def build_fbnet(cfg, name, in_channels):
197197
stages = []
198198
trunk_stride_per_stage = _get_stride_per_stage(arch_def_blocks)
199199
shape_spec_per_stage = []
200+
fuse_ops = getattr(cfg.MODEL.FBNET_V2, "FUSE_OPS", False)
201+
is_qat = getattr(cfg, "QAT", False)
200202
for i, stride_i in enumerate(trunk_stride_per_stage):
201203
stages.append(
202204
builder.build_blocks(
203205
arch_def_blocks,
204206
stage_indices=[i],
205207
prefix_name=FBNET_BUILDER_IDENTIFIER + "_",
208+
fuse_ops=fuse_ops,
209+
is_qat=is_qat,
206210
)
207211
)
208212
shape_spec_per_stage.append(

0 commit comments

Comments
 (0)