RuntimeError: Can't call numpy() on Variable that requires grad. Use var.detach().numpy() instead

username: amir_omidi
cooked: <p>Hi every one,<br>
I have a Machine learning program, which I was working on it until 2 weeks ago. I ran it on google colab (GPU). after 2 weeks vacation  I came back to it and ran without any change.<br>
I got the error:   RuntimeError: Can’t call numpy() on Variable that requires grad. Use var.detach().numpy() instead.<br>
I changed the runtime to Local there is no change.<br>
when I download the .jpynb on my PC and run it, there is no error. it seems that there have been some changes on google colab during these 2 weeks.<br>
can you help me to solve this problem?</p>
<p>exact error text:</p>
<p>RuntimeError                              Traceback (most recent call last)<br>
 in ()<br>
29         no_mive_criteria = 0.01,<br>
30         SNR_Lin = SNRs_List_Linear[i],<br>
—&gt; 31         SNR_dB = SNRs_List_dB[i])<br>
32<br>
33     model_save_name = ‘Modelof{}QAMforSNR{}’.format(order,EbN0s_List_dB[i])</p>
<p>8 frames<br>
/usr/local/lib/python3.6/dist-packages/torch/tensor.py in <strong>array</strong>(self, dtype)<br>
490     def <strong>array</strong>(self, dtype=None):<br>
491         if dtype is None:<br>
–&gt; 492             return self.numpy()<br>
493         else:<br>
494             return self.numpy().astype(dtype, copy=False)</p>
<p>RuntimeError: Can’t call numpy() on Variable that requires grad. Use var.detach().numpy() instead.</p>

username: ptrblck
cooked: <p>Could you check, if the line of code, which is raising this error, uses any <code>numpy()</code> calls?<br>
If so, replace it with <code>tensor.detach().numpy()</code> as suggested in the error message.</p>
<p>This error was added a while ago to make sure the user is aware, that Autograd won’t be able to track the numpy operations.</p>

username: amir_omidi
cooked: <p>In whole my code there is no call for numpy()</p>

username: amir_omidi
cooked: <aside class="quote no-group" data-username="ptrblck" data-post="2" data-topic="79187">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/48/1823_2.png" class="avatar"> ptrblck:</div>
<blockquote>
<p>while ago to make sure the user is aware, that Autograd won’t be able to track the numpy operations</p>
</blockquote>
</aside>
<p>is there any way to ignore this error?</p>

username: ptrblck
cooked: <p>You could use a <code>try</code> block to get the exception, but it wouldn’t ignore the error and the operation won’t be successful.</p>

username: amir_omidi
cooked: <p>What do you think about successful running on PC and getting this error on google colab</p>

username: ptrblck
cooked: <p>The versions might be different. You could check them via <code>print(torch.__version__)</code>.</p>

username: amir_omidi
cooked: <aside class="quote no-group quote-modified" data-username="ptrblck" data-post="7" data-topic="79187">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/48/1823_2.png" class="avatar"> ptrblck:</div>
<blockquote>
<p>print(torch.<strong>version</strong>)</p>
</blockquote>
</aside>
<p>yes mine is 1.4 and in google colab is 1.5.0+cu101</p>