@@ -267,21 +267,23 @@ def check_sorting(debug_str, sort_by, ascending):
267
267
test_profile_event (False )
268
268
for sb in sort_by_options :
269
269
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 )
271
271
check_sorting (debug_str , sb , asc )
272
272
profiler .set_state ('stop' )
273
273
274
274
def test_aggregate_duplication ():
275
275
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 , \
277
277
aggregate_stats = True )
278
+ # clear aggregate stats
279
+ profiler .dumps (reset = True )
278
280
inp = mx .nd .zeros (shape = (100 , 100 ))
279
281
y = mx .nd .sqrt (inp )
280
282
inp = inp + 1
281
283
inp = inp + 1
282
284
mx .nd .waitall ()
283
285
profiler .dump (False )
284
- debug_str = profiler .dumps (format = 'json' )
286
+ debug_str = profiler .dumps (format = 'json' )
285
287
target_dict = json .loads (debug_str )
286
288
assert 'Time' in target_dict and 'operator' in target_dict ['Time' ] \
287
289
and 'sqrt' in target_dict ['Time' ]['operator' ] \
@@ -293,7 +295,7 @@ def test_aggregate_duplication():
293
295
assert target_dict ['Time' ]['operator' ]['_plus_scalar' ]['Count' ] == 2
294
296
profiler .set_state ('stop' )
295
297
296
- def test_custom_operator_profiling (seed = None , file_name = None ):
298
+ def test_custom_operator_profiling (seed = None , file_name = None ):
297
299
class Sigmoid (mx .operator .CustomOp ):
298
300
def forward (self , is_train , req , in_data , out_data , aux ):
299
301
x = in_data [0 ].asnumpy ()
@@ -330,25 +332,34 @@ def create_operator(self, ctx, in_shapes, in_dtypes):
330
332
331
333
if file_name is None :
332
334
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 ,\
334
336
aggregate_stats = True )
337
+ # clear aggregate stats
338
+ profiler .dumps (reset = True )
335
339
x = mx .nd .array ([0 , 1 , 2 , 3 ])
336
340
x .attach_grad ()
337
341
with mx .autograd .record ():
338
342
y = mx .nd .Custom (x , op_type = 'MySigmoid' )
339
343
y .backward ()
340
344
mx .nd .waitall ()
341
345
profiler .dump (False )
342
- debug_str = profiler .dumps (format = 'json' )
346
+ debug_str = profiler .dumps (format = 'json' )
343
347
target_dict = json .loads (debug_str )
344
348
assert 'Time' in target_dict and 'Custom Operator' in target_dict ['Time' ] \
345
349
and 'MySigmoid::pure_python' in target_dict ['Time' ]['Custom Operator' ] \
346
350
and '_backward_MySigmoid::pure_python' in target_dict ['Time' ]['Custom Operator' ] \
347
351
and 'MySigmoid::_zeros' in target_dict ['Time' ]['Custom Operator' ]
348
352
profiler .set_state ('stop' )
349
353
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 ):
352
363
class MyAdd (mx .operator .CustomOp ):
353
364
def forward (self , is_train , req , in_data , out_data , aux ):
354
365
self .assign (out_data [0 ], req [0 ], in_data [0 ] + 1 )
@@ -392,65 +403,46 @@ def infer_shape(self, in_shape):
392
403
def create_operator (self , ctx , shapes , dtypes ):
393
404
return MyAdd ()
394
405
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 ,\
398
407
aggregate_stats = True )
408
+ # clear aggregate stats
409
+ profiler .dumps (reset = True )
399
410
inp = mx .nd .zeros (shape = (100 , 100 ))
400
411
if mode == 'imperative' :
401
- x = inp + 1
402
412
y = mx .nd .Custom (inp , op_type = 'MyAdd1' )
403
413
z = mx .nd .Custom (inp , op_type = 'MyAdd2' )
404
414
elif mode == 'symbolic' :
405
415
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 ()
412
422
mx .nd .waitall ()
413
423
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 )
429
426
profiler .set_state ('stop' )
430
-
431
- @unittest .skip ("Flaky test https://github.com/apache/incubator-mxnet/issues/15406" )
427
+
432
428
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' , \
437
430
'test_custom_operator_profiling_multiple_custom_ops_symbolic.json' )
438
431
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
+
440
436
def test_custom_operator_profiling_naive_engine ():
441
437
# run the three tests above using Naive Engine
442
438
run_in_spawned_process (test_custom_operator_profiling , \
443
439
{'MXNET_ENGINE_TYPE' : "NaiveEngine" }, \
444
440
'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' , \
448
443
'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' , \
454
446
'test_custom_operator_profiling_multiple_custom_ops_symbolic_naive.json' )
455
447
456
448
if __name__ == '__main__' :
0 commit comments