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
[jit] Fix value association with dictionaries in the tracer #40885
Conversation
`TracingState::setValue` associates a concrete IValue in the traced program with a `Value*` symbolic. Previously, the logic for how GenericDicts worked was special cased to only work for very simple cases and silently eat other cases. This PR generalizes the logic to reflect the same behavior as using dictionaries on input: whenever we encounter a dictionary in the system, we completely "burn in" all the keys into the graph, and then recursively call `setValue` on the associated value. This has the effect of requiring that any dictionary structure you are creating in a traced program be of fixed structure, similar to how any dictionary used as input must be static as well. [ghstack-poisoned]
💊 CI failures summary and remediationsAs of commit 4aba185 (more details on the Dr. CI page): 💚 💚 Looks good so far! There are no failures yet. 💚 💚 This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group. This comment has been revised 3 times. |
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.
looks good!
} | ||
if (value_type->cast<TensorType>()) { | ||
handle_unpack(aten::values); | ||
for (const auto& entry : dict) { |
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 will actually implies that if dict[tensor, tensor] (tensor as keys) as input or cross tracing/scripting, the tensor key will always be treated as constant, which is ok, but I am wondering if we should throw some warning here to user?
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.
Agreed, I filed #40886 as a followup to improve the error messaging in all cases where a key mismatch occurs
auto static_key = graph->insertConstant(entry.key()); | ||
auto static_value = | ||
graph->insert(aten::__getitem__, {value, static_key}); | ||
setValue(entry.value(), static_value); | ||
} | ||
} else { | ||
std::ostringstream os; |
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.
error message seems out dated
`TracingState::setValue` associates a concrete IValue in the traced program with a `Value*` symbolic. Previously, the logic for how GenericDicts worked was special cased to only work for very simple cases and silently eat other cases. This PR generalizes the logic to reflect the same behavior as using dictionaries on input: whenever we encounter a dictionary in the system, we completely "burn in" all the keys into the graph, and then recursively call `setValue` on the associated value. This has the effect of requiring that any dictionary structure you are creating in a traced program be of fixed structure, similar to how any dictionary used as input must be static as well. Differential Revision: [D22342490](https://our.internmc.facebook.com/intern/diff/D22342490) [ghstack-poisoned]
`TracingState::setValue` associates a concrete IValue in the traced program with a `Value*` symbolic. Previously, the logic for how GenericDicts worked was special cased to only work for very simple cases and silently eat other cases. This PR generalizes the logic to reflect the same behavior as using dictionaries on input: whenever we encounter a dictionary in the system, we completely "burn in" all the keys into the graph, and then recursively call `setValue` on the associated value. This has the effect of requiring that any dictionary structure you are creating in a traced program be of fixed structure, similar to how any dictionary used as input must be static as well. ghstack-source-id: 248b4232ec03c7d3d21e1a45b59a112bfc2edeee Pull Request resolved: #40885
Stack from ghstack:
TracingState::setValue
associates a concrete IValue in the tracedprogram with a
Value*
symbolic. Previously, the logic for howGenericDicts worked was special cased to only work for very simple cases
and silently eat other cases.
This PR generalizes the logic to reflect the same behavior as using
dictionaries on input: whenever we encounter a dictionary in the system,
we completely "burn in" all the keys into the graph, and then
recursively call
setValue
on the associated value.This has the effect of requiring that any dictionary structure you are
creating in a traced program be of fixed structure, similar to how any
dictionary used as input must be static as well.
Differential Revision: D22342490