Skip to content

[JIT] Named Tuple annotation doesn't work with annotations.py #26437

@eellison

Description

@eellison

🐛 Bug

If annotation is accessed through annotations.py, then an exception is raised. annotations.py pathway is used in a lot of script code and should work with named tuples.

To Reproduce

_GoogLeNetOutputs = namedtuple('GoogLeNetOutputs', ['logits', 'aux_logits2', 'aux_logits1'])
def fn(x):
    # type: (Tensor) -> _GoogLeNetOutputs
    return _GoogleNetOutputs(x, x, x)

print(torch.jit.annotations.get_signature(fn))

Traceback (most recent call last):
File "test/test_jit.py", line 14745, in test_named_tuple_py2
print(torch.jit.annotations.get_signature(fn))
File "/home/eellison/local/miniconda/envs/ninja/lib/python3.7/site-packages/torch/jit/annotations.py", line 59, in get_signature
return parse_type_line(type_line)
File "/home/eellison/local/miniconda/envs/ninja/lib/python3.7/site-packages/torch/jit/annotations.py", line 109, in parse_type_line
raise RuntimeError("Failed to parse the return type of a type annotation: {}".format(str(e)))
RuntimeError: Failed to parse the return type of a type annotation: name '_GoogLeNetOutputs' is not defined

cc @suo

Metadata

Metadata

Assignees

No one assigned

    Labels

    oncall: jitAdd this issue/PR to JIT oncall triage queuetriagedThis 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