How to find PyTorch source for specific functionality?

What is the recommend method for searching the PyTorch source code?

For example I’m attempting to find the source for Dropout. I begin with the doc :

Can see dropout is implemented as :

class Dropout(_DropoutNd):
def forward(self, input):
return F.dropout(input, self.p,, self.inplace)

I wish to view how dropout is implemented but I’m unable to find the source for :
F.dropout(input, self.p,, self.inplace)

From viewing it appears to be implemented as _VF.feature_dropout(input, p, training)) but where is _VF.feature_dropout(input, p, training)) implemented in source ?

I’ve searched for _VF.feature_dropout(input, p, training)) the results of which are : but this does not show how dropout is implemented.

How to find the source for dropout and in general are there recommendations for navigating the PyTorch source ?


Hi Adrian,
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.
I found this
It is a couple years old, but has the code. It is sitting under torch/nn/_functions
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!

1 Like

Have you checked what is _VF?
Very strange:

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__)

My guess is _VF will navigate you to a specified module.
Also notice there is a module called dropout.cpp:

And most of PyTorch’s computation internals are written in C++.