Skip to content

super().__init__() not called in torch.nn.Module.__init__ #28746

@woxuankai

Description

@woxuankai

🐛 Bug

torch.nn.Module.__init__ doesn't call the super().__init__() , which will case troubles in multiple inheritance.

To Reproduce

For example,

import torch

class MyBase(object):
    def __init__(self):
        super().__init__()
        print('Base initialized!')

class A(torch.nn.Module, MyBase):
    def __init__(self):
        super().__init__()
        print('A initialized!')

class B(torch.nn.Module, MyBase):
    def __init__(self):
        super().__init__()
        print('B initialized!')

class C(A, B):
    def __init__(self):
        super().__init__()
        print('C initialized!')

c = C()

will only print

B initialized!
A initialized!
C initialized!

while MyBase.__init__ is NOT called.

Expected behavior

print

Base initialized!
B initialized!
A initialized!
C initialized!

Environment

PyTorch 1.3.0

Additional context

Deep Thoughts by Raymond Hettinger
super()

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: nnRelated to torch.nntriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions