Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add use_mkldnn attribute to ops in dygraph #25773

Conversation

sfraczek
Copy link
Contributor

PR types

New features

PR changes

APIs

Describe

Adds use_mkldnn argument to ops, similarly to how use_cudnn is used. In Dygraph mode, setting global FLAGS_use_mkldnn=true enables mkldnn for all supported operators. If it is desired to have non-mkldnn op when FLAGS_use_mkldnn=true, it can be done by passing use_mkldnn=False to Op as argument.

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@sfraczek sfraczek added dygraph issues related to dygraph mode Intel labels Jul 28, 2020
@@ -11322,7 +11322,7 @@ def scale(x, scale=1.0, bias=0.0, bias_after_scale=True, act=None, name=None):
return helper.append_activation(out)


def elementwise_add(x, y, axis=-1, act=None, name=None):
def elementwise_add(x, y, axis=-1, act=None, name=None, use_mkldnn=False):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fate of this line shall be decided after we resolve the issue discussed here: #25713 (comment)

@sfraczek sfraczek mentioned this pull request Jul 28, 2020
@grygielski
Copy link
Contributor

@luotao1 As suggested here (#25713 (comment)), I've changed a way oneDNN is called from .../layers/nn.py/ to use FLAGS_use_mkldnn. Please let me know if you are fine with this solution.

@grygielski
Copy link
Contributor

grygielski commented Aug 7, 2020

@luotao1 Could you send me logs of MAC_PR_CI_python35 or rerun if it's a random fail?

@luotao1
Copy link
Contributor

luotao1 commented Aug 7, 2020

[12:40:59][Step 1/1] 697/904 Test #700: test_slice_var .......................................................***Failed    2.98 sec
[12:40:59][Step 1/1] test_slice_var failed
[12:40:59][Step 1/1]  .E
[12:40:59][Step 1/1] ======================================================================
[12:40:59][Step 1/1] ERROR: test_check_output_8k (test_slice_var.TestSliceVar)
[12:40:59][Step 1/1] ----------------------------------------------------------------------
[12:40:59][Step 1/1] Traceback (most recent call last):
[12:40:59][Step 1/1]   File "/home/teamcity/work/37d0fbdf11d96284/build/python/paddle/fluid/tests/unittests/test_slice_var.py", line 61, in test_check_output_8k
[12:40:59][Step 1/1]     self.check_slice_output(shapes, expected_sizes, 8192)
[12:40:59][Step 1/1]   File "/home/teamcity/work/37d0fbdf11d96284/build/python/paddle/fluid/tests/unittests/test_slice_var.py", line 33, in check_slice_output
[12:40:59][Step 1/1]     shape=shape)
[12:40:59][Step 1/1]   File "/home/teamcity/work/37d0fbdf11d96284/build/python/paddle/fluid/framework.py", line 2640, in create_var
[12:40:59][Step 1/1]     var = Variable(block=self, *args, **kwargs)
[12:40:59][Step 1/1]   File "/home/teamcity/work/37d0fbdf11d96284/build/python/paddle/fluid/framework.py", line 930, in __init__
[12:40:59][Step 1/1]     "matched.".format(self.name, old_shape, shape))
[12:40:59][Step 1/1] ValueError: Variable 45858 has been created before. the previous shape is (8, 1020); the new shape is (800, 10). They are not matched.
[12:40:59][Step 1/1] 
[12:40:59][Step 1/1] ----------------------------------------------------------------------
[12:40:59][Step 1/1] Ran 2 tests in 0.003s
[12:40:59][Step 1/1] 
[12:40:59][Step 1/1] FAILED (errors=1)

It seems not random fail, but I rerun it again for you.

@lelelelelez
Copy link
Contributor

@grygielski you can download this log by https://paddle-docker-tar.cdn.bcebos.com/buildLog/386139.log

jczaja
jczaja previously approved these changes Aug 10, 2020
Copy link
Contributor

@jczaja jczaja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@luotao1
Copy link
Contributor

luotao1 commented Aug 11, 2020

