You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by "yongwww (via GitHub)" <gi...@apache.org> on 2023/02/24 23:41:51 UTC

[GitHub] [tvm] yongwww opened a new pull request, #14123: [Unity][TVMScript] emit_te sugar

yongwww opened a new pull request, #14123:
URL: https://github.com/apache/tvm/pull/14123

   Add R.emit_te, a requested support https://github.com/tlc-pack/relax/issues/197
   
   cc: @psrivas2 @Hzfengsy @YuchenJin @tqchen 
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] psrivas2 commented on a diff in pull request #14123: [Unity][TVMScript] emit_te sugar

Posted by "psrivas2 (via GitHub)" <gi...@apache.org>.
psrivas2 commented on code in PR #14123:
URL: https://github.com/apache/tvm/pull/14123#discussion_r1118867699


##########
python/tvm/script/ir_builder/relax/ir.py:
##########
@@ -325,6 +327,35 @@ def emit(value: Expr, annotate_struct_info: Optional[StructInfo] = None) -> Var:
     return _ffi_api.Emit(value, annotate_struct_info)  # type: ignore[attr-defined] # pylint: disable=no-member
 
 
+def emit_te(func: Callable, *args: Any, **kwargs: Any) -> Var:
+    """Emit a call node according to the te function.
+    This function converts arguments from relax expression to te tensor,
+    The callback func should return a te tensor or a list of te tensors.
+
+    Parameters
+    ----------
+    func : Callable
+        A function that returns a te tensor or a list of te tensors.
+
+    args : Any, optional
+        arguments passed to the function.
+
+    kwargs : Any, optional
+        The keyword arguments passed to the function.
+        Note that the key "primfunc_name_hint" is reserved for passing name hint
+        to the PrimFunc that gets generated.
+
+    Returns
+    -------
+    var : Var
+        A newly created variable that gets bound to the call code.
+    """
+
+    # Levarage the util function call_te in Relax Block Blocker
+    emit_expr = rx_bb().call_te(func, *args, **kwargs)

Review Comment:
   this would emit the call binding correctly, but would it add the Primfunc to IRModule?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] tqchen merged pull request #14123: [Unity][TVMScript] emit_te sugar

Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen merged PR #14123:
URL: https://github.com/apache/tvm/pull/14123


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] tqchen commented on pull request #14123: [Unity][TVMScript] emit_te sugar

Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on PR #14123:
URL: https://github.com/apache/tvm/pull/14123#issuecomment-1446725500

   Ah sorry i missed it!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] yongwww commented on pull request #14123: [Unity][TVMScript] emit_te sugar

Posted by "yongwww (via GitHub)" <gi...@apache.org>.
yongwww commented on PR #14123:
URL: https://github.com/apache/tvm/pull/14123#issuecomment-1453883107

   > Thanks for example @yongwww . In the output of `Before.show()` PrimFuncs for `add`, `squeeze` and `exp` are not emitted. I only see the Relax function `main` present in the module.
   
   ohhhhhh, i see, thanks for pointing this out!!! Will fix it by end of week.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] yongwww commented on pull request #14123: [Unity][TVMScript] emit_te sugar

Posted by "yongwww (via GitHub)" <gi...@apache.org>.
yongwww commented on PR #14123:
URL: https://github.com/apache/tvm/pull/14123#issuecomment-1446683807

   
   > Thanks @yongwww , as a followup, would be great if we can also confirm if it works on TVMScript parser
   
   Thanks @tqchen! Is the following test case what you meant?
   
   ```python
   @tvm.script.ir_module
       class Before:
           @R.function
           def main(x: R.Tensor((10, 20), "float32")) -> R.Tensor(None, "float32", ndim=2):
               # block 0
               with R.dataflow():
                   lv0 = R.emit_te(topi.add, x, relax.const(1, "float32"))
                   lv1 = R.emit_te(topi.exp, lv0)
                   gv = R.emit_te(topi.squeeze, lv1)
                   R.output(gv)
               return gv
   
       Before.show()
   ```
   
   output of Before.show():
   ```python
   @I.ir_module
   class Module:
       @R.function
       def main(
           x: R.Tensor((10, 20), dtype="float32")
       ) -> R.Tensor((10, 20), dtype="float32"):
           with R.dataflow():
               lv = R.call_tir(
                   add,
                   (x, R.const(1, "float32")),
                   out_sinfo=R.Tensor((10, 20), dtype="float32"),
               )
               lv0: R.Tensor((10, 20), dtype="float32") = lv
               lv2 = R.call_tir(exp, (lv0,), out_sinfo=R.Tensor((10, 20), dtype="float32"))
               lv1: R.Tensor((10, 20), dtype="float32") = lv2
               lv4 = R.call_tir(
                   squeeze, (lv1,), out_sinfo=R.Tensor((10, 20), dtype="float32")
               )
               gv: R.Tensor((10, 20), dtype="float32") = lv4
               R.output(gv)
           return gv
   ```
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] psrivas2 commented on pull request #14123: [Unity][TVMScript] emit_te sugar

