From eb7b0ddd7dc6901357c8fb9e92c9ef7bafd0b607 Mon Sep 17 00:00:00 2001 From: Yang Zhang Date: Thu, 27 Feb 2020 19:02:33 +0800 Subject: [PATCH] Force `cudnn` backend for depthwise convs when fp16 is enabled (#270) --- ppdet/modeling/backbones/blazenet.py | 14 ++++++++------ ppdet/modeling/backbones/mobilenet.py | 4 +++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ppdet/modeling/backbones/blazenet.py b/ppdet/modeling/backbones/blazenet.py index 8b4f63db3..d3987521a 100644 --- a/ppdet/modeling/backbones/blazenet.py +++ b/ppdet/modeling/backbones/blazenet.py @@ -19,6 +19,7 @@ from __future__ import print_function from paddle import fluid from paddle.fluid.param_attr import ParamAttr +from ppdet.experimental import mixed_precision_global_state from ppdet.core.workspace import register __all__ = ['BlazeNet'] @@ -151,6 +152,7 @@ class BlazeNet(object): use_pool = not stride == 1 use_double_block = double_channels is not None act = 'relu' if use_double_block else None + mixed_precision_enabled = mixed_precision_global_state() is not None if use_5x5kernel: conv_dw = self._conv_norm( @@ -160,7 +162,7 @@ class BlazeNet(object): stride=stride, padding=2, num_groups=in_channels, - use_cudnn=False, + use_cudnn=mixed_precision_enabled, name=name + "1_dw") else: conv_dw_1 = self._conv_norm( @@ -170,7 +172,7 @@ class BlazeNet(object): stride=1, padding=1, num_groups=in_channels, - use_cudnn=False, + use_cudnn=mixed_precision_enabled, name=name + "1_dw_1") conv_dw = self._conv_norm( input=conv_dw_1, @@ -179,7 +181,7 @@ class BlazeNet(object): stride=stride, padding=1, num_groups=in_channels, - use_cudnn=False, + use_cudnn=mixed_precision_enabled, name=name + "1_dw_2") conv_pw = self._conv_norm( @@ -199,7 +201,7 @@ class BlazeNet(object): num_filters=out_channels, stride=1, padding=2, - use_cudnn=False, + use_cudnn=mixed_precision_enabled, name=name + "2_dw") else: conv_dw_1 = self._conv_norm( @@ -209,7 +211,7 @@ class BlazeNet(object): stride=1, padding=1, num_groups=out_channels, - use_cudnn=False, + use_cudnn=mixed_precision_enabled, name=name + "2_dw_1") conv_dw = self._conv_norm( input=conv_dw_1, @@ -218,7 +220,7 @@ class BlazeNet(object): stride=1, padding=1, num_groups=out_channels, - use_cudnn=False, + use_cudnn=mixed_precision_enabled, name=name + "2_dw_2") conv_pw = self._conv_norm( diff --git a/ppdet/modeling/backbones/mobilenet.py b/ppdet/modeling/backbones/mobilenet.py index 56afdf964..e275fe1f1 100644 --- a/ppdet/modeling/backbones/mobilenet.py +++ b/ppdet/modeling/backbones/mobilenet.py @@ -20,6 +20,7 @@ from paddle import fluid from paddle.fluid.param_attr import ParamAttr from paddle.fluid.regularizer import L2Decay +from ppdet.experimental import mixed_precision_global_state from ppdet.core.workspace import register __all__ = ['MobileNet'] @@ -104,6 +105,7 @@ class MobileNet(object): stride, scale, name=None): + mixed_precision_enabled = mixed_precision_global_state() is not None depthwise_conv = self._conv_norm( input=input, filter_size=3, @@ -111,7 +113,7 @@ class MobileNet(object): stride=stride, padding=1, num_groups=int(num_groups * scale), - use_cudnn=False, + use_cudnn=mixed_precision_enabled, name=name + "_dw") pointwise_conv = self._conv_norm( -- GitLab