Skip to content

Commit

Permalink
Corrections to profiling tutorial (apache#11887)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thomelane authored and indhub committed Jul 29, 2018
1 parent 0fe3029 commit 8a702c4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions docs/tutorials/python/profiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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')
```

Expand Down

0 comments on commit 8a702c4

Please sign in to comment.