Skip to content

[JIT] Default method arguments for container types is broken #21545

@jamesr66a

Description

@jamesr66a
import torch
from typing import List

class Foo(torch.jit.ScriptModule):
    @torch.jit.script_method
    def forward(self, languages: List[str]=[], per_token_languages: List[List[str]]=[]):
        return torch.rand(3, 4)

f = Foo()
f.save('/tmp/test.zip')

torch.jit.load('/tmp/test.zip')
Traceback (most recent call last):
  File "repro_load_fail2.py", line 12, in <module>
    torch.jit.load('/tmp/test.zip')
  File "/Users/jamesreed/pytorch/torch/jit/__init__.py", line 147, in load
    torch._C.import_ir_module(module_lookup, f, map_location, _extra_files)
RuntimeError:
Return value was annotated as having type Tuple[List[str], List[List[str]]] but is actually of type Tuple[List[Tensor], List[Tensor]]:
at code/test.py:2:12
op_version_set = 1
def forward(self,
           ~~~~~~...  <--- HERE
    languages: List[str]=[],
    per_token_languages: List[List[str]]=[]) -> Tensor:
  _0 = torch.rand([3, 4], dtype=None, layout=None, device=None, pin_memory=None)
  return _0

cc @suo

Metadata

Metadata

Assignees

No one assigned

    Labels

    jit-backlogoncall: 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