-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TVMScript][Relax] Allow return statement in DataflowBlock (#17131)
Prior to this commit, TVMScript required the return value of a Relax to be specified outside of any `with R.dataflow()` blocks. This resulted in a common pattern, where the return value of a function was first called with `R.output(ret_value)`, to mark `ret_value` as a `tvm::relax::Var` instead of a `tvm::relax::DataflowVar`, followed immediately by a `return ret_value` statement. This commit updates the TVMScript parser to allow a `return` statement inside a `with R.dataflow()` block. This is syntactic sugar that is equivalent to calling `R.output`, followed by a `return`. With this change, the following two TVMScript examples are now equivalent. (Prior to this change, the `return_inside_dataflow` example would raise an error during parsing.) ```python @R.function(private=True) def output_then_return(A: R.Tensor): with R.dataflow(): B = R.add(A, A) C = R.multiply(B, B) R.output(C) return C @R.function(private=True) def return_inside_dataflow(A: R.Tensor): with R.dataflow(): B = R.add(A, A) C = R.multiply(B, B) return C ```
- Loading branch information
1 parent
ff8e416
commit a242046
Showing
3 changed files
with
75 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters