-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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] greedy by size memory planning strategy #64349
Conversation
Greedy by size (a heuristic that allocates largest tensors first) based on [this paper]( https://arxiv.org/pdf/2001.03288.pdf). It's factored the way it is for the purposes of making subsequent strategies simpler to implement. make greedy deterministic [ghstack-poisoned]
🔗 Helpful links
💊 CI failures summary and remediationsAs of commit fd9cd4a (more details on the Dr. CI page):
🕵️ 4 new failures recognized by patternsThe following CI failures do not appear to be due to upstream breakages: pytorch_linux_xenial_py3_6_gcc5_4_test (1/4)Step: "Test" (full log | diagnosis details | 🔁 rerun)
|
Job | Step | Action |
---|---|---|
Lint / clang-format | Run clang-format | 🔁 rerun |
This comment was automatically generated by Dr. CI (expand for details).
Please report bugs/suggestions to the (internal) Dr. CI Users group.
Greedy by size (a heuristic that allocates largest tensors first) based on [this paper]( https://arxiv.org/pdf/2001.03288.pdf). It's factored the way it is for the purposes of making subsequent strategies simpler to implement. make greedy deterministic [ghstack-poisoned]
Greedy by size (a heuristic that allocates largest tensors first) based on [this paper]( https://arxiv.org/pdf/2001.03288.pdf). It's factored the way it is for the purposes of making subsequent strategies simpler to implement. make greedy deterministic [ghstack-poisoned]
Greedy by size (a heuristic that allocates largest tensors first) based on [this paper]( https://arxiv.org/pdf/2001.03288.pdf). It's factored the way it is for the purposes of making subsequent strategies simpler to implement. make greedy deterministic [ghstack-poisoned]
Greedy by size (a heuristic that allocates largest tensors first) based on [this paper]( https://arxiv.org/pdf/2001.03288.pdf). It's factored the way it is for the purposes of making subsequent strategies simpler to implement. make greedy deterministic [ghstack-poisoned]
Greedy by size (a heuristic that allocates largest tensors first) based on [this paper]( https://arxiv.org/pdf/2001.03288.pdf). It's factored the way it is for the purposes of making subsequent strategies simpler to implement. make greedy deterministic [ghstack-poisoned]
Greedy by size (a heuristic that allocates largest tensors first) based on [this paper]( https://arxiv.org/pdf/2001.03288.pdf). It's factored the way it is for the purposes of making subsequent strategies simpler to implement. make greedy deterministic [ghstack-poisoned]
Greedy by size (a heuristic that allocates largest tensors first) based on [this paper]( https://arxiv.org/pdf/2001.03288.pdf). It's factored the way it is for the purposes of making subsequent strategies simpler to implement. make greedy deterministic [ghstack-poisoned]
Greedy by size (a heuristic that allocates largest tensors first) based on [this paper]( https://arxiv.org/pdf/2001.03288.pdf). It's factored the way it is for the purposes of making subsequent strategies simpler to implement. make greedy deterministic [ghstack-poisoned]
@makslevental has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
Greedy by size (a heuristic that allocates largest tensors first) based on [this paper]( https://arxiv.org/pdf/2001.03288.pdf). It's factored the way it is for the purposes of making subsequent strategies simpler to implement. make greedy deterministic Differential Revision: [D30769096](https://our.internmc.facebook.com/intern/diff/D30769096) [ghstack-poisoned]
Greedy by size (a heuristic that allocates largest tensors first) based on [this paper]( https://arxiv.org/pdf/2001.03288.pdf). It's factored the way it is for the purposes of making subsequent strategies simpler to implement. make greedy deterministic Differential Revision: [D30769096](https://our.internmc.facebook.com/intern/diff/D30769096) [ghstack-poisoned]
Greedy by size (a heuristic that allocates largest tensors first) based on [this paper]( https://arxiv.org/pdf/2001.03288.pdf). It's factored the way it is for the purposes of making subsequent strategies simpler to implement. make greedy deterministic Differential Revision: [D30769096](https://our.internmc.facebook.com/intern/diff/D30769096) [ghstack-poisoned]
Greedy by size (a heuristic that allocates largest tensors first) based on [this paper]( https://arxiv.org/pdf/2001.03288.pdf). It's factored the way it is for the purposes of making subsequent strategies simpler to implement. make greedy deterministic Differential Revision: [D30769096](https://our.internmc.facebook.com/intern/diff/D30769096) [ghstack-poisoned]
Greedy by size (a heuristic that allocates largest tensors first) based on [this paper]( https://arxiv.org/pdf/2001.03288.pdf). It's factored the way it is for the purposes of making subsequent strategies simpler to implement. make greedy deterministic Differential Revision: [D30769096](https://our.internmc.facebook.com/intern/diff/D30769096) [ghstack-poisoned]
Greedy by size (a heuristic that allocates largest tensors first) based on [this paper]( https://arxiv.org/pdf/2001.03288.pdf). It's factored the way it is for the purposes of making subsequent strategies simpler to implement. make greedy deterministic Differential Revision: [D30769096](https://our.internmc.facebook.com/intern/diff/D30769096) [ghstack-poisoned]
Greedy by size (a heuristic that allocates largest tensors first) based on [this paper]( https://arxiv.org/pdf/2001.03288.pdf). It's factored the way it is for the purposes of making subsequent strategies simpler to implement. make greedy deterministic Differential Revision: [D30769096](https://our.internmc.facebook.com/intern/diff/D30769096) [ghstack-poisoned]
Greedy by size (a heuristic that allocates largest tensors first) based on [this paper]( https://arxiv.org/pdf/2001.03288.pdf). It's factored the way it is for the purposes of making subsequent strategies simpler to implement. make greedy deterministic Differential Revision: [D30769096](https://our.internmc.facebook.com/intern/diff/D30769096) [ghstack-poisoned]
Greedy by size (a heuristic that allocates largest tensors first) based on [this paper]( https://arxiv.org/pdf/2001.03288.pdf). It's factored the way it is for the purposes of making subsequent strategies simpler to implement. make greedy deterministic Differential Revision: [D30769096](https://our.internmc.facebook.com/intern/diff/D30769096) [ghstack-poisoned]
Greedy by size (a heuristic that allocates largest tensors first) based on [this paper]( https://arxiv.org/pdf/2001.03288.pdf). It's factored the way it is for the purposes of making subsequent strategies simpler to implement. make greedy deterministic Differential Revision: [D30769096](https://our.internmc.facebook.com/intern/diff/D30769096) [ghstack-poisoned]
Greedy by size (a heuristic that allocates largest tensors first) based on [this paper]( https://arxiv.org/pdf/2001.03288.pdf). It's factored the way it is for the purposes of making subsequent strategies simpler to implement. make greedy deterministic Differential Revision: [D30769096](https://our.internmc.facebook.com/intern/diff/D30769096) [ghstack-poisoned]
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.
a few qs. I seem to be struggling to fully understand this PR.
makeAllocation(ulvr, size, ordered_allocations, findOffsetWithSmallestGap); | ||
} | ||
|
||
auto cmp = liveRangeStartCmp(); |
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.
to double check, cmp
returns a boolean and not -1, 0, 1
?
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.
@Krovatkin that's correct
[&cmp](auto m1, auto m2) { return cmp(m1.ulvr, m2.ulvr); }); | ||
return ordered_allocations; | ||
} | ||
|
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.
we seem to be missing greedyBySizeWithSmallestGap
or is it somehow covered the other two?
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.
@Krovatkin hmm not sure what version you were looking at but it's in this commit
[&cmp](auto& p1, auto& p2) { | ||
auto len1 = p1.first.lvr.end - p1.first.lvr.begin; | ||
auto len2 = p2.first.lvr.end - p2.first.lvr.begin; | ||
return len1 == len2 ? (p1.second == p2.second ? cmp(p1.first, p2.first) |
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.
I'd suggest to assign .second
, .first
into temps with descriptive names, otherwise it's a bit hard to reason about what those are. Looks like .second
is size?
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.
cmp(p1.first, p2.first) would this also be in an non-increasing order or it doesn't matter?
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.
@Krovatkin *.first
are the "unique" live ranges. we're sorting here by length and then breaking ties by size and start. it's convoluted i admit but it happens and it's very frustrating dealing with non-deterministic orderings when debugging.
std::sort( | ||
sorted_length_then_size_live_ranges.begin(), | ||
sorted_length_then_size_live_ranges.end(), | ||
[&cmp](auto& p1, auto& p2) { |
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.
nit: maybe we could encapsulate this into its own comparator.
a) you won't have to pass &cmp
b) a reader won't have to read the same code twice if they don't realize the sorting order is the same.
} | ||
|
||
// don't simplify this to gap = a - b because you'll get buffer overflow... | ||
if (alloc.reg.offset >= prev_offset) { |
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.
when would this case happen you seem to be inserting in the order of increasing offsets in makeAllocation
?
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.
@Krovatkin good catch - it's true this doesn't make sense in this function (findFirstOffset
) but it has since been refactored and makes more sense in context
size_t prev_offset = 0; | ||
|
||
for (const auto& alloc : ordered_allocations) { | ||
if (!overlapLiveRange(alloc.ulvr, unalloced_ulvr)) { |
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.
I'm a bit confused here. It looks like we are skipping live ranges that don't overlap with the unallocated live range?
I was thinking we should be specifically looking for the ranges that do not overlap otherwise we can't reuse that storage?
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.
@Krovatkin this is looking for live ranges that overlap in time and then finding the smallest gap between these "live" live ranges. this should really be done using something like an interval tree (and an overlap lookup). I'm looking into this but one issue is interval trees don't deal well with duplicated endpoints. In the single-threaded case that's not an issue but in the concurrency case it might pop up.
Greedy by size (a heuristic that allocates largest tensors first) based on [this paper]( https://arxiv.org/pdf/2001.03288.pdf). It's factored the way it is for the purposes of making subsequent strategies simpler to implement. make greedy deterministic Differential Revision: [D30769096](https://our.internmc.facebook.com/intern/diff/D30769096) [ghstack-poisoned]
CI Flow Status⚛️ CI FlowRuleset - Version:
You can add a comment to the PR and tag @pytorchbot with the following commands: # ciflow rerun, "ciflow/default" will always be added automatically
@pytorchbot ciflow rerun
# ciflow rerun with additional labels "-l <ciflow/label_name>", which is equivalent to adding these labels manually and trigger the rerun
@pytorchbot ciflow rerun -l ciflow/scheduled -l ciflow/slow For more information, please take a look at the CI Flow Wiki. |
@makslevental has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
Hi @makslevental! Thank you for your pull request. We require contributors to sign our Contributor License Agreement, and yours needs attention. You currently have a record in our system, but the CLA is no longer valid, and will need to be resubmitted. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as |
Stack from ghstack:
Greedy by size (a heuristic that allocates largest tensors first) based on this paper. It's factored the way it is for the purposes of making subsequent strategies simpler to implement.
make greedy deterministic
Differential Revision: D30769096