File tree Expand file tree Collapse file tree 3 files changed +19
-2
lines changed
python/paddle/fluid/layers Expand file tree Collapse file tree 3 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,15 @@ class SoftmaxMKLDNNKernel : public paddle::framework::OpKernel<T> {
73
73
softmax_dst_memory);
74
74
std::vector<primitive> pipeline{softmax};
75
75
stream (stream::kind::eager).submit (pipeline).wait ();
76
+
77
+ const bool is_test = ctx.Attr <bool >(" is_test" );
78
+ if (!is_test) {
79
+ T threshold = exp (-64 );
80
+ for (size_t i = 0 ; i < dst_tz[0 ] * dst_tz[1 ]; ++i) {
81
+ output_data[i] =
82
+ output_data[i] < threshold ? threshold : output_data[i];
83
+ }
84
+ }
76
85
}
77
86
};
78
87
Original file line number Diff line number Diff line change @@ -97,6 +97,9 @@ class SoftmaxOpMaker : public framework::OpProtoAndCheckerMaker {
97
97
AddAttr<bool >(" use_mkldnn" ,
98
98
" (bool, default false) Only used in mkldnn kernel" )
99
99
.SetDefault (false );
100
+ AddAttr<bool >(" is_test" ,
101
+ " Disable epsilon adding to softmax results. Used by MKLDNN." )
102
+ .SetDefault (false );
100
103
AddComment (R"DOC(
101
104
Softmax Operator.
102
105
Original file line number Diff line number Diff line change @@ -88,6 +88,7 @@ def fc(input,
88
88
bias_attr = None ,
89
89
use_mkldnn = False ,
90
90
act = None ,
91
+ is_test = False ,
91
92
name = None ):
92
93
"""
93
94
**Fully Connected Layer**
@@ -134,6 +135,7 @@ def fc(input,
134
135
bias_attr (ParamAttr|list of ParamAttr, default None): The parameter attribute for the bias
135
136
of this layer. If it is set to None, no bias will be added to the output units.
136
137
act (str, default None): Activation to be applied to the output of this layer.
138
+ is_test(bool): A flag indicating whether execution is in test phase.
137
139
use_mkldnn(bool): Use mkldnn kernel or not, it is valid only when the mkldnn
138
140
library is installed. Default: False
139
141
name (str, default None): The name of this layer.
@@ -177,8 +179,11 @@ def fc(input,
177
179
inputs = {"Input" : input ,
178
180
"W" : w },
179
181
outputs = {"Out" : tmp },
180
- attrs = {"use_mkldnn" : use_mkldnn ,
181
- "bias_attr" : bias_attr })
182
+ attrs = {
183
+ "use_mkldnn" : use_mkldnn ,
184
+ "is_test" : is_test ,
185
+ "bias_attr" : bias_attr
186
+ })
182
187
return helper .append_activation (tmp )
183
188
else :
184
189
for input_var , param_attr in helper .iter_inputs_and_params ():
You can’t perform that action at this time.
0 commit comments