<h2 dir="auto">To Reproduce</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import torch

class Model(torch.jit.ScriptModule):
    @torch.jit.script_method
    def forward(self, input):
        # type: (Tensor) -&gt; Tensor
        return input
        
class TupleModel(Model):
    @torch.jit.script_method
    def forward(self, input):
        # type: (Tuple[Tensor, Tensor]) -&gt; Tuple[Tensor, Tensor]
        return input

m1 = Model()
m2 = TupleModel()
x = torch.randn(3, 3)
m1(x)
m2((x, x))

RuntimeError: Method 'forward' already defined (insert at ../torch/csrc/api/include/torch/ordered_dict.h:359)"><pre class="notranslate"><code class="notranslate">import torch

class Model(torch.jit.ScriptModule):
    @torch.jit.script_method
    def forward(self, input):
        # type: (Tensor) -&gt; Tensor
        return input
        
class TupleModel(Model):
    @torch.jit.script_method
    def forward(self, input):
        # type: (Tuple[Tensor, Tensor]) -&gt; Tuple[Tensor, Tensor]
        return input

m1 = Model()
m2 = TupleModel()
x = torch.randn(3, 3)
m1(x)
m2((x, x))

RuntimeError: Method 'forward' already defined (insert at ../torch/csrc/api/include/torch/ordered_dict.h:359)
</code></pre></div>
<p dir="auto">I've seen one case where this errors out silently and I get incorrect behavior. I am not putting it here because it is a really big case, I will try to shorten it if it is of interest.</p>
<h2 dir="auto">Expected behavior</h2>
<p dir="auto">No crash</p>
<p dir="auto">Code example:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import torch

class Base(torch.jit.ScriptModule):
    def __init__(self):
        super().__init__()

    @torch.jit.script_method
    def forward(self, x):
        for i in range(x.size(0)):
            x += x[i].sum()
        return x


class Derived(Base):
    def __init__(self):
        super().__init__()

    @torch.jit.script_method
    def forward(self, x):
        for i in range(x.size(0)):
            x -= x[i].sum()
        return x

d = Derived()
print(d(torch.rand(3, 4)))
"><pre class="notranslate"><code class="notranslate">import torch

class Base(torch.jit.ScriptModule):
    def __init__(self):
        super().__init__()

    @torch.jit.script_method
    def forward(self, x):
        for i in range(x.size(0)):
            x += x[i].sum()
        return x


class Derived(Base):
    def __init__(self):
        super().__init__()

    @torch.jit.script_method
    def forward(self, x):
        for i in range(x.size(0)):
            x -= x[i].sum()
        return x

d = Derived()
print(d(torch.rand(3, 4)))

</code></pre></div>
<p dir="auto">Fails with:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Traceback (most recent call last):
  File &quot;subclass.py&quot;, line 24, in &lt;module&gt;
    d = Derived()
  File &quot;/Users/jamesreed/onnx-fairseq/pytorch/torch/jit/__init__.py&quot;, line 591, in init_then_register
    self._create_methods(defs, rcbs)
