I wanted to see how the conv1d module is implemented https://pytorch.org/docs/stable/_modules/torch/nn/modules/conv.html#Conv1d. So I looked at functional.py but still couldn’t find the looping and cross-correlation computation.
Then I searched Github by keyword ‘conv1d’, checked conv.cpp https://github.com/pytorch/pytorch/blob/eb5d28ecefb9d78d4fff5fac099e70e5eb3fbe2e/torch/csrc/api/src/nn/modules/conv.cpp 1 but still couldn’t locate where the computation is happening.
My question is two-fold.
Where is the source code that "conv1d” is implemented?
In general, if I want to check how the modules are implemented, where is the best place to find? Any pointer to the documentation will be appreciated. Thank you.
The PyTorch conv1d is defined as a one-dimensional convolution that is applied over an input signal collected from some input planes. In detail, we will discuss Conv1d using PyTorch in python.
Figure-3: PyTorch code to showcase that Conv1d and Linear layer operations are equivalent.
groups controls the connections between inputs and outputs. in_channels and out_channels must both be divisible by groups .
conv.cpp
file you're linking uses torch::conv1d
, which is defined here and uses at::convolution
which in turn uses at::_convolution
, which dispatches to multiple variants, for instance at::cudnn_convolution
. at::cudnn_convolution
is, I believe, created here via a markup file and just plugs in directly to cuDNN
implementation (though I cannot pinpoint the exact point in code when that happens).Below is an answer that I got from pytorch discussion board:
I believe the “handroll”-ed convolution is defined here: https://github.com/pytorch/pytorch/blob/master/aten/src/THNN/generic/SpatialConvolutionMM.c 3
The NN module implementations are here: https://github.com/pytorch/pytorch/tree/master/aten/src The GPU version is in THCUNN and the CPU version in THNN
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With