V-aerus commented on code in PR #19937:
URL: https://github.com/apache/tvm/pull/19937#discussion_r3523202149
##########
python/tvm/relax/frontend/torch/base_fx_graph_translator.py:
##########
@@ -2619,6 +2619,16 @@ def _masked_select(self, node: fx.Node) -> relax.Var:
data_flat = self.block_builder.emit(relax.op.reshape(data, [-1]))
mask_flat = self.block_builder.emit(relax.op.reshape(mask, [-1]))
indices = self.block_builder.emit(relax.op.nonzero(mask_flat))
+ tensor_meta = node.meta.get("tensor_meta")
+ if tensor_meta is not None and len(tensor_meta.shape) == 1:
+ num_selected = tensor_meta.shape[0]
+ if not isinstance(num_selected, int):
+ num_selected = tirx.Var(str(num_selected), "int64")
+ else:
+ num_selected = tirx.Var(f"{node.name}_num_selected", "int64")
+ indices = self.block_builder.match_cast(
+ indices, relax.TensorType([1, num_selected], "int64")
+ )
Review Comment:
Thanks for the review. I checked the current TVM Relax API and existing code
patterns. `BlockBuilder.match_cast` is used with `relax.TensorType(shape,
dtype)` in the current codebase, for example in
`tests/python/relax/test_blockbuilder_core.py`, and the ONNX frontend has a
similar `nonzero ->
match_cast` pattern using `relax.TensorType([1, num_nonzero], "int64")`.
Also, in this TVM version, `relax.TensorType` accepts a shape and dtype. I
don't see `relax.TensorStructInfo` being used in the current tree. The current
code passes the targeted masked_select tests, so I will keep this as
`TensorType` unless maintainers prefer a different API.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]