How to find PyTorch source for specific functionality?

Adrian.1: <p>What is the recommend method for searching the PyTorch source code?</p>
<p>For example I’m attempting to find the source for Dropout. I begin with the doc :<br>
<a href="https://pytorch.org/docs/stable/_modules/torch/nn/modules/dropout.html" class="onebox" target="_blank" rel="nofollow noopener">https://pytorch.org/docs/stable/_modules/torch/nn/modules/dropout.html</a></p>
<p>Can see dropout is implemented as :</p>
<p>class Dropout(_DropoutNd):<br>
<span class="mention">@weak_script_method</span><br>
def forward(self, input):<br>
return F.dropout(input, self.p, self.training, self.inplace)</p>
<p>I wish to view how dropout is implemented but I’m unable to find the source for :<br>
F.dropout(input, self.p, self.training, self.inplace)</p>
<p>From viewing <a href="https://pytorch.org/docs/stable/_modules/torch/nn/functional.html#dropout2d" rel="nofollow noopener">https://pytorch.org/docs/stable/_modules/torch/nn/functional.html#dropout2d</a> it appears to be implemented as _VF.feature_dropout(input, p, training)) but where is _VF.feature_dropout(input, p, training)) implemented in source ?</p>
<p>I’ve searched for _VF.feature_dropout(input, p, training))  the results of which are : <a href="https://github.com/pytorch/pytorch/blob/a47749cb28bb630bc99601a64e24ad453d9583a9/torch/nn/functional.py" rel="nofollow noopener">https://github.com/pytorch/pytorch/blob/a47749cb28bb630bc99601a64e24ad453d9583a9/torch/nn/functional.py</a> but this does not show how dropout is implemented.</p>
<p>How to find the source for dropout and in general are there recommendations for navigating the PyTorch source <a href="https://github.com/pytorch/pytorch" rel="nofollow noopener">https://github.com/pytorch/pytorch</a> ?</p>

gladwig: <p>Hi Adrian,<br>
This will not be a good answer to your question, but I was looking for something similar and had basically the same set of questions.<br>
I found this <a href="https://github.com/pytorch/pytorch/blob/ceb4f84d12304d03a6a46693e54390869c0c208e/torch/nn/_functions/dropout.py" rel="nofollow noopener">dropout.py</a><br>
It is a couple years old, but has the code. It is sitting under torch/nn/_functions<br>
Its not there in the current repository. I wonder if it has something to do with the refactoring they did that moved state to ‘the graph’. Just a guess. Post if you find the current location!</p>

zjplab: <p>Have you checked what is <code>_VF</code>?<br>
Very strange:</p>
<pre><code class="lang-python">import torch
import sys
import types


class VFModule(types.ModuleType):
    def __init__(self, name):
        super(VFModule, self).__init__(name)
        self.vf = torch._C._VariableFunctions

    def __getattr__(self, attr):
        return getattr(self.vf, attr)

sys.modules[__name__] = VFModule(__name__)
</code></pre>
<p>My guess is <code>_VF</code> will navigate you to a specified module.<br>
Also notice there is a module called <code>dropout.cpp</code>:<a href="https://github.com/pytorch/pytorch/blob/d1623f4cc9334ade7376b3685bb91d3071e3b418/torch/csrc/api/src/nn/modules/dropout.cpp" rel="nofollow noopener">https://github.com/pytorch/pytorch/blob/d1623f4cc9334ade7376b3685bb91d3071e3b418/torch/csrc/api/src/nn/modules/dropout.cpp</a></p>
<p>And most of PyTorch’s computation internals are written in C++.</p>