python -m torch.utils.bottleneck /path/to/source/script.py [args]
    

where [args] are any number of arguments to  script.py  , or run ` python  -m
torch.utils.bottleneck  -h  ` for more usage instructions.

Warning

Because your script will be profiled, please ensure that it exits in a finite
amount of time.

Warning

Due to the asynchronous nature of CUDA kernels, when running against CUDA
code, the cProfile output and CPU-mode autograd profilers may not show correct
timings: the reported CPU time reports the amount of time used to launch the
kernels but does not include the time the kernel spent executing on a GPU
unless the operation does a synchronize. Ops that do synchronize appear to be
extremely expensive under regular CPU-mode profilers. In these case where
timings are incorrect, the CUDA-mode autograd profiler may be helpful.

Note

To decide which (CPU-only-mode or CUDA-mode) autograd profiler output to look
at, you should first check if your script is CPU-bound (“CPU total time is
much greater than CUDA total time”). If it is CPU-bound, looking at the
results of the CPU-mode autograd profiler will help. If on the other hand your
script spends most of its time executing on the GPU, then it makes sense to
start looking for responsible CUDA operators in the output of the CUDA-mode
autograd profiler.

Of course the reality is much more complicated and your script might not be in
one of those two extremes depending on the part of the model you’re
evaluating. If the profiler outputs don’t help, you could try looking at the
result of [ ` torch.autograd.profiler.emit_nvtx()  `
](autograd.html#torch.autograd.profiler.emit_nvtx
"torch.autograd.profiler.emit_nvtx") with ` nvprof  ` . However, please take
into account that the NVTX overhead is very high and often gives a heavily
skewed timeline.

Warning

If you are profiling CUDA code, the first profiler that ` bottleneck  ` runs
(cProfile) will include the CUDA startup time (CUDA buffer allocation cost) in
its time reporting. This should not matter if your bottlenecks result in code
much slower than the CUDA startup time.

For more complicated uses of the profilers (like in a multi-GPU case), please
see [ https://docs.python.org/3/library/profile.html
](https://docs.python.org/3/library/profile.html) or [ `
torch.autograd.profiler.profile()  `
](autograd.html#torch.autograd.profiler.profile
"torch.autograd.profiler.profile") for more information.

[ Next ![](_static/images/chevron-right-orange.svg) ](checkpoint.html
"torch.utils.checkpoint") [ ![](_static/images/chevron-right-orange.svg)
Previous ](storage.html "torch.Storage")

* * *

© Copyright 2019, Torch Contributors.

Built with [ Sphinx ](http://sphinx-doc.org/) using a [ theme
](https://github.com/rtfd/sphinx_rtd_theme) provided by [ Read the Docs
](https://readthedocs.org) .

  * torch.utils.bottleneck 

![](https://www.googleadservices.com/pagead/conversion/795629140/?label=txkmCPmdtosBENSssfsC&guid=ON&script=0)

##  Docs

Access comprehensive developer documentation for PyTorch

[ View Docs ](https://pytorch.org/docs/stable/index.html)

##  Tutorials

Get in-depth tutorials for beginners and advanced developers

[ View Tutorials ](https://pytorch.org/tutorials)

##  Resources

Find development resources and get your questions answered

[ View Resources ](https://pytorch.org/resources)

[ ](https://pytorch.org/)

  * [ PyTorch ](https://pytorch.org/)
  * [ Get Started ](https://pytorch.org/get-started)
  * [ Features ](https://pytorch.org/features)
  * [ Ecosystem ](https://pytorch.org/ecosystem)
  * [ Blog ](https://pytorch.org/blog/)
  * [ Contributing ](https://github.com/pytorch/pytorch/blob/master/CONTRIBUTING.md)

  * [ Resources ](https://pytorch.org/resources)
  * [ Tutorials ](https://pytorch.org/tutorials)
  * [ Docs ](https://pytorch.org/docs/stable/index.html)
  * [ Discuss ](https://discuss.pytorch.org)
  * [ Github Issues ](https://github.com/pytorch/pytorch/issues)
  * [ Brand Guidelines ](htt