Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

suo
Copy link
Member

@suo suo commented Jul 1, 2020

Stack from ghstack:

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

`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]
@suo suo requested a review from apaszke as a code owner July 1, 2020 21:28
@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Jul 1, 2020
@suo suo linked an issue Jul 1, 2020 that may be closed by this pull request
@suo suo requested review from wanchaol and jamesr66a July 1, 2020 21:38
@dr-ci
Copy link

dr-ci bot commented Jul 1, 2020

💊 CI failures summary and remediations

As 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.

See how this bot performed.

This comment has been revised 3 times.

Copy link
Contributor

@wanchaol wanchaol left a 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) {
Copy link
Contributor

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?

Copy link
Member Author

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;
Copy link
Contributor

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]
suo added a commit that referenced this pull request Jul 1, 2020
`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
@facebook-github-bot
Copy link
Contributor

@suo merged this pull request in 9fa1f27.

@facebook-github-bot facebook-github-bot deleted the gh/suo/337/head branch July 5, 2020 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Merged oncall: jit Add this issue/PR to JIT oncall triage queue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent behavior when tracing dictionaries
4 participants