Posted by "psrivas2 (via GitHub)" <gi...@apache.org>.
psrivas2 commented on PR #14123:
URL: https://github.com/apache/tvm/pull/14123#issuecomment-1446803243

   Thanks for example @yongwww . In the output of `Before.show()` PrimFuncs for `add`, `squeeze` and `exp` are not emitted. I only see the Relax function `main` present in the module.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] tqchen commented on pull request #14123: [Unity][TVMScript] emit_te sugar

Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on PR #14123:
URL: https://github.com/apache/tvm/pull/14123#issuecomment-1446388364

   Thanks @yongwww , as a followup, would be great if we can also confirm if it works on TVMScript parser


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] tvm-bot commented on pull request #14123: [Unity][TVMScript] emit_te sugar

Posted by "tvm-bot (via GitHub)" <gi...@apache.org>.
tvm-bot commented on PR #14123:
URL: https://github.com/apache/tvm/pull/14123#issuecomment-1444723646

   <!---bot-comment-->
   
   Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from [Reviewers](https://github.com/apache/incubator-tvm/blob/master/CONTRIBUTORS.md#reviewers) by @-ing them in a comment.
   
   <!--bot-comment-ccs-start-->
    * cc @Hzfengsy, @junrushao, @quic-sanirudh, @shingjan <sub>See [#10317](https://github.com/apache/tvm/issues/10317) for details</sub><!--bot-comment-ccs-end-->
   
   <sub>Generated by [tvm-bot](https://github.com/apache/tvm/blob/main/ci/README.md#github-actions)</sub>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] psrivas2 commented on pull request #14123: [Unity][TVMScript] emit_te sugar

Posted by "psrivas2 (via GitHub)" <gi...@apache.org>.
psrivas2 commented on PR #14123:
URL: https://github.com/apache/tvm/pull/14123#issuecomment-1446355370

   awesome, thanks!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] yongwww commented on a diff in pull request #14123: [Unity][TVMScript] emit_te sugar

Posted by "yongwww (via GitHub)" <gi...@apache.org>.
yongwww commented on code in PR #14123:
URL: https://github.com/apache/tvm/pull/14123#discussion_r1119003108


##########
python/tvm/script/ir_builder/relax/ir.py:
##########
@@ -325,6 +327,35 @@ def emit(value: Expr, annotate_struct_info: Optional[StructInfo] = None) -> Var:
     return _ffi_api.Emit(value, annotate_struct_info)  # type: ignore[attr-defined] # pylint: disable=no-member
 
 
+def emit_te(func: Callable, *args: Any, **kwargs: Any) -> Var:
+    """Emit a call node according to the te function.
+    This function converts arguments from relax expression to te tensor,
+    The callback func should return a te tensor or a list of te tensors.
+
+    Parameters
+    ----------
+    func : Callable
+        A function that returns a te tensor or a list of te tensors.
+
+    args : Any, optional
+        arguments passed to the function.
+
+    kwargs : Any, optional
+        The keyword arguments passed to the function.
+        Note that the key "primfunc_name_hint" is reserved for passing name hint
+        to the PrimFunc that gets generated.
+
+    Returns
+    -------
+    var : Var
+        A newly created variable that gets bound to the call code.
+    """
+
+    # Levarage the util function call_te in Relax Block Blocker
+    emit_expr = rx_bb().call_te(func, *args, **kwargs)

Review Comment:
   Yes, the actual emit happens later. Actually the call_te is just a helper function, it is used to help prepare the expr to be emitted later.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org