Skip to content

Commit

Permalink
fix ZeroDivisionError in utils.bottleneck (pytorch#11987)
Browse files Browse the repository at this point in the history
Summary:
**ZeroDivisionError** occurs when `cuda_prof_exec_time` is small enough.
This situation is normal for a project that has little CUDA work.

Or someone does not make his work transferred to CUDA successfully. In this time he profiles the code, this error occurs.
Pull Request resolved: pytorch#11987

Differential Revision: D10488568

Pulled By: soumith

fbshipit-source-id: db8c1e9e88a00943c100958ebef41a1cb56e7e65
  • Loading branch information
egg-west authored and facebook-github-bot committed Oct 22, 2018
1 parent 95caa37 commit e64f75a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions torch/utils/bottleneck/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,12 @@ def main():
# Print both the result of the CPU-mode and CUDA-mode autograd profilers
# if their execution times are very different.
cuda_prof_exec_time = cpu_time_total(autograd_prof_cuda)
cpu_prof_exec_time = cpu_time_total(autograd_prof_cpu)
pct_diff = cuda_prof_exec_time - cpu_prof_exec_time / cuda_prof_exec_time
if abs(pct_diff) > 0.05:
print_autograd_prof_summary(autograd_prof_cpu, 'CPU', autograd_prof_sortby, autograd_prof_topk)
if len(autograd_prof_cpu.function_events) > 0:
cpu_prof_exec_time = cpu_time_total(autograd_prof_cpu)
pct_diff = (cuda_prof_exec_time - cpu_prof_exec_time) / cuda_prof_exec_time
if abs(pct_diff) > 0.05:
print_autograd_prof_summary(autograd_prof_cpu, 'CPU', autograd_prof_sortby, autograd_prof_topk)

print_autograd_prof_summary(autograd_prof_cuda, 'CUDA', autograd_prof_sortby, autograd_prof_topk)

if __name__ == '__main__':
Expand Down

0 comments on commit e64f75a

Please sign in to comment.