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

Record shaping assertions and use them for tracing / scripting optimization and codegen #46948

Open
vadimkantorov opened this issue Oct 27, 2020 · 5 comments
Labels
module: codegen Issues related to the codegen for Aten and Autograd oncall: jit Add this issue/PR to JIT oncall triage queue
Projects

Comments

@vadimkantorov
Copy link
Contributor

vadimkantorov commented Oct 27, 2020

Motivated in #40373 (comment).

Recording assertions assert X.shape[1] == Y.shape[2] and X.shape[2] == 64 and Z.ndim == 3 (or directly via torch.assert_shapes(...)) as part of tracing / scripting can help and streamline codegen (as can eliminate unneeded checks or broadcasts). #40373 contains a wider discussion, but @ezyang suggested that a more limited scope can be of value as well.

cc @gmagogsfm @apaszke

@mrshenli mrshenli added module: codegen Issues related to the codegen for Aten and Autograd oncall: jit Add this issue/PR to JIT oncall triage queue labels Oct 28, 2020
@github-actions github-actions bot added this to Need triage in JIT Triage Oct 28, 2020
@vadimkantorov
Copy link
Contributor Author

If these are recorded, it may be useful to let user access these (shape inference) "type hints".
One way this could be done is by: assert torch.record_shapes(lambda X, Y, Z: X.shape[1] == Y.shape[2] and X.shape[2] == 64 and Z.ndim == 3, X, Y, Z) and then accesssing by hints = torch.get_recorded_shape_hints(X, Y, Z)

@vadimkantorov
Copy link
Contributor Author

vadimkantorov commented Jun 15, 2023

Btw with dynamo, this idea of explicit user-provided hints/guarantees may be still relevant @ezyang @albanD (including for asserting numel less than int32 max)

Some other useful constraints can include divisibility: e.g. assert tensor.shape[-1] % 64 == 0 which could simplify the emitted code

If these are in form of assert statement, they can be nicely executed in eager mode as well and blow up nicely if something is wrong

@vadimkantorov
Copy link
Contributor Author

Related: #107735

@eellison eellison removed their assignment Aug 23, 2023
@vadimkantorov
Copy link
Contributor Author

Related idea on manual decaying shapes to static to help/simplify the export:

@vadimkantorov
Copy link
Contributor Author

Somewhat related question on Dynamo preserving the shape/dtype assert statements in Dynamo-captured graphs: https://stackoverflow.com/questions/78426965/how-do-i-get-dynamo-export-to-not-export-shape-asserts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: codegen Issues related to the codegen for Aten and Autograd oncall: jit Add this issue/PR to JIT oncall triage queue
Projects
JIT Triage
  
In discussion
Development

No branches or pull requests

3 participants