From 9ba585f5bfbd7740a7042ff4883c2ceb3436d87e Mon Sep 17 00:00:00 2001 From: Tao Luo Date: Mon, 22 Jun 2020 09:57:09 +0800 Subject: [PATCH] fix PE in test_profiler.py (#25144) --- .../fluid/tests/unittests/test_profiler.py | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_profiler.py b/python/paddle/fluid/tests/unittests/test_profiler.py index 97ced3d99ea..07daa97c054 100644 --- a/python/paddle/fluid/tests/unittests/test_profiler.py +++ b/python/paddle/fluid/tests/unittests/test_profiler.py @@ -94,17 +94,13 @@ class TestProfiler(unittest.TestCase): event.name.startswith("Runtime API")): print("Warning: unregister", event.name) - def run_iter(self, exe, main_program, fetch_list, pass_acc_calculator): + def run_iter(self, exe, main_program, fetch_list): x = np.random.random((32, 784)).astype("float32") y = np.random.randint(0, 10, (32, 1)).astype("int64") outs = exe.run(main_program, feed={'x': x, 'y': y}, fetch_list=fetch_list) - acc = np.array(outs[1]) - b_size = np.array(outs[2]) - pass_acc_calculator.add(value=acc, weight=b_size) - pass_acc = pass_acc_calculator.eval() def net_profiler(self, exe, @@ -120,13 +116,11 @@ class TestProfiler(unittest.TestCase): profile_path = self.get_profile_path() if not use_new_api: with profiler.profiler(state, 'total', profile_path, tracer_option): - pass_acc_calculator = fluid.average.WeightedAverage() for iter in range(10): if iter == 2: profiler.reset_profiler() self.run_iter(exe, main_program, - [avg_cost, batch_acc, batch_size], - pass_acc_calculator) + [avg_cost, batch_acc, batch_size]) else: options = utils.ProfilerOptions(options={ 'state': state, @@ -136,11 +130,9 @@ class TestProfiler(unittest.TestCase): 'profile_path': profile_path }) with utils.Profiler(enabled=True, options=options) as prof: - pass_acc_calculator = fluid.average.WeightedAverage() for iter in range(10): self.run_iter(exe, main_program, - [avg_cost, batch_acc, batch_size], - pass_acc_calculator) + [avg_cost, batch_acc, batch_size]) utils.get_profiler().record_step() if batch_range is None and iter == 2: utils.get_profiler().reset() @@ -156,7 +148,7 @@ class TestProfiler(unittest.TestCase): "Default", batch_range=[5, 10], use_new_api=use_new_api) - #self.net_profiler('CPU', "Default", use_parallel_executor=True) + self.net_profiler(exe, 'CPU', "Default", use_parallel_executor=True) @unittest.skipIf(not core.is_compiled_with_cuda(), "profiler is enabled only with GPU") @@ -167,9 +159,10 @@ class TestProfiler(unittest.TestCase): exe, 'GPU', "OpDetail", - batch_range=[0, 100], + batch_range=[0, 10], use_new_api=use_new_api) - #self.net_profiler('GPU', "OpDetail", use_parallel_executor=True) + self.net_profiler( + exe, 'GPU', "OpDetail", use_parallel_executor=True) @unittest.skipIf(not core.is_compiled_with_cuda(), "profiler is enabled only with GPU") @@ -182,7 +175,8 @@ class TestProfiler(unittest.TestCase): "AllOpDetail", batch_range=None, use_new_api=use_new_api) - #self.net_profiler('All', "AllOpDetail", use_parallel_executor=True) + self.net_profiler( + exe, 'All', "AllOpDetail", use_parallel_executor=True) class TestProfilerAPIError(unittest.TestCase): -- GitLab