Skip to content

Commit

Permalink
Update the precision of pad, pad2d, pad_constant_like's unit tests fr…
Browse files Browse the repository at this point in the history
…om fp32 to fp64 (PaddlePaddle#22394)

* update the ut precision of pad pad2d pad_constant_like from fp32 to fp64, test=develop
  • Loading branch information
FrostML authored Feb 2, 2020
1 parent 371f377 commit 0404e7a
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion paddle/fluid/operators/pad2d_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ class Pad2dCPUKernel : public framework::OpKernel<T> {
GetPaddings(pads, context);
auto mode = context.Attr<std::string>("mode");
auto data_format = context.Attr<std::string>("data_format");
T value = context.Attr<T>("pad_value");
T value = static_cast<T>(context.Attr<float>("pad_value"));

auto* x = context.Input<Tensor>("X");
auto in_dims = x->dims();
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/operators/pad2d_op.cu
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ class Pad2dCUDAKernel : public framework::OpKernel<T> {
GetPaddings(pads, context);
auto mode = context.Attr<std::string>("mode");
auto data_format = context.Attr<std::string>("data_format");
T value = context.Attr<T>("pad_value");
T value = static_cast<T>(context.Attr<float>("pad_value"));

auto* x = context.Input<Tensor>("X");
auto in_dims = x->dims();
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/operators/pad_constant_like_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class PadConstantLikeKernel : public framework::OpKernel<T> {
return;
}

T pad_value = context.Attr<T>("pad_value");
T pad_value = static_cast<T>(context.Attr<float>("pad_value"));
out->mutable_data<T>(context.GetPlace());

int rank = context.Input<framework::Tensor>("X")->dims().size();
Expand Down
5 changes: 3 additions & 2 deletions python/paddle/fluid/tests/unittests/test_pad2d_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ def setUp(self):
self.variable_paddings = False
self.initTestCase()
self.op_type = "pad2d"
self.inputs = {'X': np.random.random(self.shape).astype("float32"), }
self.inputs = {'X': np.random.random(self.shape).astype("float64")}
self.attrs = {}
if self.variable_paddings:
self.attrs['paddings'] = []
self.inputs['Paddings'] = np.array(self.paddings).flatten().astype(
"int32")
else:
self.attrs['paddings'] = np.array(self.paddings).flatten()
self.attrs['paddings'] = np.array(self.paddings).flatten().astype(
"int32")
self.attrs['pad_value'] = self.pad_value
self.attrs['mode'] = self.mode
self.attrs['data_format'] = self.data_format
Expand Down
4 changes: 2 additions & 2 deletions python/paddle/fluid/tests/unittests/test_pad_constant_like.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def setUp(self):
self.initTestCase()
self.op_type = "pad_constant_like"
self.inputs = {
'X': np.random.random(self.x_shape).astype("float32"),
'Y': np.random.random(self.y_shape).astype("float32")
'X': np.random.random(self.x_shape).astype("float64"),
'Y': np.random.random(self.y_shape).astype("float64")
}
self.attrs = {}
self.attrs['pad_value'] = self.pad_value
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/tests/unittests/test_pad_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def setUp(self):
}

def get_dtype(self):
return np.float32
return np.float64

def test_check_output(self):
self.check_output()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@
'modified_huber_loss', \
'mul', \
'nce', \
'pad', \
'pad2d', \
'pad_constant_like', \
'pool2d', \
'pool3d', \
'prroi_pool', \
Expand Down

0 comments on commit 0404e7a

Please sign in to comment.