Difference between torch::Tensor and at::Tensor

username: Carsten_Ditzel
cooked: <p>I dont quite get the difference between those two tensor entities. I roughly remember to have read somewhere that at::Tensor should best be avoided for some reason I cannot recall, but what is the general advise here?<br>
thanks in advance</p>

username: ptrblck
cooked: <p><code>at::Tensor</code> is not differentiable while <code>torch::Tensor</code> is. It was similar to the difference between <code>Variables</code> and pure <code>tensors</code> in Python pre <code>0.4.0</code>.<br>
As far as I know <code>torch::Tensors</code> won’t have any overhead in using them even if you don’t need to differentiate them, so that might be the reason to prefer the <code>torch</code> namespace for creating tensors.</p>

username: soldierofhell
cooked: <p>Hi,</p>
<p>I feel like even in “official” code those two are used interchangeably (inconsitently?). Lets take for example cannonical tutorial <a href="https://pytorch.org/tutorials/advanced/cpp_extension.html#writing-the-c-op" rel="nofollow noopener">https://pytorch.org/tutorials/advanced/cpp_extension.html#writing-the-c-op</a></p>
<p>Header of forward pass returns <code>std::vector&lt;at::Tensor&gt;</code> (and where is the casting inside?):</p>
<pre><code class="lang-auto">std::vector&lt;at::Tensor&gt; lltm_forward(
    torch::Tensor input,
    torch::Tensor weights,
    torch::Tensor bias,
    torch::Tensor old_h,
    torch::Tensor old_cell)
</code></pre>
<p>and then later header of backward pass returns <code>std::vector&lt;torch::Tensor&gt;</code></p>
<pre><code class="lang-auto">std::vector&lt;torch::Tensor&gt; lltm_backward(
    torch::Tensor grad_h,
    torch::Tensor grad_cell,
    torch::Tensor new_cell,
    torch::Tensor input_gate,
    torch::Tensor output_gate,
    torch::Tensor candidate_cell,
    torch::Tensor X,
    torch::Tensor gate_weights,
    torch::Tensor weights)
</code></pre>
<p>Regards,</p>

username: soldierofhell
cooked: <p>Another example are brand new cpu ops in torchvision:<br>
<aside class="onebox whitelistedgeneric">
  <header class="source">
      <img src="https://github.githubassets.com/favicon.ico" class="site-icon" width="16" height="16">
      <a href="https://github.com/pytorch/vision/tree/master/torchvision/csrc/cpu" target="_blank" rel="nofollow noopener">GitHub</a>
  </header>
  <article class="onebox-body">
    <img src="https://avatars2.githubusercontent.com/u/21003710?s=400&amp;amp;v=4" class="thumbnail onebox-avatar" width="60" height="60">

<h3><a href="https://github.com/pytorch/vision/tree/master/torchvision/csrc/cpu" target="_blank" rel="nofollow noopener">pytorch/vision</a></h3>

<p>Datasets, Transforms and Models specific to Computer Vision - pytorch/vision</p>


  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>
<br>
written purely using <code>at::Tensor</code> (actually I even see also <code>TH/TH.h</code> headers here, but no <code>torch::Tensor</code>)</p>

username: Kiki_Rizki_Arpiandi
cooked: <p>Ok guys, I still do not understand about this torch::Tensor vs at::Tensor stuff, Will bad things happen if I use at::Tensor instead of torch::Tensor ? d</p>

username: vincentqb
cooked: <p>In case someone stumble on this thread, see also <a href="https://github.com/pytorch/pytorch/issues/14257#issuecomment-440487374" rel="noopener nofollow ugc">comment</a></p>