-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[dynamic shapes] unbacked-safe slicing #161414
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
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/161414
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 08cf5ae with merge base 84b57c9 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This pull request was exported from Phabricator. Differential Revision: D80948073 |
3787eed
to
fa9e353
Compare
Summary: Generates new unbacked symbols for slice output size & storage offset, when appropriate semantics are unclear. Teaches inductor to codegen the slice with flexible semantics. Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/56218d85e2da09d9ede3809718ec989c2151632c Rollback Plan: Differential Revision: D80948073
This pull request was exported from Phabricator. Differential Revision: D80948073 |
torch/_inductor/lowering.py
Outdated
|
||
# realize to get strides/storage offset | ||
if x.maybe_get_layout() is None: | ||
x.realize() |
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.
@eellison I'm not very familiar with inductor lowering, so I wasn't sure if this was the right approach; the goal was to call as_strided with codegened sizes/strides/offset, but later figured I had to call realize()
, on inputs like ir.Pointwise
.
maybe this case should be lowering in a different way?
elif guard_or_false(start_index >= end_index): | ||
new_size = 0 | ||
|
||
# create unbacked if case unknown |
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: unknown -> undecided due to unbacked shapes.
def slice_(x, dim=0, start=0, end=2**63, step=1, clamp=True): | ||
""" | ||
Lowers a slice call, creating ExternKernels for the output size & storage offset symbols, | ||
if the indices are unbacked and appropriate semantics aren't known. |
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: semantics are the same for known and unknown.
maybe:
creating ExternKernels to compute the output size & storage offset symbols dynamically if they cant be determined at compile time because indices are unbacked.
): | ||
return x | ||
except TypeError: | ||
pass |
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.
why would a type error be thrown? statically_known_leq should be resilient to unbacked.
sym_storage = sym | ||
|
||
if V.graph.current_node is None or not clamp or (sym_size is None and sym_storage is None): | ||
return TensorBox( |
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 path is taken if no unbacked symbols has been allocated meaning that we know how to determine things statically and no need for dynamic computations.
except TypeError: | ||
pass | ||
|
||
# try to avoid dynamic (unbacked) slice |
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 does not seem the appropriate line for this comment?
pass | ||
|
||
# try to avoid dynamic (unbacked) slice | ||
def compute_slice_index(index, size, default=None): |
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 is only called once with default being 0?
sounds like we never call it with index None in this version?
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.
approved but please address my comments before landing
Summary: Generates new unbacked symbols for slice output size & storage offset, when appropriate semantics are unclear. Teaches inductor to codegen the slice with flexible semantics. Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/56218d85e2da09d9ede3809718ec989c2151632c Rollback Plan: Reviewed By: laithsakka Differential Revision: D80948073
b79015a
to
6267444
Compare
6267444
to
4830a22
Compare
Summary: Generates new unbacked symbols for slice output size & storage offset, when appropriate semantics are unclear. Teaches inductor to codegen the slice with flexible semantics. Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/56218d85e2da09d9ede3809718ec989c2151632c Rollback Plan: Reviewed By: laithsakka Differential Revision: D80948073
Summary: Generates new unbacked symbols for slice output size & storage offset, when appropriate semantics are unclear. Teaches inductor to codegen the slice with flexible semantics. Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/56218d85e2da09d9ede3809718ec989c2151632c Reviewed By: laithsakka Differential Revision: D80948073
4830a22
to
12b4954
Compare
Summary: Generates new unbacked symbols for slice output size & storage offset, when appropriate semantics are unclear. Teaches inductor to codegen the slice with flexible semantics. Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/56218d85e2da09d9ede3809718ec989c2151632c Reviewed By: laithsakka Differential Revision: D80948073
12b4954
to
08cf5ae
Compare
@pytorchbot merge (Initiating merge automatically since Phabricator Diff has merged) |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Summary:
Generates new unbacked symbols for slice output size & storage offset, when appropriate semantics are unclear. Teaches inductor to codegen the slice with flexible semantics.
Test Plan:
contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/56218d85e2da09d9ede3809718ec989c2151632c
Rollback Plan:
Differential Revision: D80948073
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @chenyang78 @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben