Why adaptive_avg_pool1d became adaptive_avg_pool2d in make_fx?

heshuju: <p>I need to use the make_fx interface to output aten ops and convert them into corresponding torch diaclects. But I found that make_fx will replace some ops. How does this happen and how should I solve it?</p>
<pre><code class="lang-auto">import torch
import os
from torch.fx.experimental.proxy_tensor import make_fx
print("os:pid:", os.getpid())
class Aten_Adaptive_avg_pool1d(torch.nn.Module):
    def __init__(self, output_size):
        super().__init__()
        self.output_size=output_size
    def forward(self, self_):
        return torch.ops.aten.adaptive_avg_pool1d(self_, output_size=self.output_size)

if __name__ == "__main__":
    model = Aten_Adaptive_avg_pool1d(3)
    model.train(False)
    model = model.eval()
    #"adaptive_avg_pool1d": {"inputs": 1, "outputs": 1, "attrs": {"output_size": [3]}, "input_shapes": ["1,32,128"]},
    input = torch.randn(1,32,128)
    traced_model = make_fx(model)(input)
    print(traced_model.graph)
    pass
</code></pre>
<p>and It print out:</p>
<pre><code class="lang-auto">graph():
    %arg0_1 : [num_users=1] = placeholder[target=arg0_1]
    %unsqueeze : [num_users=1] = call_function[target=torch.ops.aten.unsqueeze.default](args = (%arg0_1, -2), kwargs = {})
    %_adaptive_avg_pool2d : [num_users=1] = call_function[target=torch.ops.aten._adaptive_avg_pool2d.default](args = (%unsqueeze, [1, 3]), kwargs = {})
    %squeeze : [num_users=1] = call_function[target=torch.ops.aten.squeeze.dim](args = (%_adaptive_avg_pool2d, -2), kwargs = {})
    return squeeze
</code></pre>
<p>I need some help, thanks~</p>

heshuju: <p>I  find  adaptive_avg_pool1d expand it  to adaptive_avg_pool2d.in cpp library .<br>
How does make_fx trace back to function calls in the cpp library?</p>
<aside class="onebox githubblob" data-onebox-src="https://github.com/pytorch/pytorch/blob/470132c6a10d1279ee66a43778edb91f1032512f/aten/src/ATen/native/Pooling.cpp#L43">
  <header class="source">

      <a href="https://github.com/pytorch/pytorch/blob/470132c6a10d1279ee66a43778edb91f1032512f/aten/src/ATen/native/Pooling.cpp#L43" target="_blank" rel="noopener nofollow ugc">github.com/pytorch/pytorch</a>
  </header>

  <article class="onebox-body">
    <h4><a href="https://github.com/pytorch/pytorch/blob/470132c6a10d1279ee66a43778edb91f1032512f/aten/src/ATen/native/Pooling.cpp#L43" target="_blank" rel="noopener nofollow ugc">aten/src/ATen/native/Pooling.cpp</a></h4>

<div class="git-blob-info">
  <a href="https://github.com/pytorch/pytorch/blob/470132c6a10d1279ee66a43778edb91f1032512f/aten/src/ATen/native/Pooling.cpp#L43" rel="noopener nofollow ugc"><code>470132c6a</code></a>
</div>



    <pre class="onebox"><code class="lang-cpp">
      <ol class="start lines" start="33" style="counter-reset: li-counter 32 ;">
          <li>static void check1d(</li>
          <li>    const char* function_name,</li>
          <li>    const char* argument_name,</li>
          <li>    IntArrayRef x) {</li>
          <li>  TORCH_CHECK(</li>
          <li>      x.size() == 1,</li>
          <li>      function_name, "() argument '", argument_name,</li>
          <li>      "' should contain one int (got ", x.size(), ")");</li>
          <li>}</li>
          <li></li>
          <li class="selected">Tensor adaptive_avg_pool1d(const Tensor &amp; self, IntArrayRef output_size) {</li>
          <li>  checkDimRange("adaptive_avg_pool1d", TensorArg(self, "self", 1), 2, 4 /* exclusive */);</li>
          <li>  check1d("adaptive_avg_pool1d", "output_size", output_size);</li>
          <li></li>
          <li>  auto output = at::adaptive_avg_pool2d(</li>
          <li>      self.unsqueeze(-2),</li>
          <li>      {1, output_size[0]});</li>
          <li></li>
          <li>  return output.squeeze(-2);</li>
          <li>}</li>
          <li></li>
      </ol>
    </code></pre>



  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>