Skip to content

[JIT] invoking nn.Sequential requires all intermediary results to be the same type #27401

@eellison

Description

@eellison

🐛 Bug

To Reproduce

class A(torch.nn.Module):
    def __init__(self):
        super(A, self).__init__()

    def forward(self, x):
        return x + 3

class B(torch.nn.Module):
    def __init__(self):
        super(B, self).__init__()

    def forward(self, x):
        return {"1": x}

class C(torch.nn.Module):
    __constants__ = ['foo']

    def __init__(self):
        super(C, self).__init__()
        self.foo = torch.nn.Sequential(A(), B())

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

c = C()
print(torch.jit.script(c).graph)

RuntimeError:
Variable 'input' previously has type Tensor but is now being assigned to a value of type Dict[str, Tensor] : at :4:16
def forward(self, input):
for m in self:
input = m(input)
~~~~~ <--- HERE
return input

Expected behavior

Either this should work or be documented as not working.

cc @suo

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