Skip to content

Commit 32f8ac7

Browse files
committed
Remove additional message
1 parent 34a8084 commit 32f8ac7

File tree

3 files changed

+21
-42
lines changed

3 files changed

+21
-42
lines changed

paddle/fluid/operators/fc_mkldnn_op.cc

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,67 +23,56 @@ namespace operators {
2323
using paddle::framework::Tensor;
2424
using paddle::platform::MKLDNNDeviceContext;
2525

26-
struct MKLDNNMatrixSize final {
27-
explicit MKLDNNMatrixSize(const std::vector<int>& in,
28-
const std::vector<int>& w)
29-
: mb{in[0]}, ic{in[1]}, oc{w[1]}, h{in[2]}, w{in[3]} {}
30-
31-
bool is_spatial() const { return h > 2 && w > 2; }
32-
33-
const int mb;
34-
const int ic;
35-
const int oc;
36-
const int h, w;
37-
};
38-
3926
template <typename T>
4027
class MKLDNNMD {
4128
public:
4229
explicit MKLDNNMD(const T* in, const T* w, bool bias)
43-
: sz_(std::unique_ptr<MKLDNNMatrixSize>(new MKLDNNMatrixSize(
44-
paddle::framework::vectorize2int(in->dims()),
45-
paddle::framework::vectorize2int(w->dims())))) {
30+
: in{paddle::framework::vectorize2int(in->dims())},
31+
w{paddle::framework::vectorize2int(w->dims())} {
4632
with_bias_ = bias;
4733
}
4834

4935
mkldnn::memory::desc dst() const {
50-
return platform::MKLDNNMemDesc({sz_->mb, sz_->oc},
36+
return platform::MKLDNNMemDesc({in[0], w[1]},
5137
mkldnn::memory::data_type::f32,
5238
mkldnn::memory::format::nc);
5339
}
5440

5541
mkldnn::memory::desc src() const {
56-
return sz_->is_spatial()
57-
? platform::MKLDNNMemDesc({sz_->mb, sz_->ic, sz_->h, sz_->w},
42+
return is_spatial()
43+
? platform::MKLDNNMemDesc({in[0], in[1], in[2], in[3]},
5844
mkldnn::memory::data_type::f32,
5945
mkldnn::memory::format::nchw)
60-
: platform::MKLDNNMemDesc({sz_->mb, sz_->ic},
46+
: platform::MKLDNNMemDesc({in[0], in[1]},
6147
mkldnn::memory::data_type::f32,
6248
mkldnn::memory::format::nc);
6349
}
6450

6551
mkldnn::memory::desc weights() const {
66-
return sz_->is_spatial()
67-
? platform::MKLDNNMemDesc({sz_->oc, sz_->ic, sz_->h, sz_->w},
52+
return is_spatial()
53+
? platform::MKLDNNMemDesc({w[1], in[1], in[2], in[3]},
6854
mkldnn::memory::data_type::f32,
6955
mkldnn::memory::format::oihw)
70-
: platform::MKLDNNMemDesc({sz_->oc, sz_->ic},
56+
: platform::MKLDNNMemDesc({w[1], in[1]},
7157
mkldnn::memory::data_type::f32,
7258
mkldnn::memory::format::oi);
7359
}
7460

7561
mkldnn::memory::desc bias() const {
7662
return with_bias_
77-
? platform::MKLDNNMemDesc({sz_->oc},
78-
mkldnn::memory::data_type::f32,
63+
? platform::MKLDNNMemDesc({w[1]}, mkldnn::memory::data_type::f32,
7964
mkldnn::memory::format::format_undef)
8065
: platform::MKLDNNMemDesc({}, mkldnn::memory::data_type::f32,
8166
mkldnn::memory::format::format_undef);
8267
}
8368

8469
private:
85-
std::unique_ptr<MKLDNNMatrixSize> sz_;
70+
bool is_spatial() const { return in.size() > 1 && w.size() > 1; }
71+
72+
std::vector<int> in;
73+
std::vector<int> w;
8674
bool with_bias_;
75+
bool is_spatial_;
8776
};
8877

8978
class MKLDNNMemory {

paddle/fluid/operators/fc_op.cc

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ void FCOp::InferShape(framework::InferShapeContext* ctx) const {
2929
auto w_dims = ctx->GetInputDim("W");
3030
std::vector<int64_t> output_shape({in_dims[0], w_dims[1]});
3131

32-
PADDLE_ENFORCE(in_dims.size() == 4,
33-
"Fully Connected input should be 4-D tensor.");
32+
PADDLE_ENFORCE(in_dims.size() == 4 || in_dims.size() == 2,
33+
"Fully Connected input should be 2-D or 4-D tensor.");
3434

3535
PADDLE_ENFORCE(w_dims.size() == 2,
3636
"Fully Connected input should be 2-D tensor.");
@@ -96,22 +96,11 @@ FCOpMaker::FCOpMaker(OpProto* proto, OpAttrChecker* op_checker)
9696
9797
The fully connected operation calculates the output based on the input, weights and bias attribute.
9898
The size of each dimension of the parameters checked in the infer-shape.
99-
Input(Input) is NCHW or NC format. Where N is batch size, C is the number of channels,
100-
H is the height of the feature, and W is the width of the feature.
101-
Weights(W) is OIHW or OI format. Where H is the height of the feature, W is the width of the feature,
102-
O is the height of output, and I is the number of channels.
103-
Output(Out) is NC format. Where N is batch size, and C is the number of channels.
10499
The matrix of bias is generated by the mkldnn framework, when the bias_attr is True.
105100
Additional parametrs are use_mkldnn and bias_attr.
106101
The input(X) size and output(Out) size may be diffrent.
107102
108-
Example:
109-
Input:
110-
Input shape: $(N, C_{in}, H_{in}, W_{in})$
111-
Weight shape: $(O_{out}, I_{in}, H_{in}, W_{in})$
112-
Bias shape: $(O_{out})$
113-
Output:
114-
Output shape: $(N, C_{out})$
103+
The fully connected layer only supports MKLDNN version
115104
)DOC");
116105
}
117106

python/paddle/fluid/layers/nn.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,9 @@ def fc(input,
167167
shape=param_shape,
168168
dtype=dtype,
169169
is_bias=False)
170-
bias_attr = False
171-
if bias_attr is not None:
170+
if bias_attr is None or bias_attr is False:
171+
bias_attr = False
172+
else:
172173
bias_attr = True
173174
helper.append_op(
174175
type="fc",

0 commit comments

Comments
 (0)