-
Notifications
You must be signed in to change notification settings - Fork 26.3k
bind OrderedDict() and Dict constructor #26170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
[ghstack-poisoned]
ghstack-source-id: 442e055 Pull Request resolved: pytorch#26170
| case TypeKind::FloatType: | ||
| case TypeKind::StringType: | ||
| case TypeKind::TensorType: | ||
| case TypeKind::VarType: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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));
}
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)", |
There was a problem hiding this comment.
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
|
Replaced by #26373 b/c ghstack was poisioned and i had to resubmit |
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
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
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::dictconstructor since then the types would be more explicit.