Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions python/paddle/fluid/tests/unittests/test_device_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ def execute(main_program, startup_program):
exe.run(main_program)


def get_vaild_warning_num(warning, w):
num = 0
for i in range(len(w)):
if warning in str(w[i].message):
num += 1
return num


class TestDeviceGuard(unittest.TestCase):
def test_device_guard(self):
main_program = fluid.Program()
Expand Down Expand Up @@ -133,7 +141,10 @@ def test_without_kernel_op(self):
i = fluid.layers.increment(x=i, value=1, in_place=True)
fluid.layers.less_than(x=i, y=loop_len, cond=cond)

assert len(w) == 1
warning = "The Op(while) is not support to set device."
warning_num = get_vaild_warning_num(warning, w)
assert warning_num == 1

all_ops = main_program.global_block().ops
device_attr_name = core.op_proto_and_checker_maker.kOpDeviceAttrName()
for op in all_ops:
Expand Down Expand Up @@ -169,7 +180,10 @@ def test_warning(self):
shape=[1], value=4.0, dtype='float32')
result = fluid.layers.less_than(x=x, y=y, force_cpu=False)

assert len(w) == 2
warning = "\'device_guard\' has higher priority when they are used at the same time."
warning_num = get_vaild_warning_num(warning, w)
assert warning_num == 2

all_ops = main_program.global_block().ops
device_attr_name = core.op_proto_and_checker_maker.kOpDeviceAttrName()
for op in all_ops:
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/tests/unittests/test_gather_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def test_out2(self):
"index": index_np,
'axis': axis_np},
fetch_list=[out])
expected_output = gather_numpy(x_np, index_np, axis_np)
expected_output = gather_numpy(x_np, index_np, axis_np[0])
self.assertTrue(np.allclose(result, expected_output))


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_no_var_save(self):
params_filename='params')
expected_warn = "no variable in your model, please ensure there are any variables in your model to save"
self.assertTrue(len(w) > 0)
self.assertTrue(expected_warn == str(w[0].message))
self.assertTrue(expected_warn == str(w[-1].message))


if __name__ == '__main__':
Expand Down