NotImplementedError when using _backend.SpatialFullConvolution in latest pytorch

ttoosi: <p>Hi,<br>
For my code, I need to access <strong>_backend.SpatialFullConvolution_updateOutput</strong>, when I use it in an earlier version of PyTorch it works fine but in the newer version (<strong>‘1.3.0.dev20190814’)</strong> I get the following error:</p>
<p>_backend.SpatialFullConvolution_updateOutput(<br>
File “/conda-envs/pytorch_tensorflow/lib/python3.6/site-packages/torch/_thnn/utils.py”, line 27, in __ getattr __<br>
raise NotImplementedError</p>
<p>Is this behavior expected?</p>
<p>Thanks,<br>
Tahereh</p>

gchanan: <aside class="quote no-group" data-username="ttoosi" data-post="1" data-topic="53489">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/t/e5b9ba/48.png" class="avatar"> ttoosi:</div>
<blockquote>
<p>SpatialFullConvolution_updateOutput</p>
</blockquote>
</aside>
<p>what do you use it for?</p>

ttoosi: <p>Hi,</p>
<p>I am trying to access backward path parameters e.g. weights, like what is used for here:<br>
<aside class="onebox githubblob">
  <header class="source">
      <a href="https://github.com/willwx/sign-symmetry/blob/master/functional/af_conv2d_function.py" target="_blank" rel="nofollow noopener">github.com</a>
  </header>
  <article class="onebox-body">
    <h4><a href="https://github.com/willwx/sign-symmetry/blob/master/functional/af_conv2d_function.py" target="_blank" rel="nofollow noopener">willwx/sign-symmetry/blob/master/functional/af_conv2d_function.py</a></h4>
<pre><code class="lang-py">"""
A conv2d autograd Function that supports different feedforward and feedback weights
Uses the same C functions used in the legacy SpatialConvolution module to implement actual computation
References:
    - https://github.com/L0SG/feedback-alignment-pytorch/blob/master/lib/fa_linear.py
    - https://pytorch.org/docs/master/notes/extending.html
    - torch/legacy/nn/SpatialConvolution.py
"""

import torch.autograd as autograd
from torch._thnn import type2backend


class AsymmetricFeedbackConv2dFunc(autograd.Function):

    @staticmethod
    def forward(context, input, weight, weight_feedback, bias, stride, padding):
        _backend = type2backend[input.type()]
        input = input.contiguous()
        output = input.new()
</code></pre>

  This file has been truncated. <a href="https://github.com/willwx/sign-symmetry/blob/master/functional/af_conv2d_function.py" target="_blank" rel="nofollow noopener">show original</a>

  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>
</p>
<p>I was wondering if there is a substitute for this backend in the new version?</p>
<p>Thanks,<br>
Tahereh</p>

gchanan: <p>I’m not 100% sure what your code is doing, but it looks like you could probably use a backward hook to achieve the same effect.  “SpatialConvolutionMM” is the same as “thnn_conv2d” I believe.</p>

ttoosi: <p>Thanks for your reply.<br>
backward hook only gives me the gradients computed in each layer. I want to be able to write my backward function which does not assume backpropagation (symmetric weight). That’s why access to _backend.SpatialConvolutionMM_updateGradInput<br>
is important for my code. I would like to have access to such a function in the new Pytorch if it is possible.</p>

gchanan: <p>we don’t expose a function that does that anymore to Python. It’s still available in C++ (though not guaranteed to continue to exist), should be thnn_backward.</p>
<p>I’d probably just write your own version for this case, though, if this is the only updateGradInput variant you need.</p>

HaFred: <p>Hi, sorry to bring this up. But may I know how do you access either the <code>torch._thnn.type2backend</code> or <code>SpatialConvolutionMM</code> in pytorch &gt;1.5 nowadays? I am facing the same issue here…<br>
Thank you very much.</p>

ttoosi: <p>Hi! Unfortunately, I don’t have access to <code>torch._thnn.type2backend</code> in the newer pytorch. I had to find other ways.</p>