pytorch

Where is the source code of pytorch conv2d?


Where do I find the source code of the pytorch function conv2d?

It should be in torch.nn.functional but I only find _add_docstr lines, if i search for conv2d. I looked here:

https://github.com/pytorch/pytorch/blob/master/torch/nn/functional.py

Update: It's is not my typing, I do mean the function. Conv2d class uses conv2d function from the nn.functional

Here:

https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/conv.py

On line 338:

return F.conv2d(F.pad(input, expanded_padding, mode='circular')

F is how they import functional

So then I went there, but I don't find the code.


Solution

  • The functional code is implemented in C++. As of version 1.13.1 the entry point into the C++ code for conv2d is at aten/src/ATen/native/Convolution.cpp:804.

    If you are interested more generally in how functions are registered to the API then you can take a look at aten/src/ATen/native/README.md. A deeper dive will benefit from understanding some of the design decisions in PyTorch. For example, the dispatcher mechanism (see here). More general information can be found in the PyTorch developer's wiki, though keep in mind this wiki is primarily a tool for contributors and is not as polished as the Python API documentation. IMO a good starting point is the Core Frontend Onboarding page which gives links to most everything needed to get your head around the PyTorch source code.