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

Handling the shape for loop condition #1230

Open
gramalingam opened this issue Dec 18, 2023 · 0 comments
Open

Handling the shape for loop condition #1230

gramalingam opened this issue Dec 18, 2023 · 0 comments

Comments

@gramalingam
Copy link
Collaborator

When mapping python loops to ONNX Loop, we need some strategy for typing (the shape, really) the loop-condition variable.

  • One option is that all code uses a scalar (0D tensor) for the loop-condition, and this works fine.

But occasionally we run into situations where a 1D tensor with a single value is used. Currently, ONNX seems to permit this. If we want to allow this in ONNX Script:

  • If we type the loop-body-subgraph to expect a 0D value as "condition", the ONNX checker will fail if and when the actual condition is a 1D tensor
  • If we leave the loop-body-subgraph condition as a "boolean" without any shape, in some cases at least the ONNX checker fails (complaining about unknown rank).
  • If we want to handle both reasonably, we will likely need to integrate shape-inference info into the onnxscript translator so that it can do different things based on the inferred type.
  • One simpler short-cut would be for onnxscript to emit a Reshape/Squeeze for the loop-condition to convert it into a 0D tensor. But ideally, we should not emit this when it is unnecessary. Else, we end up with redundant ops (though a downstream optimizer could potentially remove it).
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

No branches or pull requests

1 participant