Skip to content

Conversation

@abadams
Copy link
Member

@abadams abadams commented Apr 17, 2024

It was O(n) for n facts. This makes it O(log(n))

This was particularly bad for pipelines with lots of inputs or outputs,
because those pipelines have lots of asserts, which make for lots of
facts to substitute in.

Speeds up lowering of local laplacian with 20 pyramid levels (which has
only one input and one output) by 1.09x

Speeds up lowering of the adams 2019 cost model training pipeline (lots
of weight inputs and lots outputs due to derivatives) by 1.5x

Speeds up resnet50 (tons of weight inputs) lowering by 7.3x!

abadams added 10 commits April 16, 2024 17:06
Deletes a bunch of code and speeds up lowering time of local laplacian
with 20 pyramid levels by ~2.5%
It was O(n) for n facts. This makes it O(log(n))

This was particularly bad for pipelines with lots of inputs or outputs,
because those pipelines have lots of asserts, which make for lots of
facts to substitute in.

Speeds up lowering of local laplacian with 20 pyramid levels (which has
only one input and one output) by 1.09x

Speeds up lowering of the adams 2019 cost model training pipeline (lots
of weight inputs and lots outputs due to derivatives) by 1.5x

Speeds up resnet50 (tons of weight inputs) lowering by 7.3x!
@abadams
Copy link
Member Author

abadams commented Apr 18, 2024

Ready for review

std::vector<const Variable *> pop_list;
std::vector<const Variable *> bounds_pop_list;
std::vector<Expr> truths, falsehoods;
std::set<Expr, IRDeepCompare> truths, falsehoods;
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you considered unordered_set?

Copy link
Member Author

Choose a reason for hiding this comment

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

comparing Exprs for < is actually a lot cheaper than hashing them, because you can early out as soon as you find an IRNodeType that differs instead of having to descend to the bottom.

Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth putting that in a comment then :-)

Copy link
Member Author

Choose a reason for hiding this comment

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

Meh, that was a bit of a guess. Nowhere in the compiler do we use unordered sets or maps with Expr keys, because we don't have a hash function. I'm just doing what we do everywhere else.

@abadams
Copy link
Member Author

abadams commented Apr 19, 2024

Failure unrelated (seems to be a performance flake). Ready for review.

@abadams
Copy link
Member Author

abadams commented Apr 19, 2024

Oh oops, you already approved it.

@abadams abadams merged commit 31c52ab into main Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants