From c27336d3b9fa105d0ae913e240ea6223713b1479 Mon Sep 17 00:00:00 2001 From: Thom Lane Date: Wed, 25 Jul 2018 11:51:50 -0700 Subject: [PATCH] Corrections to profiling tutorial Corrected a race condition with stopping profiling. Added mx.nd.waitall to ensure all operations have completed, including GPU operations that might otherwise be missing. Also added alternative code for context selection GPU vs CPU, that had error before on machines with nvidia-smi. --- docs/tutorials/python/profiler.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/tutorials/python/profiler.md b/docs/tutorials/python/profiler.md index 81ecc2a84edd..d99bb19ee029 100644 --- a/docs/tutorials/python/profiler.md +++ b/docs/tutorials/python/profiler.md @@ -94,7 +94,10 @@ Let's define a method that will run one training iteration given data and label. ```python # Use GPU if available -ctx = mx.gpu() if mx.test_utils.list_gpus() else mx.cpu() +try: + mx.test_utils.list_gpus(); ctx = mx.gpu() +except: + ctx = mx.cpu() # Initialize the parameters with random weights net.collect_params().initialize(mx.init.Xavier(), ctx=ctx) @@ -144,7 +147,8 @@ profiler.set_state('run') run_training_iteration(*next(itr)) -# Ask the profiler to stop recording +# Ask the profiler to stop recording after operations have completed +mx.nd.waitall() profiler.set_state('stop') ```