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

[Relax][Bugfix] Infer TIR values from shapes inside a tuple #17312

Conversation

Lunderberg
Copy link
Contributor

If a Relax function contains an R.match_cast that defines a symbolic shape, and the value provided to the R.match_cast has a known static shape, the relax.transform.CanoncalizeBindings() pass can in-line the known static shape. However, while these known TIR values were only collected if the expression used in R.match_cast was a R.Tensor, R.Shape, and R.Prim (Relax types which may contain symbolic TIR values), they were not collected if the R.match_cast expression was a R.Tuple.

For example, while using R.match_cast to convert from R.Tensor([16]) to R.Tensor([batch_size]) would identify that batch_size must be 16, using R.match_cast to convert from R.Tuple(R.Tensor([16])) to R.Tuple(R.Tensor([batch_size])) would not.

This commit updates the InferSymbolicVarMap to collect all symbolic shapes, even if they occur within a R.Tuple.

If a Relax function contains an `R.match_cast` that defines a symbolic
shape, and the value provided to the `R.match_cast` has a known static
shape, the `relax.transform.CanoncalizeBindings()` pass can in-line
the known static shape.  However, while these known TIR values were
only collected if the expression used in `R.match_cast` was a
`R.Tensor`, `R.Shape`, and `R.Prim` (Relax types which may contain
symbolic TIR values), they were not collected if the `R.match_cast`
expression was a `R.Tuple`.

For example, while using `R.match_cast` to convert from
`R.Tensor([16])` to `R.Tensor([batch_size])` would identify that
`batch_size` must be `16`, using `R.match_cast` to convert from
`R.Tuple(R.Tensor([16]))` to `R.Tuple(R.Tensor([batch_size]))` would
not.

This commit updates the `InferSymbolicVarMap` to collect all symbolic
shapes, even if they occur within a `R.Tuple`.
@vinx13 vinx13 merged commit be8607d into apache:main Aug 28, 2024
18 of 19 checks passed
@Lunderberg Lunderberg deleted the relax_bugfix_infer_tir_values_from_shape_inside_tuple branch August 29, 2024 14:01
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.

2 participants