<p dir="auto">In the autograd tutorial, <a href="https://pytorch.org/tutorials/beginner/blitz/autograd_tutorial.html" rel="nofollow">https://pytorch.org/tutorials/beginner/blitz/autograd_tutorial.html</a></p>
<blockquote>
<p dir="auto">print(x.grad)</p>
</blockquote>
<p dir="auto">gives output:</p>
<blockquote>
<p dir="auto">tensor([[4.5000, 4.5000],<br>
[4.5000, 4.5000]])</p>
</blockquote>
<p dir="auto">but it hangs afterwards.</p>
<p dir="auto">pytorch version: 1.5.0<br>
python: 3.7.7<br>
OS: windows 7</p>
<p dir="auto">cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/ezyang/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/ezyang">@ezyang</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/ssnl/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/ssnl">@ssnl</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/albanD/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/albanD">@albanD</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/zou3519/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/zou3519">@zou3519</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/gqchen/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/gqchen">@gqchen</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/peterjc123/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/peterjc123">@peterjc123</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/nbcsm/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/nbcsm">@nbcsm</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/guyang3532/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/guyang3532">@guyang3532</a></p>
<p dir="auto">Whenever backward() is called to compute gradients the python script never terminates. The backward function is not per se blocking and all lines after it are still executed however the script just does not terminate. This may be related with the operation system which is Windows 7 or with the use of  conda. At least there is another <a href="https://stackoverflow.com/questions/57857690/pytorch-autograd-obstructs-script-from-terminating" rel="nofollow">(post on Stack Overflow)</a>  describing the same problem in the same environment.</p>
<h2 dir="auto">To Reproduce</h2>
<p dir="auto">Steps to reproduce the behavior:</p>
<ol dir="auto">
<li>install PyTorch on windows 7 via conda (<code class="notranslate">conda create --name grad_test pytorch -c pytorch</code>)</li>
<li>run example code given below taken from the post on Stack Overflow</li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import torch

x = torch.randn(3, requires_grad=True)
y = x * 2
print(y)

gradients = torch.tensor([0.1, 1.0, 0.0001], dtype=torch.float)
y.backward(gradients)
print(x.grad)

print(&quot;all done&quot;)"><pre class="notranslate"><code class="notranslate">import torch

x = torch.randn(3, requires_grad=True)
y = x * 2
print(y)

gradients = torch.tensor([0.1, 1.0, 0.0001], dtype=torch.float)
y.backward(gradients)
print(x.grad)

print("all done")
</code></pre></div>

<h2 dir="auto">Expected behavior</h2>
<p dir="auto">Script runs and exits after printing "all done".</p>

<h2 dir="auto">Environment</h2>
<p dir="auto">PyTorch version: 1.3.0<br>
Is debug build: No<br>
CUDA used to build PyTorch: 10.1</p>
<p dir="auto">OS: Microsoft Windows 7 Enterprise<br>
CMake version: version 3.9.6</p>
<p dir="auto">Python version: 3.7<br>
Is CUDA available: Yes<br>
CUDA runtime version: 10.1.243<br>
GPU models and configuration: GPU 0: GeForce GTX 1080<br>
Nvidia driver version: 441.12<br>
cuDNN version: Could not collect</p>
<p dir="auto">Versions of relevant libraries:<br>
[pip] numpy==1.17.3<br>
[pip] torch==1.3.0<br>
[pip] torchvision==0.4.1<br>
[conda] blas                      1.0                         mkl    anaconda<br>
[conda] libblas                   3.8.0                    14_mkl    conda-forge<br>
[conda] libcblas                  3.8.0                    14_mkl    conda-forge<br>
[conda] liblapack                 3.8.0                    14_mkl    conda-forge<br>
[conda] mkl                       2019.4                      245<br>
[conda] mkl-service               2.3.0            py37hfa6e2cd_0    conda-forge<br>
[conda] pytorch                   1.3.0           py3.7_cuda101_cudnn7_0    pytorch<br>
[conda] torchvision               0.4.1                py37_cu101    pytorch</p>
<p dir="auto">cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/ezyang/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/ezyang">@ezyang</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/ssnl/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/ssnl">@ssnl</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/albanD/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/albanD">@albanD</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/zou3519/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/zou3519">@zou3519</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/gqchen/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/gqchen">@gqchen</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/peterjc123/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/peterjc123">@peterjc123</a></p>