How to watch the values of the local variables in functions?

username: YeeHoran
cooked: <p>Dear friends,</p>
<p>I am using spyder to debug a project built on PyTorch, I am in the trouble of how can I watch the values of the local variables in the Variable Explorer panel, please? With that, I can see the process in detail.</p>
<p>Thank you in advance!</p>

username: marksaroufim
cooked: <p>Tensor values are inspectable just like any other python variable. I usually just set <code>breakpoint()</code> in my code or use a library like. I haven’t checked whether Spyder renders things correctly but I believe it should, VS Code and Pycharm do it just fine</p>
<pre><code class="lang-auto">import rich
rich.inspect(tensor)
</code></pre>

username: YeeHoran
cooked: <p>Oh, thank you so much for your help!</p>
<p>I tried the approach, and got the following variable value as follows in the console panel, is it correct?</p>
<p>Thank you again!</p>
<p>!next<br>
╭─────────────────────────── &lt;class ‘torch.Tensor’&gt; ───────────────────────────╮<br>
│ ╭──────────────────────────────────────────────────────────────────────────╮ │<br>
│ │ tensor([2, 2, 2, 2, 2, 1, 2, 0], device=‘cuda:0’)                        │ │<br>
│ ╰──────────────────────────────────────────────────────────────────────────╯ │<br>
│                                                                              │<br>
│          data = tensor([2, 2, 2, 2, 2, 1, 2, 0], device=‘cuda:0’)            │<br>
│        device = device(type=‘cuda’, index=0)                                 │<br>
│         dtype = torch.int64                                                  │<br>
│          grad = None                                                         │<br>
│       grad_fn = None                                                         │<br>
│          imag = RuntimeError(‘imag is not implemented for tensors with       │<br>
│                 non-complex dtypes.’)                                        │<br>
│       is_cuda = True                                                         │<br>
│       is_leaf = True                                                         │<br>
│       is_meta = False                                                        │<br>
│     is_mkldnn = False                                                        │<br>
│        is_mlc = False                                                        │<br>
│        is_ort = False                                                        │<br>
│  is_quantized = False                                                        │<br>
│     is_sparse = False                                                        │<br>
│ is_sparse_csr = False                                                        │<br>
│     is_vulkan = False                                                        │<br>
│        is_xpu = False                                                        │<br>
│        layout = torch.strided                                                │<br>
│          name = None                                                         │<br>
│         names = (None,)                                                      │<br>
│          ndim = 1                                                            │<br>
│     output_nr = 0                                                            │<br>
│          real = RuntimeError(‘real is not implemented for tensors with       │<br>
│                 non-complex dtypes.’)                                        │<br>
│ requires_grad = False                                                        │<br>
│  retains_grad = False                                                        │<br>
│         shape = torch.Size([8])                                              │<br>
│             T = tensor([2, 2, 2, 2, 2, 1, 2, 0], device=‘cuda:0’)            │<br>
╰──────────────────────────────────────────────────────────────────────────────╯</p>

username: marksaroufim
cooked: <p>Yup that’s right a tensor is a data structure as you can see, if you just need the data then you can just pull it out with <code>tensor.data</code></p>