Skip to content

Commit

Permalink
增加静态图下的 fp16 单测
Browse files Browse the repository at this point in the history
  • Loading branch information
Ainavo committed Mar 16, 2023
1 parent 7dfb87c commit 8a6ac3e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 30 deletions.
55 changes: 26 additions & 29 deletions python/paddle/fluid/tests/unittests/test_trapezoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,35 +226,32 @@ def test_xwithdx():


class Testfp16Trapezoid(TestTrapezoidAPI):
# def test_fp16_with_gpu(self):
# paddle.enable_static()
# if paddle.fluid.core.is_compiled_with_cuda():
# place = paddle.CUDAPlace(0)
# with paddle.static.program_guard(
# paddle.static.Program(), paddle.static.Program()
# ):
# input_y = np.random.random([4, 4]).astype("float16")
# y = paddle.static.data(
# name="y", shape=[4, 4], dtype="float16"
# )

# input_x = np.random.random([4, 4]).astype("float16")
# x = paddle.static.data(
# name="x", shape=[4, 4], dtype="float16"
# )

# exe = paddle.static.Executor(place)
# out = self.paddle_api(y=y, x=x, dx=self.dx, axis=self.axis)
# res = exe.run(
# paddle.static.default_main_program(),
# feed={
# "y": input_y,
# "x": input_x,
# "dx": self.dx,
# "axis": self.axis
# },
# fetch_list=[out],
# )
def test_fp16_with_gpu(self):
paddle.enable_static()
if paddle.fluid.core.is_compiled_with_cuda():
place = paddle.CUDAPlace(0)
with paddle.static.program_guard(
paddle.static.Program(), paddle.static.Program()
):
input_y = np.random.random([4, 4]).astype("float16")
y = paddle.static.data(name="y", shape=[4, 4], dtype="float16")

input_x = np.random.random([4, 4]).astype("float16")
x = paddle.static.data(name="x", shape=[4, 4], dtype="float16")

exe = paddle.static.Executor(place)
out = self.paddle_api(y=y, x=x, dx=self.dx, axis=self.axis)
res = exe.run(
paddle.static.default_main_program(),
feed={
"y": input_y,
"x": input_x,
"dx": self.dx,
"axis": self.axis,
},
fetch_list=[out],
)

def set_api(self):
self.paddle_api = paddle.trapezoid
self.ref_api = np.trapz
Expand Down
1 change: 0 additions & 1 deletion python/paddle/tensor/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -5286,7 +5286,6 @@ def cumulative_trapezoid(y, x=None, dx=None, axis=-1, name=None):
import paddle
paddle.set_device('cpu')
y = paddle.to_tensor([4, 5, 6], dtype='float32')
print(paddle.cumulative_trapezoid(y))
Expand Down

0 comments on commit 8a6ac3e

Please sign in to comment.