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

Generalize constant_table from tensor only to ivalue #37631

Closed
wants to merge 1 commit into from

Conversation

bzinodev
Copy link
Contributor

Currently JIT serialization allows only tensor in the constant table (CONSTANTS section). All other constants are inlined. In some cases these constant can be long and contains non ASCII strings, currently not serialized.

@bzinodev bzinodev requested a review from apaszke as a code owner April 30, 2020 23:31
@bzinodev bzinodev requested a review from jamesr66a April 30, 2020 23:32
@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Apr 30, 2020
@dr-ci
Copy link

dr-ci bot commented Apr 30, 2020

💊 CI failures summary and remediations

As of commit 8d3208b (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 61 times.

Copy link
Member

@suo suo left a comment

Choose a reason for hiding this comment

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

Nice! This is a great generalization and looks like it wasn't too hairy of a change. Left some comments inline.

Also: how does this interact with the mobile import? I remember you mentioned there were some issues but I don't see related changes in this

torch/csrc/jit/serialization/python_print.cpp Outdated Show resolved Hide resolved
torch/csrc/jit/serialization/python_print.cpp Show resolved Hide resolved
torch/csrc/jit/serialization/python_print.cpp Outdated Show resolved Hide resolved
torch/csrc/jit/serialization/python_print.cpp Outdated Show resolved Hide resolved
test/jit/test_freezing.py Show resolved Hide resolved
@bzinodev bzinodev force-pushed the constant_table branch 2 times, most recently from 61042dd to 29540c3 Compare May 18, 2020 19:02
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@bzinodev has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@bzinodev bzinodev force-pushed the constant_table branch 2 times, most recently from cff65dd to 7839272 Compare May 20, 2020 02:20
@bzinodev bzinodev force-pushed the constant_table branch 3 times, most recently from 8239218 to a02c73a Compare May 29, 2020 20:02
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@bzinodev has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@bzinodev has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@bzinodev has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@bzinodev has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Member

@suo suo left a comment

Choose a reason for hiding this comment

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

lgtm

// Apply visitor to every subvalue.
// TODO: There are several places that recurse over IValue. This is fragile.
// This visitor should be used to recurse over ivalues.
void visit(const std::function<bool (const IValue &)>& visitor) const;
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a short comment explaining how the return bool is used?

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@bzinodev has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@zdevito zdevito left a comment

Choose a reason for hiding this comment

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

See comments. I think there are some issues here.

@@ -101,6 +101,46 @@ TypePtr IValue::type() const {
TORCH_INTERNAL_ASSERT(false, "unhandled case in IValue::type()");
}

void IValue::visit(const std::function<bool (const IValue &)>& visitor) const {
Copy link
Contributor

Choose a reason for hiding this comment

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

I recommend against adding this to IValue: it does not contain tests, and is not even turned on in this PR. It is the kind of simple function that people looking at ivalue will think it tested and implemented correctly. This should be implemented locally where needed unless we commit to completely implementing it and testing it.

void printConstant(TaggedStringStream& stmt, const IValue& v) {
const auto customFormatter = [&](std::ostream& ss, const IValue& v) {
if (v.isTensor()) {
ss << "CONSTANTS.c" << getOrAddTensorConstant(v.toTensor());
if (v.isTensor() || containsNonASCIIString(v)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this isn't the right condition: we should be able to correctly print non-ascii strings with the appropriate escapes. In fact, I think we actually do. I think what is going on here is that some aggregate constant is getting printed through a call to its pretty printer, and the bug lies in the fact that the pretty printer for that aggregate doesn't recursively invoke our our repr code for strings. I feel like this bug should be fixed there, this feels like a workaround.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO, only small string should be allowed to be inlined. All large constant (lists,dicts, strings) should be in the constant table. I followed this logic and time is spent parsing string literals. I would not spend time adding logic to parse unicode strings.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@bzinodev has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Currently only constant except tensor must be inlined during serialization.
Tensor are stored in the contant table. This patch generalizes this capability
to any IValue. This is particularly useful for non ASCII string literal that
cannot be inlined.
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@bzinodev has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@bzinodev has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@bzinodev bzinodev closed this Oct 13, 2020
@facebook-github-bot facebook-github-bot deleted the constant_table branch January 27, 2021 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
oncall: jit Add this issue/PR to JIT oncall triage queue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants