@@ -419,7 +419,48 @@ def backward_cpu_cosim(self, inputs, grad_outputs):
419419 chainer .enable_cosim ()
420420 return output_cosim
421421
422- def cpu_cosim_verify_result (self , mkl_result , numpy_result ):
422+ def cpu_cosim_dump_forward_inputs (self , in_data ):
423+ """dump all forward inputs into file
424+
425+ Aims to dump the inputs into a file in order to reproduce offline,
426+ if encountering a mismatch in cosim results of forward prop.
427+ To support this feature, implement it for each function.
428+
429+ Args:
430+ inputs: Tuple of input arrays.
431+
432+ """
433+ pass
434+
435+ def cpu_cosim_dump_backward_inputs (self , in_data , out_grad ):
436+ """dump all backward inputs into file
437+
438+ Aims to dump the inputs into a file in order to reproduce offline,
439+ if encountering a mismatch in cosim results of backward prop.
440+ To support this feature, implement it for each function.
441+
442+ Args:
443+ inputs: Tuple of input arrays.
444+ out_grad: Tuple of output gradient arrays.
445+
446+ """
447+ pass
448+
449+ def cpu_cosim_dump_inputs (self , inputs , out_grad = None ):
450+ """dump all inputs into a file in order to reprocude errors offline.
451+ """
452+ inputs = [x if isinstance (x , variable .Variable )
453+ else variable .Variable (x )
454+ for x in inputs ]
455+
456+ in_data = tuple ([x .data for x in inputs ])
457+
458+ if out_grad is None :
459+ self .cpu_cosim_dump_forward_inputs (in_data )
460+ else :
461+ self .cpu_cosim_dump_backward_inputs (in_data , out_grad )
462+
463+ def cpu_cosim_verify_result (self , mkl_result , numpy_result , inputs , out_grad = None ):
423464 """cosim verify result between MKLDNN and numpy
424465 """
425466 if not chainer .is_cosim ():
@@ -449,7 +490,13 @@ def cpu_cosim_verify_result(self, mkl_result, numpy_result):
449490 numpy_y_nd = np .array (numpy_y )
450491 i = i + 1
451492 if isinstance (mkl_x_nd , np .ndarray ):
452- testing .assert_allclose (mkl_x_nd , numpy_y_nd , ** check_options )
493+ try :
494+ testing .assert_allclose (mkl_x_nd , numpy_y_nd , ** check_options )
495+ except AssertionError :
496+ self .cpu_cosim_dump_inputs (inputs , out_grad )
497+ raise
498+ except :
499+ raise
453500 else :
454501 raise KeyError ('cosim, unexpected!' )
455502
0 commit comments