File tree Expand file tree Collapse file tree 3 files changed +17
-1
lines changed
python/paddle/fluid/layers Expand file tree Collapse file tree 3 files changed +17
-1
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 @@ -87,6 +87,7 @@ def fc(input,
87
87
bias_attr = None ,
88
88
use_mkldnn = False ,
89
89
act = None ,
90
+ is_test = False ,
90
91
name = None ):
91
92
"""
92
93
**Fully Connected Layer**
@@ -133,6 +134,7 @@ def fc(input,
133
134
bias_attr (ParamAttr|list of ParamAttr, default None): The parameter attribute for the bias
134
135
of this layer. If it is set to None, no bias will be added to the output units.
135
136
act (str, default None): Activation to be applied to the output of this layer.
137
+ is_test(bool): A flag indicating whether execution is in test phase.
136
138
use_mkldnn(bool): Use mkldnn kernel or not, it is valid only when the mkldnn
137
139
library is installed. Default: False
138
140
name (str, default None): The name of this layer.
@@ -177,7 +179,9 @@ def fc(input,
177
179
"W" : w },
178
180
outputs = {"Out" : tmp },
179
181
attrs = {"use_mkldnn" : use_mkldnn ,
180
- "bias_attr" : bias_attr })
182
+ "is_test" : is_test ,
183
+ "bias_attr" : bias_attr
184
+ })
181
185
return helper .append_activation (tmp )
182
186
else :
183
187
for input_var , param_attr in helper .iter_inputs_and_params ():
You can’t perform that action at this time.
0 commit comments