Skip to content

Commit f0b6d72

Browse files
Zha0q1apeforest
authored andcommitted
update previous flaky naive engine test (apache#15651)
* update precious flaky naive engine test * retriever tests * retrigger tests * retrigger tests * retrigger tests * retrigger tests * retrigger tests * Update test_profiler.py * retrigger tests * retrigger tests * retrigger tests * retrigger tests * retrigger tests * retrigger tests * Update test_profiler.py * retrigger tests * retrigger tests * retrigger tests * retrigger tests * Update test_profiler.py * retrigger tests * Update test_profiler.py
1 parent 0f28f5b commit f0b6d72

File tree

1 file changed

+40
-48
lines changed

1 file changed

+40
-48
lines changed

tests/python/unittest/test_profiler.py

Lines changed: 40 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -267,21 +267,23 @@ def check_sorting(debug_str, sort_by, ascending):
267267
test_profile_event(False)
268268
for sb in sort_by_options:
269269
for asc in ascending_options:
270-
debug_str = profiler.dumps(format = 'json', sort_by = sb, ascending = asc)
270+
debug_str = profiler.dumps(format='json', sort_by=sb, ascending=asc)
271271
check_sorting(debug_str, sb, asc)
272272
profiler.set_state('stop')
273273

274274
def test_aggregate_duplication():
275275
file_name = 'test_aggregate_duplication.json'
276-
enable_profiler(profile_filename = file_name, run=True, continuous_dump=True, \
276+
enable_profiler(profile_filename=file_name, run=True, continuous_dump=True, \
277277
aggregate_stats=True)
278+
# clear aggregate stats
279+
profiler.dumps(reset=True)
278280
inp = mx.nd.zeros(shape=(100, 100))
279281
y = mx.nd.sqrt(inp)
280282
inp = inp + 1
281283
inp = inp + 1
282284
mx.nd.waitall()
283285
profiler.dump(False)
284-
debug_str = profiler.dumps(format = 'json')
286+
debug_str = profiler.dumps(format='json')
285287
target_dict = json.loads(debug_str)
286288
assert 'Time' in target_dict and 'operator' in target_dict['Time'] \
287289
and 'sqrt' in target_dict['Time']['operator'] \
@@ -293,7 +295,7 @@ def test_aggregate_duplication():
293295
assert target_dict['Time']['operator']['_plus_scalar']['Count'] == 2
294296
profiler.set_state('stop')
295297

296-
def test_custom_operator_profiling(seed = None, file_name = None):
298+
def test_custom_operator_profiling(seed=None, file_name=None):
297299
class Sigmoid(mx.operator.CustomOp):
298300
def forward(self, is_train, req, in_data, out_data, aux):
299301
x = in_data[0].asnumpy()
@@ -330,25 +332,34 @@ def create_operator(self, ctx, in_shapes, in_dtypes):
330332

331333
if file_name is None:
332334
file_name = 'test_custom_operator_profiling.json'
333-
enable_profiler(profile_filename = file_name, run=True, continuous_dump=True,\
335+
enable_profiler(profile_filename=file_name, run=True, continuous_dump=True,\
334336
aggregate_stats=True)
337+
# clear aggregate stats
338+
profiler.dumps(reset=True)
335339
x = mx.nd.array([0, 1, 2, 3])
336340
x.attach_grad()
337341
with mx.autograd.record():
338342
y = mx.nd.Custom(x, op_type='MySigmoid')
339343
y.backward()
340344
mx.nd.waitall()
341345
profiler.dump(False)
342-
debug_str = profiler.dumps(format = 'json')
346+
debug_str = profiler.dumps(format='json')
343347
target_dict = json.loads(debug_str)
344348
assert 'Time' in target_dict and 'Custom Operator' in target_dict['Time'] \
345349
and 'MySigmoid::pure_python' in target_dict['Time']['Custom Operator'] \
346350
and '_backward_MySigmoid::pure_python' in target_dict['Time']['Custom Operator'] \
347351
and 'MySigmoid::_zeros' in target_dict['Time']['Custom Operator']
348352
profiler.set_state('stop')
349353

350-
def test_custom_operator_profiling_multiple_custom_ops_imperative(seed = None, \
351-
mode = 'imperative', file_name = None):
354+
def check_custom_operator_profiling_multiple_custom_ops_output(debug_str):
355+
target_dict = json.loads(debug_str)
356+
assert 'Time' in target_dict and 'Custom Operator' in target_dict['Time'] \
357+
and 'MyAdd1::pure_python' in target_dict['Time']['Custom Operator'] \
358+
and 'MyAdd2::pure_python' in target_dict['Time']['Custom Operator'] \
359+
and 'MyAdd1::_plus_scalar' in target_dict['Time']['Custom Operator'] \
360+
and 'MyAdd2::_plus_scalar' in target_dict['Time']['Custom Operator']
361+
362+
def custom_operator_profiling_multiple_custom_ops(seed, mode, file_name):
352363
class MyAdd(mx.operator.CustomOp):
353364
def forward(self, is_train, req, in_data, out_data, aux):
354365
self.assign(out_data[0], req[0], in_data[0] + 1)
@@ -392,65 +403,46 @@ def infer_shape(self, in_shape):
392403
def create_operator(self, ctx, shapes, dtypes):
393404
return MyAdd()
394405

395-
if file_name is None:
396-
file_name = 'test_custom_operator_profiling_multiple_custom_ops_imperative.json'
397-
enable_profiler(profile_filename = file_name, run=True, continuous_dump=True,\
406+
enable_profiler(profile_filename=file_name, run=True, continuous_dump=True,\
398407
aggregate_stats=True)
408+
# clear aggregate stats
409+
profiler.dumps(reset=True)
399410
inp = mx.nd.zeros(shape=(100, 100))
400411
if mode == 'imperative':
401-
x = inp + 1
402412
y = mx.nd.Custom(inp, op_type='MyAdd1')
403413
z = mx.nd.Custom(inp, op_type='MyAdd2')
404414
elif mode == 'symbolic':
405415
a = mx.symbol.Variable('a')
406-
b = a + 1
407-
c = mx.symbol.Custom(data=a, op_type='MyAdd1')
408-
d = mx.symbol.Custom(data=a, op_type='MyAdd2')
409-
b.bind(mx.cpu(), {'a': inp}).forward()
410-
c.bind(mx.cpu(), {'a': inp}).forward()
411-
d.bind(mx.cpu(), {'a': inp}).forward()
416+
b = mx.symbol.Custom(data=a, op_type='MyAdd1')
417+
c = mx.symbol.Custom(data=a, op_type='MyAdd2')
418+
y = b.bind(mx.cpu(), {'a': inp})
419+
z = c.bind(mx.cpu(), {'a': inp})
420+
yy = y.forward()
421+
zz = z.forward()
412422
mx.nd.waitall()
413423
profiler.dump(False)
414-
debug_str = profiler.dumps(format = 'json')
415-
target_dict = json.loads(debug_str)
416-
'''
417-
We are calling _plus_scalar within MyAdd1 and MyAdd2 and outside both the custom
418-
operators, so in aggregate stats we should have three different kinds of
419-
_plus_scalar under domains "Custom Operator" and "operator"
420-
'''
421-
assert 'Time' in target_dict and 'Custom Operator' in target_dict['Time'] \
422-
and 'MyAdd1::pure_python' in target_dict['Time']['Custom Operator'] \
423-
and 'MyAdd2::pure_python' in target_dict['Time']['Custom Operator'] \
424-
and 'MyAdd1::_plus_scalar' in target_dict['Time']['Custom Operator'] \
425-
and 'MyAdd2::_plus_scalar' in target_dict['Time']['Custom Operator'] \
426-
and '_plus_scalar' not in target_dict['Time']['Custom Operator'] \
427-
and 'operator' in target_dict['Time'] \
428-
and '_plus_scalar' in target_dict['Time']['operator']
424+
debug_str = profiler.dumps(format='json')
425+
check_custom_operator_profiling_multiple_custom_ops_output(debug_str)
429426
profiler.set_state('stop')
430-
431-
@unittest.skip("Flaky test https://github.com/apache/incubator-mxnet/issues/15406")
427+
432428
def test_custom_operator_profiling_multiple_custom_ops_symbolic():
433-
run_in_spawned_process(test_custom_operator_profiling_multiple_custom_ops_imperative, \
434-
{'MXNET_EXEC_BULK_EXEC_INFERENCE' : 0, \
435-
'MXNET_EXEC_BULK_EXEC_TRAIN' : 0}, \
436-
'symbolic', \
429+
custom_operator_profiling_multiple_custom_ops(None, 'symbolic', \
437430
'test_custom_operator_profiling_multiple_custom_ops_symbolic.json')
438431

439-
@unittest.skip("Flaky test https://github.com/apache/incubator-mxnet/issues/15406")
432+
def test_custom_operator_profiling_multiple_custom_ops_imperative():
433+
custom_operator_profiling_multiple_custom_ops(None, 'imperative', \
434+
'test_custom_operator_profiling_multiple_custom_ops_imperative.json')
435+
440436
def test_custom_operator_profiling_naive_engine():
441437
# run the three tests above using Naive Engine
442438
run_in_spawned_process(test_custom_operator_profiling, \
443439
{'MXNET_ENGINE_TYPE' : "NaiveEngine"}, \
444440
'test_custom_operator_profiling_naive.json')
445-
run_in_spawned_process(test_custom_operator_profiling_multiple_custom_ops_imperative, \
446-
{'MXNET_ENGINE_TYPE' : "NaiveEngine"}, \
447-
'imperative', \
441+
run_in_spawned_process(custom_operator_profiling_multiple_custom_ops, \
442+
{'MXNET_ENGINE_TYPE' : "NaiveEngine"}, 'imperative', \
448443
'test_custom_operator_profiling_multiple_custom_ops_imperative_naive.json')
449-
run_in_spawned_process(test_custom_operator_profiling_multiple_custom_ops_imperative, \
450-
{'MXNET_ENGINE_TYPE' : "NaiveEngine", \
451-
'MXNET_EXEC_BULK_EXEC_INFERENCE' : 0, \
452-
'MXNET_EXEC_BULK_EXEC_TRAIN' : 0}, \
453-
'symbolic', \
444+
run_in_spawned_process(custom_operator_profiling_multiple_custom_ops, \
445+
{'MXNET_ENGINE_TYPE' : "NaiveEngine"}, 'symbolic', \
454446
'test_custom_operator_profiling_multiple_custom_ops_symbolic_naive.json')
455447

456448
if __name__ == '__main__':

0 commit comments

Comments
 (0)