Don’t know is it a bug or just partial coverage but the _fields attribute of NamedTuple unavailable while scripting.
class _Contents(NamedTuple):
a : Optional[torch.Tensor]
b : Optional[torch.Tensor]
c : Optional[torch.Tensor]
d : Optional[torch.Tensor]
@torch.jit.script
class Container:
def __init__(self, fields):
# type: (Tuple[int, int], _Contents)
self.fields = fields
def has(self, name: str) -> bool:
"""
Returns:
bool: whether the field called `name` exists.
"""
return name in self.fields._fields
RuntimeError:
Unknown attribute to named tuple:
at container.py:91:23
def has(self, name: str) -> bool:
"""
Returns:
bool: whether the field called `name` exists.
"""
return name in self.fields._fields
~~~~~~~~~~~~~~~~~~~~ <--- HERE