<h2 dir="auto">Issue description</h2>
<p dir="auto">in a simple test network I get an error when dropout layer is included (error does not happen when the dropout layer is excluded):</p>
<p dir="auto">Traceback (most recent call last):<br>
File "testnet.py", line 48, in <br>
r = net(V)<br>
RuntimeError:<br>
Function.apply returned the wrong number of outputs.:<br>
operation failed in interpreter:<br>
/home/tester/anaconda3/lib/python3.6/site-packages/torch/nn/functional.py(554): dropout<br>
/home/tester/anaconda3/lib/python3.6/site-packages/torch/nn/modules/dropout.py(53): forward<br>
/home/tester/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py(491): <strong>call</strong><br>
testnet.py(25): forward<br>
testnet.py(48): </p>
<h2 dir="auto">Code example</h2>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import torch
from torch import jit
import torch.nn as nn
from torch.autograd import Variable
import torch.optim as optim........

  
@torch.jit.compile(nderivs=1)
class TestNet(nn.Module):
    def __init__(self):
        super(TestNet, self).__init__()
        self.net1 = nn.Linear(100, 200)
        self.net2 = nn.Linear(200, 1)
        self.bn = nn.BatchNorm1d(200)
        self.sigmoid = nn.Sigmoid()
        self.ReLU = nn.ReLU(inplace=False)
        self.drop = nn.Dropout(0.5)
    def forward(self, V):
        return self.sigmoid(self.net2(self.drop(self.ReLU(self.bn(self.net1(V)))
#        return self.sigmoid(self.net2(self.ReLU(self.bn(self.net1(V))))).squeez


use_cuda = False
net = TestNet()
criterion = nn.BCELoss()
if use_cuda:
    net.cuda()
    criterion.cuda()
    V = Variable(torch.randn(100, 100)).cuda()
    label = Variable(torch.randn(100)).cuda()
else:
    V = Variable(torch.randn(100, 100))
    label = Variable(torch.randn(100))

optim_betas = (0.9, 0.999)
optimizer = optim.Adam(filter(lambda p: p.requires_grad, net.parameters()), lr=0.01, betas=optim_betas)
criterion = nn.BCELoss()

net.train()
for i in range(0,1000000):
    net.zero_grad()
    r = net(V)
    err = criterion(r, label)
    err.backward()...
"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">torch</span>
<span class="pl-k">from</span> <span class="pl-s1">torch</span> <span class="pl-k">import</span> <span class="pl-s1">jit</span>
<span class="pl-k">import</span> <span class="pl-s1">torch</span>.<span class="pl-s1">nn</span> <span class="pl-k">as</span> <span class="pl-s1">nn</span>
<span class="pl-k">from</span> <span class="pl-s1">torch</span>.<span class="pl-s1">autograd</span> <span class="pl-k">import</span> <span class="pl-v">Variable</span>
<span class="pl-k">import</span> <span class="pl-s1">torch</span>.<span class="pl-s1">optim</span> <span class="pl-k">as</span> <span class="pl-s1">optim</span>........

  
<span class="pl-en">@<span class="pl-s1">torch</span>.<span class="pl-s1">jit</span>.<span class="pl-en">compile</span>(<span class="pl-s1">nderivs</span><span class="pl-c1">=</span><span class="pl-c1">1</span>)</span>
<span class="pl-k">class</span> <span class="pl-v">TestNet</span>(<span class="pl-s1">nn</span>.<span class="pl-v">Module</span>):
    <span class="pl-k">def</span> <span class="pl-en">__init__</span>(<span class="pl-s1">self</span>):
        <span class="pl-en">super</span>(<span class="pl-v">TestNet</span>, <span class="pl-s1">self</span>).<span class="pl-en">__init__</span>()
        <span class="pl-s1">self</span>.<span class="pl-s1">net1</span> <span class="pl-c1">=</span> <span class="pl-s1">nn</span>.<span class="pl-v">Linear</span>(<span class="pl-c1">100</span>, <span class="pl-c1">200</span>)
        <span class="pl-s1">self</span>.<span class="pl-s1">net2</span> <span class="pl-c1">=</span> <span class="pl-s1">nn</span>.<span class="pl-v">Linear</span>(<span class="pl-c1">200</span>, <span class="pl-c1">1</span>)
        <span class="pl-s1">self</span>.<span class="pl-s1">bn</span> <span class="pl-c1">=</span> <span class="pl-s1">nn</span>.<span class="pl-v">BatchNorm1d</span>(<span class="pl-c1">200</span>)
        <span class="pl-s1">self</span>.<span class="pl-s1">sigmoid</span> <span class="pl-c1">=</span> <span class="pl-s1">nn</span>.<span class="pl-v">Sigmoid</span>()
        <span class="pl-s1">self</span>.<span class="pl-v">ReLU</span> <span class="pl-c1">=</span> <span class="pl-s1">nn</span>.<span class="pl-v">ReLU</span>(<span class="pl-s1">inplace</span><span class="pl-c1">=</span><span class="pl-c1">False</span>)
        <span class="pl-s1">self</span>.<span class="pl-s1">drop</span> <span class="pl-c1">=</span> <span class="pl-s1">nn</span>.<span class="pl-v">Dropout</span>(<span class="pl-c1">0.5</span>)
    <span class="pl-k">def</span> <span class="pl-en">forward</span>(<span class="pl-s1">self</span>, <span class="pl-v">V</span>):
        <span class="pl-k">return</span> <span class="pl-s1">self</span>.<span class="pl-s1">sigmoid</span>(<span class="pl-s1">self</span>.<span class="pl-s1">net2</span>(<span class="pl-s1">self</span>.<span class="pl-s1">drop</span>(<span class="pl-s1">self</span>.<span class="pl-v">ReLU</span>(<span class="pl-s1">self</span>.<span class="pl-en">bn</span>(<span class="pl-s1">self</span>.<span class="pl-en">net1</span>(<span class="pl-v">V</span>)))
<span class="pl-c">#        return self.sigmoid(self.net2(self.ReLU(self.bn(self.net1(V))))).squeez</span>


<span class="pl-s1">use_cuda</span> <span class="pl-c1">=</span> <span class="pl-c1">False</span>
<span class="pl-s1">net</span> <span class="pl-c1">=</span> <span class="pl-v">TestNet</span>()
<span class="pl-s1">criterion</span> <span class="pl-c1">=</span> <span class="pl-s1">nn</span>.<span class="pl-v">BCELoss</span>()
<span class="pl-k">if</span> <span class="pl-s1">use_cuda</span>:
    <span class="pl-s1">net</span>.<span class="pl-en">cuda</span>()
    <span class="pl-s1">criterion</span>.<span class="pl-en">cuda</span>()
    <span class="pl-v">V</span> <span class="pl-c1">=</span> <span class="pl-v">Variable</span>(<span class="pl-s1">torch</span>.<span class="pl-en">randn</span>(<span class="pl-c1">100</span>, <span class="pl-c1">100</span>)).<span class="pl-en">cuda</span>()
    <span class="pl-s1">label</span> <span class="pl-c1">=</span> <span class="pl-v">Variable</span>(<span class="pl-s1">torch</span>.<span class="pl-en">randn</span>(<span class="pl-c1">100</span>)).<span class="pl-en">cuda</span>()
<span class="pl-s1">else</span>:
    <span class="pl-v">V</span> <span class="pl-c1">=</span> <span class="pl-v">Variable</span>(<span class="pl-s1">torch</span>.<span class="pl-en">randn</span>(<span class="pl-c1">100</span>, <span class="pl-c1">100</span>))
    <span class="pl-s1">label</span> <span class="pl-c1">=</span> <span class="pl-v">Variable</span>(<span class="pl-s1">torch</span>.<span class="pl-en">randn</span>(<span class="pl-c1">100</span>))

<span class="pl-s1">optim_betas</span> <span class="pl-c1">=</span> (<span class="pl-c1">0.9</span>, <span class="pl-c1">0.999</span>)
<span class="pl-s1">optimizer</span> <span class="pl-c1">=</span> <span class="pl-s1">optim</span>.<span class="pl-v">Adam</span>(<span class="pl-en">filter</span>(<span class="pl-k">lambda</span> <span class="pl-s1">p</span>: <span class="pl-s1">p</span>.<span class="pl-s1">requires_grad</span>, <span class="pl-s1">net</span>.<span class="pl-en">parameters</span>()), <span class="pl-s1">lr</span><span class="pl-c1">=</span><span class="pl-c1">0.01</span>, <span class="pl-s1">betas</span><span class="pl-c1">=</span><span class="pl-s1">optim_betas</span>)
<span class="pl-s1">criterion</span> <span class="pl-c1">=</span> <span class="pl-s1">nn</span>.<span class="pl-v">BCELoss</span>()

<span class="pl-s1">net</span>.<span class="pl-en">train</span>()
<span class="pl-k">for</span> <span class="pl-s1">i</span> <span class="pl-c1">in</span> <span class="pl-en">range</span>(<span class="pl-c1">0</span>,<span class="pl-c1">1000000</span>):
    <span class="pl-s1">net</span>.<span class="pl-en">zero_grad</span>()
    <span class="pl-s1">r</span> <span class="pl-c1">=</span> <span class="pl-en">net</span>(<span class="pl-v">V</span>)
    <span class="pl-s1">err</span> <span class="pl-c1">=</span> <span class="pl-en">criterion</span>(<span class="pl-s1">r</span>, <span class="pl-s1">label</span>)
    <span class="pl-s1">err</span>.<span class="pl-en">backward</span>()...</pre></div>
<h2 dir="auto">System Info</h2>
<p dir="auto">PyTorch version: 0.5.0a0+59f5f9a<br>
Is debug build: No<br>
CUDA used to build PyTorch: None</p>
<p dir="auto">OS: Ubuntu 16.04.4 LTS<br>
GCC version: (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609<br>
CMake version: version 3.9.4</p>
<p dir="auto">Python version: 3.6<br>
Is CUDA available: No<br>
CUDA runtime version: No CUDA<br>
GPU models and configuration: No CUDA<br>
Nvidia driver version: No CUDA<br>
cuDNN version: No CUDA</p>
<p dir="auto">Versions of relevant libraries:<br>
[pip] numpy (1.14.0)<br>
[pip] numpydoc (0.7.0)<br>
[pip] torch (0.5.0a0+59f5f9a)<br>
[conda] magma-cuda80              2.3.0                         1    pytorch<br>
[conda] torch                     0.5.0a0+59f5f9a           </p>
<p dir="auto">Code example:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import torch
import torch.nn.functional as F

@torch.jit.trace(torch.zeros(1, 2, 3))
def dropout_test(x):
    x = torch.neg(x)
    return F.dropout(x)

dropout_test(torch.zeros(1, 2, 3, requires_grad=True))"><pre class="notranslate"><code class="notranslate">import torch
import torch.nn.functional as F

@torch.jit.trace(torch.zeros(1, 2, 3))
def dropout_test(x):
    x = torch.neg(x)
    return F.dropout(x)

dropout_test(torch.zeros(1, 2, 3, requires_grad=True))
</code></pre></div>
<p dir="auto">Output:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="17:20:04 ~ $ python dropoutcrash.py
Traceback (most recent call last):
  File &quot;dropoutcrash.py&quot;, line 9, in &lt;module&gt;
    dropout_test(torch.zeros(1, 2, 3, requires_grad=True))
RuntimeError:
VariableType::ID() not implemented:
operation failed in interpreter:
/Users/jamesreed/onnx-fairseq/pytorch/torch/nn/functional.py(555): dropout
dropoutcrash.py(7): dropout_test
/Users/jamesreed/onnx-fairseq/pytorch/torch/jit/__init__.py(475): wrapper
dropoutcrash.py(4): &lt;module&gt;"><pre class="notranslate"><code class="notranslate">17:20:04 ~ $ python dropoutcrash.py
Traceback (most recent call last):
  File "dropoutcrash.py", line 9, in &lt;module&gt;
    dropout_test(torch.zeros(1, 2, 3, requires_grad=True))
RuntimeError:
VariableType::ID() not implemented:
operation failed in interpreter:
/Users/jamesreed/onnx-fairseq/pytorch/torch/nn/functional.py(555): dropout
dropoutcrash.py(7): dropout_test
/Users/jamesreed/onnx-fairseq/pytorch/torch/jit/__init__.py(475): wrapper
dropoutcrash.py(4): &lt;module&gt;
</code></pre></div>
<p dir="auto">Discussed with <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/zdevito/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/zdevito">@zdevito</a> offline, this appears to the the tracer tracing this op in the wrong mode, and two things are incorrect:</p>
<ol dir="auto">
<li>The <code class="notranslate">tracing_autograd_python_function</code> flag is set</li>
<li>The op has a Handle output</li>
</ol>