Skip to content

Module 'Sequential' has no attribute '_modules' : #98064

@SerBad

Description

@SerBad

🐛 Describe the bug

import torch
import torch.nn as nn
class MyModule(nn.Module):
    def __init__(self):

        super(MyModule, self).__init__()

        self.seq = nn.Sequential(
            nn.Linear(10, 20),
            nn.ReLU(),
            nn.Linear(20, 5)
        )

def forward(self, x):
    return self.seq(x)

my_module = MyModule()
scripted_module = torch.jit.script(my_module)
RuntimeError: 
Module 'Sequential' has no attribute '_modules' :
  File "/home/zhou/.local/lib/python3.10/site-packages/torch/nn/modules/container.py", line 251
    @property
    def modules(self):
        return self._modules
               ~~~~~~~~~~~~~ <--- HERE

Versions

version = '2.0.0+cu117'
debug = False
cuda = '11.7'
git_version = 'c263bd43e8e8502d4726643bc6fd046f0130ac0e'
hip = None

cc @EikanWang @jgong5 @wenzhe-nrv @sanchitintel

Metadata

Metadata

Assignees

No one assigned

    Labels

    oncall: jitAdd this issue/PR to JIT oncall triage queue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions