You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by "hugolatendresse (via GitHub)" <gi...@apache.org> on 2025/04/14 08:25:58 UTC

[PR] [Relax][Python] support for index.Tensor [tvm]

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

   New op for advanced indexing


-- 
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][PyTorch] support for index.Tensor [tvm]

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


-- 
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][Python] support for index.Tensor [tvm]

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

   @tvm-bot rerun


-- 
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][Python] support for index.Tensor [tvm]

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

   @tvm-bot rerun


-- 
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][Python] support for index.Tensor [tvm]

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

   @tvm-bot rerun


-- 
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][PyTorch] support for index.Tensor [tvm]

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


##########
python/tvm/relax/transform/legalize_ops/manipulate.py:
##########
@@ -162,6 +163,23 @@ def te_gather_nd(data, indices, batch_dims):
     return bb.call_te(te_gather_nd, call.args[0], call.args[1], int(call.attrs.batch_dims))
 
 
+@register_legalize("relax.index_tensor")
+def _index_tensor(bb: BlockBuilder, call: Call) -> Expr:
+    t = call.args[1]
+    n_field = len(t.struct_info.fields)
+    while isinstance(t, Var):
+        binding = bb.lookup_binding(t)
+        if not isinstance(binding, (Tuple, Var)):
+            break
+        t = binding
+
+    assert isinstance(t, (Tuple, Var))

Review Comment:
   It might help understanding if we can briefly explain why backtracing `t` is needed. My understanding is that without backtracing it's still correct, but may result in trivial TupleGetItems that can be easily removed.  Correct me if I'm wrong.



-- 
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][Python] support for index.Tensor [tvm]

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

   @tvm-bot rerun


-- 
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][Python] support for index.Tensor [tvm]

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

   @MasterJH5574 @tlopex this is ready for review.
   
   @tqchen note that this allows OpenAI's Whisper to be ingested by TVM using the exported program translator (after a few minor edits, including remove in-place operations). Correctness is achieved, as tested here https://github.com/hugolatendresse/catalyst-fleet/blob/a4a4be6/whisper/whisper_inlined.py
   
   The tvm-bot refuses to rerun the tests due to Ubuntu 20.04 LTS being retired - maybe [this](https://github.com/apache/tvm/pull/17846) needs to be merged first 


-- 
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][PyTorch] support for index.Tensor [tvm]

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


##########
python/tvm/relax/transform/legalize_ops/manipulate.py:
##########
@@ -162,6 +163,23 @@ def te_gather_nd(data, indices, batch_dims):
     return bb.call_te(te_gather_nd, call.args[0], call.args[1], int(call.attrs.batch_dims))
 
 
+@register_legalize("relax.index_tensor")
+def _index_tensor(bb: BlockBuilder, call: Call) -> Expr:
+    t = call.args[1]
+    n_field = len(t.struct_info.fields)
+    while isinstance(t, Var):
+        binding = bb.lookup_binding(t)
+        if not isinstance(binding, (Tuple, Var)):
+            break
+        t = binding
+
+    assert isinstance(t, (Tuple, Var))

Review Comment:
   @MasterJH5574 you are right that it is not needed. It would simply remove unneeded TupleGetItems like you said. I removed the backtracking and all tests still pass. Let me know if you prefer it like that or if I should revert (I'm indifferent). 



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