From 0064f6d9762668f37340d39f63017c55b93b97ee Mon Sep 17 00:00:00 2001 From: fengjiayi Date: Thu, 11 Jan 2018 10:24:18 +0800 Subject: [PATCH] refine test --- python/paddle/v2/fluid/tests/test_clip.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/python/paddle/v2/fluid/tests/test_clip.py b/python/paddle/v2/fluid/tests/test_clip.py index 7e72112a8..a71823f7e 100644 --- a/python/paddle/v2/fluid/tests/test_clip.py +++ b/python/paddle/v2/fluid/tests/test_clip.py @@ -34,6 +34,9 @@ fluid.backward.append_backward( hidden1_grad = prog.block(0).var(hidden1.name + "@GRAD") hidden1_grad_clip = prog_clip.block(0).var(hidden1.name + "@GRAD") +hidden2_grad = prog.block(0).var(hidden2.name + "@GRAD") +hidden2_grad_clip = prog_clip.block(0).var(hidden2.name + "@GRAD") + train_reader = paddle.batch( paddle.reader.shuffle( paddle.dataset.mnist.train(), buf_size=8192), @@ -49,11 +52,16 @@ for data in train_reader(): count += 1 if count > 5: break - out = exe.run(prog, feed=feeder.feed(data), fetch_list=[hidden1_grad]) - out_clip = exe.run(prog_clip, - feed=feeder.feed(data), - fetch_list=[hidden1_grad_clip]) - if not (out[0].clip(min=CLIP_MIN, max=CLIP_MAX) == out_clip[0]).all(): + out1, out2 = exe.run(prog, + feed=feeder.feed(data), + fetch_list=[hidden1_grad, hidden2_grad]) + out1_clip, out2_clip = exe.run( + prog_clip, + feed=feeder.feed(data), + fetch_list=[hidden1_grad_clip, hidden2_grad_clip]) + if not ((out1.clip( + min=CLIP_MIN, max=CLIP_MAX) == out1_clip).all() and + (out2 == out2_clip).all()): exit(1) exit(0) -- GitLab