Skip to content

Conversation

@eellison
Copy link
Contributor

@eellison eellison commented Sep 13, 2019

Stack from ghstack:

Binds the OrderedDict() and dict() constructor into torchscript. For the case of the empty constructor dict() i typed it as [str, Tensor] because:
• we're almost dropping support for python 2, at which point all dicts are ordered
• then it's more conventional to write x : Dict[int, int] = {} which is already supported
• It is possible to construct an arbitrarily typed empty OrderedDict through
OrderedDict(torch.jit.annotate(List[Tuple[key, value]], [])

We could consider dropping the no inputs aten::dict constructor since then the types would be more explicit.

@eellison eellison requested a review from apaszke as a code owner September 13, 2019 15:59
@pytorchbot pytorchbot added oncall: jit Add this issue/PR to JIT oncall triage queue module: internals Related to internal abstractions in c10 and ATen labels Sep 13, 2019
eellison pushed a commit to eellison/pytorch that referenced this pull request Sep 13, 2019
ghstack-source-id: 442e055
Pull Request resolved: pytorch#26170
@eellison eellison requested review from driazati and suo September 13, 2019 16:03
case TypeKind::FloatType:
case TypeKind::StringType:
case TypeKind::TensorType:
case TypeKind::VarType:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can a VarType that is not one of the specified key types work as a dict key?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise it fails in schema parsing, since the dict is first instantiated with vartype

TypePtr value_type = static_cast<const DictType*>(output_type.get())->getValueType();
return [=](Stack& stack) {
auto vals = c10::impl::GenericDict(key_type, value_type);
vals.reserve(stack.size() / 2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is stack's size related to the size of vals

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

             for (size_t i = 0; i < num_inputs; i += 2) {
               auto val = pop(stack);
               auto key = pop(stack);
               vals.insert_or_assign(std::move(key), std::move(val));
             }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be num_inputs * 2 then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no because each iteration the dict size increases by one

},
aliasAnalysisSpecialCase()),
Operator(
"aten::dict((tKey, tVal)[] inputs) -> Dict(tKey, tVal)",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should just enumerate the supported keys instead of using vartype

@eellison
Copy link
Contributor Author

Replaced by #26373 b/c ghstack was poisioned and i had to resubmit

@eellison eellison closed this Sep 17, 2019
facebook-github-bot pushed a commit that referenced this pull request Sep 19, 2019
Summary:
Makes c10::Dict Ordered and bins binds the OrderedDict() and dict() constructor into torchscript. For the case of the empty constructor dict() i typed it as [str, Tensor] because:
• we're almost dropping support for python 2, at which point all dicts are ordered
• then it's more conventional to write x : Dict[int, int] = {} which is already supported
• It is possible to construct an arbitrarily typed empty OrderedDict through
OrderedDict(torch.jit.annotate(List[Tuple[key, value]], [])

We could consider dropping the no inputs aten::dict constructor since then the types would be more explicit.

This replaces #26170 and #26372 b/c ghstack was poisioned and i had to resubmit
Pull Request resolved: #26465

Differential Revision: D17481604

Pulled By: eellison

fbshipit-source-id: d2d49795a518c3489881afac45d070e5262c5849
zdevito pushed a commit to zdevito/ATen that referenced this pull request Sep 19, 2019
Summary:
Makes c10::Dict Ordered and bins binds the OrderedDict() and dict() constructor into torchscript. For the case of the empty constructor dict() i typed it as [str, Tensor] because:
• we're almost dropping support for python 2, at which point all dicts are ordered
• then it's more conventional to write x : Dict[int, int] = {} which is already supported
• It is possible to construct an arbitrarily typed empty OrderedDict through
OrderedDict(torch.jit.annotate(List[Tuple[key, value]], [])

We could consider dropping the no inputs aten::dict constructor since then the types would be more explicit.

This replaces pytorch/pytorch#26170 and pytorch/pytorch#26372 b/c ghstack was poisioned and i had to resubmit
Pull Request resolved: pytorch/pytorch#26465

Differential Revision: D17481604

Pulled By: eellison

fbshipit-source-id: d2d49795a518c3489881afac45d070e5262c5849
@facebook-github-bot facebook-github-bot deleted the gh/eellison/18/head branch October 28, 2019 22:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: internals Related to internal abstractions in c10 and ATen oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants