Skip to content

Commit 190cfd6

Browse files
committed
fix squeeze shape check; test=develop
1 parent b7baeed commit 190cfd6

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

paddle/fluid/operators/squeeze_op.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class SqueezeOpInferShape : public framework::InferShapeBase {
4040
"tensor's rank.");
4141
}
4242

43-
auto out_dims = GetOutputShape(axes, x_dims);
43+
auto out_dims = GetOutputShape(axes, x_dims, ctx);
4444
ctx->SetOutputDim("Out", out_dims);
4545
if (x_dims[0] == out_dims[0]) {
4646
// Only pass LoD when the first dimension of output and Input(X)
@@ -50,7 +50,8 @@ class SqueezeOpInferShape : public framework::InferShapeBase {
5050
}
5151

5252
static framework::DDim GetOutputShape(const std::vector<int> squeeze_dims,
53-
const framework::DDim &in_dims) {
53+
const framework::DDim &in_dims,
54+
framework::InferShapeContext *ctx) {
5455
size_t num_squeeze_dims = squeeze_dims.size();
5556
int cnt_squeezed_dims = 0;
5657
bool should_squeeze[9] = {false};
@@ -71,9 +72,12 @@ class SqueezeOpInferShape : public framework::InferShapeBase {
7172
// Check current index, the upper limit has beed checked in line 36.
7273
PADDLE_ENFORCE(current >= 0,
7374
"Invalid axis, the negative axis is out of range.");
74-
PADDLE_ENFORCE(in_dims[current] == 1,
75-
"Invalid axis index, the axis that will be squeezed "
76-
"should be equal to 1.");
75+
76+
if (ctx->IsRuntime()) {
77+
PADDLE_ENFORCE(in_dims[current] == 1,
78+
"Invalid axis index, the axis that will be squeezed "
79+
"should be equal to 1.");
80+
}
7781

7882
if (!(should_squeeze[current])) {
7983
++cnt_squeezed_dims;

0 commit comments

Comments
 (0)