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

fix PE in test_profiler.py (#25144)

上级 19c4db1b
......@@ -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):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册