2020-08-06 20:00:32 
2020-08-06 20:00:34 ****************
2020-08-06 20:00:34 0. You must have one RD (XiaoguangHu01 or lanxianghit) and one TPM (saxon-zh or jzhang533 or swtkiwi or Heeenrrry or TCChenlong) approval for the api change for the management reason of API interface.
2020-08-06 20:00:34 1. You must have one TPM (saxon-zh or jzhang533 or swtkiwi or Heeenrrry or TCChenlong) approval for the api change for the management reason of API document.
2020-08-06 20:00:34 
2020-08-06 20:00:34 There are 2 approved errors.
2020-08-06 20:00:34 ****************
2020-08-06 20:00:34 API Difference is: 
2020-08-06 20:00:34 - paddle.fluid.dygraph.Conv2D (paddle.fluid.dygraph.nn.Conv2D, ('document', 'eaf7f009cbb4ce2f03453b767b8e3286'))
2020-08-06 20:00:34 ?                                                                            ^^   ^^ --    ^ ----- ^^^^ -----
2020-08-06 20:00:34 
2020-08-06 20:00:34 + paddle.fluid.dygraph.Conv2D (paddle.fluid.dygraph.nn.Conv2D, ('document', 'c1fc780ffd5769b4c16e71608c77fbf8'))
2020-08-06 20:00:34 ?                                                                            ^^ + ++ ^^^^^    ++ ^^^^^^^^  ^
2020-08-06 20:00:34 
2020-08-06 20:00:34 - paddle.fluid.dygraph.Conv2D.__init__ (ArgSpec(args=['self', 'num_channels', 'num_filters', 'filter_size', 'stride', 'padding', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'dtype'], varargs=None, keywords=None, defaults=(1, 0, 1, None, None, None, True, None, 'float32')), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
2020-08-06 20:00:34 + paddle.fluid.dygraph.Conv2D.__init__ (ArgSpec(args=['self', 'num_channels', 'num_filters', 'filter_size', 'stride', 'padding', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'use_mkldnn', 'act', 'dtype'], varargs=None, keywords=None, defaults=(1, 0, 1, None, None, None, True, True, None, 'float32')), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
2020-08-06 20:00:34 ?                                                                                                                                                                                               ++++++++++++++                                                                               ++++++
2020-08-06 20:00:34 
2020-08-06 20:00:34 - paddle.fluid.dygraph.Pool2D (paddle.fluid.dygraph.nn.Pool2D, ('document', '1a697b10e08b443dc2865bfa1e1422a5'))
2020-08-06 20:00:34 ?                                                                               -----  ^^  ^ ----------------
2020-08-06 20:00:34 
2020-08-06 20:00:34 + paddle.fluid.dygraph.Pool2D (paddle.fluid.dygraph.nn.Pool2D, ('document', '28cc18bbe69ffb12e449a6e0344baebd'))
2020-08-06 20:00:34 ?                                                                            ++++ +++++++++++++++    ^  ^^^^
2020-08-06 20:00:34 
2020-08-06 20:00:34 - paddle.fluid.dygraph.Pool2D.__init__ (ArgSpec(args=['self', 'pool_size', 'pool_type', 'pool_stride', 'pool_padding', 'global_pooling', 'use_cudnn', 'ceil_mode', 'exclusive', 'data_format'], varargs=None, keywords=None, defaults=(-1, 'max', 1, 0, False, True, False, True, 'NCHW')), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
2020-08-06 20:00:34 + paddle.fluid.dygraph.Pool2D.__init__ (ArgSpec(args=['self', 'pool_size', 'pool_type', 'pool_stride', 'pool_padding', 'global_pooling', 'use_cudnn', 'use_mkldnn', 'ceil_mode', 'exclusive', 'data_format'], varargs=None, keywords=None, defaults=(-1, 'max', 1, 0, False, True, True, False, True, 'NCHW')), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
2020-08-06 20:00:34 ?                                                                                                                                               ++++++++++++++                                                                                                            ++++++
2020-08-06 20:00:34 
2020-08-06 20:00:34 - paddle.fluid.dygraph.Linear (paddle.fluid.dygraph.nn.Linear, ('document', 'db61dfab21ff2bd3984cccdfcb559570'))
2020-08-06 20:00:34 ?                                                                            ^^^^^^^^^^^^^^^ --   ^   ^^^ ^^
2020-08-06 20:00:34 
2020-08-06 20:00:34 + paddle.fluid.dygraph.Linear (paddle.fluid.dygraph.nn.Linear, ('document', '84844734ccb96fadf34fbce9f2a8acf0'))
2020-08-06 20:00:34 ?                                                                            ^^^^^^    ^^^^^  ++++ ^ ^^^^^^^
2020-08-06 20:00:34 
2020-08-06 20:00:34 - paddle.fluid.dygraph.Linear.__init__ (ArgSpec(args=['self', 'input_dim', 'output_dim', 'param_attr', 'bias_attr', 'act', 'dtype'], varargs=None, keywords=None, defaults=(None, None, None, 'float32')), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
2020-08-06 20:00:34 + paddle.fluid.dygraph.Linear.__init__ (ArgSpec(args=['self', 'input_dim', 'output_dim', 'param_attr', 'bias_attr', 'act', 'dtype', 'use_mkldnn'], varargs=None, keywords=None, defaults=(None, None, None, 'float32', True)), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
2020-08-06 20:00:34 ?                                                                                                                                ++++++++++++++                                                                      ++++++
2020-08-06 20:00:34 
2020-08-06 20:00:34 - paddle.fluid.dygraph.BatchNorm (paddle.fluid.dygraph.nn.BatchNorm, ('document', 'e29cbd4c024975a79f1980cebacc4651'))
2020-08-06 20:00:34 ?                                                                                  ^  ^^^^^^^^^^^^^^    ^^ ---- ^^^
2020-08-06 20:00:34 
2020-08-06 20:00:34 + paddle.fluid.dygraph.BatchNorm (paddle.fluid.dygraph.nn.BatchNorm, ('document', '8882593f14f554039a93c664f7f8be43'))
2020-08-06 20:00:34 ?                                                                                  ^^^ + ^  +++++++ ++++++++++ ^  ^
2020-08-06 20:00:34 
2020-08-06 20:00:34 - paddle.fluid.dygraph.BatchNorm.__init__ (ArgSpec(args=['self', 'num_channels', 'act', 'is_test', 'momentum', 'epsilon', 'param_attr', 'bias_attr', 'dtype', 'data_layout', 'in_place', 'moving_mean_name', 'moving_variance_name', 'do_model_average_for_mean_and_var', 'use_global_stats', 'trainable_statistics'], varargs=None, keywords=None, defaults=(None, False, 0.9, 1e-05, None, None, 'float32', 'NCHW', False, None, None, True, False, False)), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
2020-08-06 20:00:34 + paddle.fluid.dygraph.BatchNorm.__init__ (ArgSpec(args=['self', 'num_channels', 'act', 'is_test', 'momentum', 'epsilon', 'param_attr', 'bias_attr', 'dtype', 'data_layout', 'in_place', 'moving_mean_name', 'moving_variance_name', 'do_model_average_for_mean_and_var', 'use_global_stats', 'trainable_statistics', 'use_mkldnn'], varargs=None, keywords=None, defaults=(None, False, 0.9, 1e-05, None, None, 'float32', 'NCHW', False, None, None, True, False, False, True)), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
2020-08-06 20:00:34 ?                                                                                                                                                                                                                                                                                                                   ++++++++++++++                                                                                                                                      ++++++
2020-08-06 20:00:34 
2020-08-06 20:00:34 - paddle.nn.BatchNorm (paddle.fluid.dygraph.nn.BatchNorm, ('document', 'e29cbd4c024975a79f1980cebacc4651'))
2020-08-06 20:00:34 ?                                                                       ^  ^^^^^^^^^^^^^^    ^^ ---- ^^^
2020-08-06 20:00:34 
2020-08-06 20:00:34 + paddle.nn.BatchNorm (paddle.fluid.dygraph.nn.BatchNorm, ('document', '8882593f14f554039a93c664f7f8be43'))
2020-08-06 20:00:34 ?                                                                       ^^^ + ^  +++++++ ++++++++++ ^  ^
2020-08-06 20:00:34 
2020-08-06 20:00:34 - paddle.nn.BatchNorm.__init__ (ArgSpec(args=['self', 'num_channels', 'act', 'is_test', 'momentum', 'epsilon', 'param_attr', 'bias_attr', 'dtype', 'data_layout', 'in_place', 'moving_mean_name', 'moving_variance_name', 'do_model_average_for_mean_and_var', 'use_global_stats', 'trainable_statistics'], varargs=None, keywords=None, defaults=(None, False, 0.9, 1e-05, None, None, 'float32', 'NCHW', False, None, None, True, False, False)), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
2020-08-06 20:00:34 + paddle.nn.BatchNorm.__init__ (ArgSpec(args=['self', 'num_channels', 'act', 'is_test', 'momentum', 'epsilon', 'param_attr', 'bias_attr', 'dtype', 'data_layout', 'in_place', 'moving_mean_name', 'moving_variance_name', 'do_model_average_for_mean_and_var', 'use_global_stats', 'trainable_statistics', 'use_mkldnn'], varargs=None, keywords=None, defaults=(None, False, 0.9, 1e-05, None, None, 'float32', 'NCHW', False, None, None, True, False, False, True)), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
2020-08-06 20:00:34 ?                                                                                                                                                                                                                                                                                                       ++++++++++++++                                                                                                                                       ++++++
2020-08-06 20:00:34 
2020-08-06 20:00:34 - paddle.nn.Pool2D (paddle.fluid.dygraph.nn.Pool2D, ('document', '1a697b10e08b443dc2865bfa1e1422a5'))
2020-08-06 20:00:34 ?                                                                    -----  ^^  ^ ----------------
2020-08-06 20:00:34 
2020-08-06 20:00:34 + paddle.nn.Pool2D (paddle.fluid.dygraph.nn.Pool2D, ('document', '28cc18bbe69ffb12e449a6e0344baebd'))
2020-08-06 20:00:34 ?                                                                 ++++ +++++++++++++++    ^  ^^^^
2020-08-06 20:00:34 
2020-08-06 20:00:34 - paddle.nn.Pool2D.__init__ (ArgSpec(args=['self', 'pool_size', 'pool_type', 'pool_stride', 'pool_padding', 'global_pooling', 'use_cudnn', 'ceil_mode', 'exclusive', 'data_format'], varargs=None, keywords=None, defaults=(-1, 'max', 1, 0, False, True, False, True, 'NCHW')), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
2020-08-06 20:00:34 + paddle.nn.Pool2D.__init__ (ArgSpec(args=['self', 'pool_size', 'pool_type', 'pool_stride', 'pool_padding', 'global_pooling', 'use_cudnn', 'use_mkldnn', 'ceil_mode', 'exclusive', 'data_format'], varargs=None, keywords=None, defaults=(-1, 'max', 1, 0, False, True, True, False, True, 'NCHW')), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
2020-08-06 20:00:34 ?                                                                                                                                    ++++++++++++++                                                                                                            ++++++
2020-08-06 20:00:34 
2020-08-06 20:00:34 - paddle.nn.Linear (paddle.fluid.dygraph.nn.Linear, ('document', 'db61dfab21ff2bd3984cccdfcb559570'))
2020-08-06 20:00:34 ?                                                                 ^^^^^^^^^^^^^^^ --   ^   ^^^ ^^
2020-08-06 20:00:34 
2020-08-06 20:00:34 + paddle.nn.Linear (paddle.fluid.dygraph.nn.Linear, ('document', '84844734ccb96fadf34fbce9f2a8acf0'))
2020-08-06 20:00:34 ?                                                                 ^^^^^^    ^^^^^  ++++ ^ ^^^^^^^
2020-08-06 20:00:34 
2020-08-06 20:00:34 - paddle.nn.Linear.__init__ (ArgSpec(args=['self', 'input_dim', 'output_dim', 'param_attr', 'bias_attr', 'act', 'dtype'], varargs=None, keywords=None, defaults=(None, None, None, 'float32')), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
2020-08-06 20:00:34 + paddle.nn.Linear.__init__ (ArgSpec(args=['self', 'input_dim', 'output_dim', 'param_attr', 'bias_attr', 'act', 'dtype', 'use_mkldnn'], varargs=None, keywords=None, defaults=(None, None, None, 'float32', True)), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
2020-08-06 20:00:34 ?                                                                                                                      ++++++++++++++                                                                     ++++++
2020-08-06 20:00:34 
2020-08-06 20:00:36 + approval_error=1
2020-08-06 20:00:36 + '[' 1 '!=' 0 ']'

@@ -810,6 +831,7 @@ def __init__(self,
pool_padding=0,
global_pooling=False,
use_cudnn=True,
use_mkldnn=True,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we use FLAGS_use_mkldnn to global control, do you need to add use_mkldnn attribute in each API?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understood our agreement, we didn't want to add use_mkldnn attribute in standard op API, thus we have decided to use Flags here. However for dygraph ops we wanted to be able to control every op whether it should be executed with oneDNN or not. Similarly these ops have use_cuda attribute. Am I wrong?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phlrain What's your opinion about it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However for dygraph ops we wanted to be able to control every op whether it should be executed with oneDNN or not

@grygielski Discussed with @phlrain, we think FLAGS_use_mkldnn is enough for dygraph, we don't need to control every op whether it should be executed with oneDNN or not

@grygielski grygielski force-pushed the add-use_mkldnn-attribute-to-ops-in-dygraph branch 2 times, most recently from 3584eb0 to 0da66fd Compare August 17, 2020 09:22
@grygielski grygielski force-pushed the add-use_mkldnn-attribute-to-ops-in-dygraph branch 2 times, most recently from 480ed1d to 086604c Compare August 17, 2020 09:33
@grygielski
Copy link
Contributor

@luotao1 I've removed use_mkldnn attribute from all operators. I didn't delete it from dygraph_utils.py. Let me know if you are fine with that.

Copy link
Contributor

@luotao1 luotao1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

@wojtuss wojtuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@luotao1 luotao1 merged commit abfdffa into PaddlePaddle:develop Aug 18, 2020
@sfraczek sfraczek deleted the add-use_mkldnn-attribute-to-ops-in-dygraph branch September 1, 2020 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dygraph issues related to dygraph mode Intel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants