You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by "Lunderberg (via GitHub)" <gi...@apache.org> on 2024/02/08 01:05:59 UTC

[PR] [Relax] Support callback as argument [tvm]

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

   Prior to this commit, calls from Relax to external PackedFuncs could only be done through the TVM global registry.  While Relax functions accepting a callback could be written as `callback_arg: R.Callable(arg_struct_info, ret_struct_info)`, attempting to compile these functions would raise an error during the `CodeGenVM` step of `relax.build`.  In addition, the global registry is only queried when initializing the `relax.VirtualMachine`, and so later changes requires restarting the VM.
   
   This commit updates both the `CodeGenVM` lowering pass and the relax VM to support callbacks.  The motivating use case is with the `LazyTransformParams` pass, to improve flexibility by avoiding use of the global registry.


-- 
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


Re: [PR] [Relax] Support callback as argument [tvm]

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

   Merged from main to PR branch, to resolve CI breakage that was fixed in https://github.com/apache/tvm/pull/16546.


-- 
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


Re: [PR] [Relax] Support callback as argument [tvm]

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

   cc @yongwww  as well


-- 
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


Re: [PR] [Relax] Support callback as argument [tvm]

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

   @tqchen Thank you, and I'll make a follow-up PR.  I had thought that `vm.builtin.invoke_closure` was only for use with internally-generated closure objects.


-- 
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


Re: [PR] [Relax] Support callback as argument [tvm]

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

   I've submitted https://github.com/apache/tvm/pull/16573, which updates the handling of callback functions, reverts the VM changes, and passes the unit tests that were added in this PR.


-- 
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


Re: [PR] [Relax] Support callback as argument [tvm]

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


##########
include/tvm/runtime/relax_vm/bytecode.h:
##########
@@ -183,10 +184,15 @@ struct Instruction {
   /*! \brief The instruction opcode. */
   Opcode op;
   union {
-    struct /* Call */ {
+    struct /* Call, CallFromRegister */ {
       /*! \brief The destination register. */
       RegName dst;
-      /*! \brief The index into the packed function table. */
+      /*! \brief The index of the function.
+       *
+       * For `OpCode::Call`, this is an index into the table of static

Review Comment:
   we should not use CallFromRegister, instead we should lower to https://github.com/apache/tvm/blob/main/src/runtime/relax_vm/builtin.cc#L373 



-- 
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


Re: [PR] [Relax] Support callback as argument [tvm]

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


-- 
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


Re: [PR] [Relax] Support callback as argument [tvm]

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

   Good to know re: invoke_closure


-- 
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


Re: [PR] [Relax] Support callback as argument [tvm]

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

   Sorry for being late on this one. In this particular case, it is better to use  `vm.builtin.invoke_closure` to lower those possible variables that contains the Callable. There are two reasons for this
   
   - One goal of relax VM is to ensure minimal set of instructions, so far we have been keeping the miminum variant via Call and all the rest call variant using builtins like `vm.builtin.invoke_closure`
   - We need to handle the case where callback is either a PackedFunc or Closure,  `invoke_closure` handles the case. This enables reuse for compiled cases
   
   @Lunderberg  would be great to followup on this soon given this would change some binary format of the VM https://github.com/apache/tvm/blob/main/src/runtime/relax_vm/builtin.cc#L373
   


-- 
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