RuntimeError: Method 'forward' already defined (insert at ../torch/csrc/api/include/torch/detail/ordered_dict.h:140)
frame #0: torch::jit::script::Module::create_method(std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;, std::__1::function&lt;void (torch::jit::script::Method&amp;)&gt;) + 428 (0x112cceaec in libtorch.dylib)
frame #1: torch::jit::script::defineMethodsInModule(torch::jit::script::Module&amp;, std::__1::vector&lt;torch::jit::script::Def, std::__1::allocator&lt;torch::jit::script::Def&gt; &gt; const&amp;, std::__1::vector&lt;std::__1::function&lt;std::__1::shared_ptr&lt;torch::jit::script::SugaredValue&gt; (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;, torch::jit::script::Method&amp;, torch::jit::SourceRange const&amp;)&gt;, std::__1::allocator&lt;std::__1::function&lt;std::__1::shared_ptr&lt;torch::jit::script::SugaredValue&gt; (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;, torch::jit::script::Method&amp;, torch::jit::SourceRange const&amp;)&gt; &gt; &gt; const&amp;, std::__1::shared_ptr&lt;torch::jit::script::SugaredValue&gt;) + 947 (0x112ccd9b3 in libtorch.dylib)
frame #2: torch::jit::script::initJitScriptBindings(_object*)::$_3::operator()(std::__1::shared_ptr&lt;torch::jit::script::Module&gt;, std::__1::vector&lt;torch::jit::script::Def, std::__1::allocator&lt;torch::jit::script::Def&gt; &gt; const&amp;, std::__1::vector&lt;std::__1::function&lt;pybind11::function (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;)&gt;, std::__1::allocator&lt;std::__1::function&lt;pybind11::function (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;)&gt; &gt; &gt; const&amp;) const + 1702 (0x110668906 in _C.cpython-36m-darwin.so)
frame #3: void pybind11::detail::argument_loader&lt;std::__1::shared_ptr&lt;torch::jit::script::Module&gt;, std::__1::vector&lt;torch::jit::script::Def, std::__1::allocator&lt;torch::jit::script::Def&gt; &gt; const&amp;, std::__1::vector&lt;std::__1::function&lt;pybind11::function (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;)&gt;, std::__1::allocator&lt;std::__1::function&lt;pybind11::function (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;)&gt; &gt; &gt; const&amp;&gt;::call_impl&lt;void, torch::jit::script::initJitScriptBindings(_object*)::$_3&amp;, 0ul, 1ul, 2ul, pybind11::detail::void_type&gt;(torch::jit::script::initJitScriptBindings(_object*)::$_3&amp;&amp;&amp;, pybind11::detail::index_sequence&lt;0ul, 1ul, 2ul&gt;, pybind11::detail::void_type&amp;&amp;) + 396 (0x11066821c in _C.cpython-36m-darwin.so)
frame #4: std::__1::enable_if&lt;std::is_void&lt;void&gt;::value, pybind11::detail::void_type&gt;::type pybind11::detail::argument_loader&lt;std::__1::shared_ptr&lt;torch::jit::script::Module&gt;, std::__1::vector&lt;torch::jit::script::Def, std::__1::allocator&lt;torch::jit::script::Def&gt; &gt; const&amp;, std::__1::vector&lt;std::__1::function&lt;pybind11::function (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;)&gt;, std::__1::allocator&lt;std::__1::function&lt;pybind11::function (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;)&gt; &gt; &gt; const&amp;&gt;::call&lt;void, pybind11::detail::void_type, torch::jit::script::initJitScriptBindings(_object*)::$_3&amp;&gt;(torch::jit::script::initJitScriptBindings(_object*)::$_3&amp;&amp;&amp;) + 49 (0x110664071 in _C.cpython-36m-darwin.so)
frame #5: void pybind11::cpp_function::initialize&lt;torch::jit::script::initJitScriptBindings(_object*)::$_3, void, std::__1::shared_ptr&lt;torch::jit::script::Module&gt;, std::__1::vector&lt;torch::jit::script::Def, std::__1::allocator&lt;torch::jit::script::Def&gt; &gt; const&amp;, std::__1::vector&lt;std::__1::function&lt;pybind11::function (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;)&gt;, std::__1::allocator&lt;std::__1::function&lt;pybind11::function (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;)&gt; &gt; &gt; const&amp;, pybind11::name, pybind11::is_method, pybind11::sibling&gt;(torch::jit::script::initJitScriptBindings(_object*)::$_3&amp;&amp;, void (*)(std::__1::shared_ptr&lt;torch::jit::script::Module&gt;, std::__1::vector&lt;torch::jit::script::Def, std::__1::allocator&lt;torch::jit::script::Def&gt; &gt; const&amp;, std::__1::vector&lt;std::__1::function&lt;pybind11::function (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;)&gt;, std::__1::allocator&lt;std::__1::function&lt;pybind11::function (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;)&gt; &gt; &gt; const&amp;), pybind11::name const&amp;, pybind11::is_method const&amp;, pybind11::sibling const&amp;)::'lambda'(pybind11::detail::function_call&amp;)::operator()(pybind11::detail::function_call&amp;) const + 251 (0x110663f4b in _C.cpython-36m-darwin.so)
frame #6: void pybind11::cpp_function::initialize&lt;torch::jit::script::initJitScriptBindings(_object*)::$_3, void, std::__1::shared_ptr&lt;torch::jit::script::Module&gt;, std::__1::vector&lt;torch::jit::script::Def, std::__1::allocator&lt;torch::jit::script::Def&gt; &gt; const&amp;, std::__1::vector&lt;std::__1::function&lt;pybind11::function (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;)&gt;, std::__1::allocator&lt;std::__1::function&lt;pybind11::function (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;)&gt; &gt; &gt; const&amp;, pybind11::name, pybind11::is_method, pybind11::sibling&gt;(torch::jit::script::initJitScriptBindings(_object*)::$_3&amp;&amp;, void (*)(std::__1::shared_ptr&lt;torch::jit::script::Module&gt;, std::__1::vector&lt;torch::jit::script::Def, std::__1::allocator&lt;torch::jit::script::Def&gt; &gt; const&amp;, std::__1::vector&lt;std::__1::function&lt;pybind11::function (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;)&gt;, std::__1::allocator&lt;std::__1::function&lt;pybind11::function (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;)&gt; &gt; &gt; const&amp;), pybind11::name const&amp;, pybind11::is_method const&amp;, pybind11::sibling const&amp;)::'lambda'(pybind11::detail::function_call&amp;)::__invoke(pybind11::detail::function_call&amp;) + 24 (0x110663e38 in _C.cpython-36m-darwin.so)
frame #7: pybind11::cpp_function::dispatcher(_object*, _object*, _object*) + 6919 (0x10ff05a57 in _C.cpython-36m-darwin.so)
&lt;omitting python frames&gt;
frame #27: start + 1 (0x7fff5ec53015 in libdyld.dylib)
"><pre class="notranslate"><code class="notranslate">Traceback (most recent call last):
  File "subclass.py", line 24, in &lt;module&gt;
    d = Derived()
  File "/Users/jamesreed/onnx-fairseq/pytorch/torch/jit/__init__.py", line 591, in init_then_register
    self._create_methods(defs, rcbs)
