未验证 提交 9ba585f5 编写于 作者: T Tao Luo 提交者: GitHub

fix PE in test_profiler.py (#25144)

上级 19c4db1b
...@@ -94,17 +94,13 @@ class TestProfiler(unittest.TestCase): ...@@ -94,17 +94,13 @@ class TestProfiler(unittest.TestCase):
event.name.startswith("Runtime API")): event.name.startswith("Runtime API")):
print("Warning: unregister", event.name) 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") x = np.random.random((32, 784)).astype("float32")
y = np.random.randint(0, 10, (32, 1)).astype("int64") y = np.random.randint(0, 10, (32, 1)).astype("int64")
outs = exe.run(main_program, outs = exe.run(main_program,
feed={'x': x, feed={'x': x,
'y': y}, 'y': y},
fetch_list=fetch_list) 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, def net_profiler(self,
exe, exe,
...@@ -120,13 +116,11 @@ class TestProfiler(unittest.TestCase): ...@@ -120,13 +116,11 @@ class TestProfiler(unittest.TestCase):
profile_path = self.get_profile_path() profile_path = self.get_profile_path()
if not use_new_api: if not use_new_api:
with profiler.profiler(state, 'total', profile_path, tracer_option): with profiler.profiler(state, 'total', profile_path, tracer_option):
pass_acc_calculator = fluid.average.WeightedAverage()
for iter in range(10): for iter in range(10):
if iter == 2: if iter == 2:
profiler.reset_profiler() profiler.reset_profiler()
self.run_iter(exe, main_program, self.run_iter(exe, main_program,
[avg_cost, batch_acc, batch_size], [avg_cost, batch_acc, batch_size])
pass_acc_calculator)
else: else:
options = utils.ProfilerOptions(options={ options = utils.ProfilerOptions(options={
'state': state, 'state': state,
...@@ -136,11 +130,9 @@ class TestProfiler(unittest.TestCase): ...@@ -136,11 +130,9 @@ class TestProfiler(unittest.TestCase):
'profile_path': profile_path 'profile_path': profile_path
}) })
with utils.Profiler(enabled=True, options=options) as prof: with utils.Profiler(enabled=True, options=options) as prof:
pass_acc_calculator = fluid.average.WeightedAverage()
for iter in range(10): for iter in range(10):
self.run_iter(exe, main_program, self.run_iter(exe, main_program,
[avg_cost, batch_acc, batch_size], [avg_cost, batch_acc, batch_size])
pass_acc_calculator)
utils.get_profiler().record_step() utils.get_profiler().record_step()
if batch_range is None and iter == 2: if batch_range is None and iter == 2:
utils.get_profiler().reset() utils.get_profiler().reset()
...@@ -156,7 +148,7 @@ class TestProfiler(unittest.TestCase): ...@@ -156,7 +148,7 @@ class TestProfiler(unittest.TestCase):
"Default", "Default",
batch_range=[5, 10], batch_range=[5, 10],
use_new_api=use_new_api) 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(), @unittest.skipIf(not core.is_compiled_with_cuda(),
"profiler is enabled only with GPU") "profiler is enabled only with GPU")
...@@ -167,9 +159,10 @@ class TestProfiler(unittest.TestCase): ...@@ -167,9 +159,10 @@ class TestProfiler(unittest.TestCase):
exe, exe,
'GPU', 'GPU',
"OpDetail", "OpDetail",
batch_range=[0, 100], batch_range=[0, 10],
use_new_api=use_new_api) 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(), @unittest.skipIf(not core.is_compiled_with_cuda(),
"profiler is enabled only with GPU") "profiler is enabled only with GPU")
...@@ -182,7 +175,8 @@ class TestProfiler(unittest.TestCase): ...@@ -182,7 +175,8 @@ class TestProfiler(unittest.TestCase):
"AllOpDetail", "AllOpDetail",
batch_range=None, batch_range=None,
use_new_api=use_new_api) 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): class TestProfilerAPIError(unittest.TestCase):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册