RuntimeError: Method 'forward' already defined (insert at ../torch/csrc/api/include/torch/detail/ordered_dict.h:140)
frame #0: torch::jit::script::Module::create_method(std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;, std::__1::function&lt;void (torch::jit::script::Method&amp;)&gt;) + 428 (0x112cceaec in libtorch.dylib)
frame #1: torch::jit::script::defineMethodsInModule(torch::jit::script::Module&amp;, std::__1::vector&lt;torch::jit::script::Def, std::__1::allocator&lt;torch::jit::script::Def&gt; &gt; const&amp;, std::__1::vector&lt;std::__1::function&lt;std::__1::shared_ptr&lt;torch::jit::script::SugaredValue&gt; (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;, torch::jit::script::Method&amp;, torch::jit::SourceRange const&amp;)&gt;, std::__1::allocator&lt;std::__1::function&lt;std::__1::shared_ptr&lt;torch::jit::script::SugaredValue&gt; (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;, torch::jit::script::Method&amp;, torch::jit::SourceRange const&amp;)&gt; &gt; &gt; const&amp;, std::__1::shared_ptr&lt;torch::jit::script::SugaredValue&gt;) + 947 (0x112ccd9b3 in libtorch.dylib)
frame #2: torch::jit::script::initJitScriptBindings(_object*)::$_3::operator()(std::__1::shared_ptr&lt;torch::jit::script::Module&gt;, std::__1::vector&lt;torch::jit::script::Def, std::__1::allocator&lt;torch::jit::script::Def&gt; &gt; const&amp;, std::__1::vector&lt;std::__1::function&lt;pybind11::function (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;)&gt;, std::__1::allocator&lt;std::__1::function&lt;pybind11::function (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;)&gt; &gt; &gt; const&amp;) const + 1702 (0x110668906 in _C.cpython-36m-darwin.so)
frame #3: void pybind11::detail::argument_loader&lt;std::__1::shared_ptr&lt;torch::jit::script::Module&gt;, std::__1::vector&lt;torch::jit::script::Def, std::__1::allocator&lt;torch::jit::script::Def&gt; &gt; const&amp;, std::__1::vector&lt;std::__1::function&lt;pybind11::function (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;)&gt;, std::__1::allocator&lt;std::__1::function&lt;pybind11::function (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;)&gt; &gt; &gt; const&amp;&gt;::call_impl&lt;void, torch::jit::script::initJitScriptBindings(_object*)::$_3&amp;, 0ul, 1ul, 2ul, pybind11::detail::void_type&gt;(torch::jit::script::initJitScriptBindings(_object*)::$_3&amp;&amp;&amp;, pybind11::detail::index_sequence&lt;0ul, 1ul, 2ul&gt;, pybind11::detail::void_type&amp;&amp;) + 396 (0x11066821c in _C.cpython-36m-darwin.so)
frame #4: std::__1::enable_if&lt;std::is_void&lt;void&gt;::value, pybind11::detail::void_type&gt;::type pybind11::detail::argument_loader&lt;std::__1::shared_ptr&lt;torch::jit::script::Module&gt;, std::__1::vector&lt;torch::jit::script::Def, std::__1::allocator&lt;torch::jit::script::Def&gt; &gt; const&amp;, std::__1::vector&lt;std::__1::function&lt;pybind11::function (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;)&gt;, std::__1::allocator&lt;std::__1::function&lt;pybind11::function (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;)&gt; &gt; &gt; const&amp;&gt;::call&lt;void, pybind11::detail::void_type, torch::jit::script::initJitScriptBindings(_object*)::$_3&amp;&gt;(torch::jit::script::initJitScriptBindings(_object*)::$_3&amp;&amp;&amp;) + 49 (0x110664071 in _C.cpython-36m-darwin.so)
frame #5: void pybind11::cpp_function::initialize&lt;torch::jit::script::initJitScriptBindings(_object*)::$_3, void, std::__1::shared_ptr&lt;torch::jit::script::Module&gt;, std::__1::vector&lt;torch::jit::script::Def, std::__1::allocator&lt;torch::jit::script::Def&gt; &gt; const&amp;, std::__1::vector&lt;std::__1::function&lt;pybind11::function (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;)&gt;, std::__1::allocator&lt;std::__1::function&lt;pybind11::function (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;)&gt; &gt; &gt; const&amp;, pybind11::name, pybind11::is_method, pybind11::sibling&gt;(torch::jit::script::initJitScriptBindings(_object*)::$_3&amp;&amp;, void (*)(std::__1::shared_ptr&lt;torch::jit::script::Module&gt;, std::__1::vector&lt;torch::jit::script::Def, std::__1::allocator&lt;torch::jit::script::Def&gt; &gt; const&amp;, std::__1::vector&lt;std::__1::function&lt;pybind11::function (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;)&gt;, std::__1::allocator&lt;std::__1::function&lt;pybind11::function (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;)&gt; &gt; &gt; const&amp;), pybind11::name const&amp;, pybind11::is_method const&amp;, pybind11::sibling const&amp;)::'lambda'(pybind11::detail::function_call&amp;)::operator()(pybind11::detail::function_call&amp;) const + 251 (0x110663f4b in _C.cpython-36m-darwin.so)
frame #6: void pybind11::cpp_function::initialize&lt;torch::jit::script::initJitScriptBindings(_object*)::$_3, void, std::__1::shared_ptr&lt;torch::jit::script::Module&gt;, std::__1::vector&lt;torch::jit::script::Def, std::__1::allocator&lt;torch::jit::script::Def&gt; &gt; const&amp;, std::__1::vector&lt;std::__1::function&lt;pybind11::function (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;)&gt;, std::__1::allocator&lt;std::__1::function&lt;pybind11::function (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;)&gt; &gt; &gt; const&amp;, pybind11::name, pybind11::is_method, pybind11::sibling&gt;(torch::jit::script::initJitScriptBindings(_object*)::$_3&amp;&amp;, void (*)(std::__1::shared_ptr&lt;torch::jit::script::Module&gt;, std::__1::vector&lt;torch::jit::script::Def, std::__1::allocator&lt;torch::jit::script::Def&gt; &gt; const&amp;, std::__1::vector&lt;std::__1::function&lt;pybind11::function (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;)&gt;, std::__1::allocator&lt;std::__1::function&lt;pybind11::function (std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;)&gt; &gt; &gt; const&amp;), pybind11::name const&amp;, pybind11::is_method const&amp;, pybind11::sibling const&amp;)::'lambda'(pybind11::detail::function_call&amp;)::__invoke(pybind11::detail::function_call&amp;) + 24 (0x110663e38 in _C.cpython-36m-darwin.so)
frame #7: pybind11::cpp_function::dispatcher(_object*, _object*, _object*) + 6919 (0x10ff05a57 in _C.cpython-36m-darwin.so)
&lt;omitting python frames&gt;
frame #27: start + 1 (0x7fff5ec53015 in libdyld.dylib)

</code></pre></div>