From 1fec187c054562dac1759648eed8f23dcbb65eb5 Mon Sep 17 00:00:00 2001 From: cchung100m Date: Thu, 16 Oct 2025 20:00:00 +0800 Subject: [PATCH 1/2] [#18373] improve the check for no bias situation --- .../torch/base_fx_graph_translator.py | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/python/tvm/relax/frontend/torch/base_fx_graph_translator.py b/python/tvm/relax/frontend/torch/base_fx_graph_translator.py index c1cbd3416c57..b17f62738f0a 100644 --- a/python/tvm/relax/frontend/torch/base_fx_graph_translator.py +++ b/python/tvm/relax/frontend/torch/base_fx_graph_translator.py @@ -88,6 +88,22 @@ def shape_of(tensor): return tensor.shape raise ValueError("Unsupported type: {}".format(type(tensor))) + @staticmethod + def _is_no_bias(bias): + """Check if bias represents 'no bias' condition. + + This handles both Python None and relax.op.null_value() expressions + that might be used to represent missing bias parameters. + """ + if bias is None: + return True + + # Check if this is a null_value expression + if isinstance(bias, relax.Call) and bias.op.name == "relax.null_value": + return True + + return False + def retrieve_args(self, node: fx.Node): return self._retrieve_args(node.args) @@ -103,7 +119,7 @@ def _retrieve_args(self, node): elif isinstance(node, dict): return {self._retrieve_args(k): self._retrieve_args(v) for k, v in node.items()} elif node is None: - return relax.op.null_value() + return None else: return node @@ -758,7 +774,7 @@ def _conv_transpose1d_impl( ) ) - if bias is None: + if self._is_no_bias(bias): return conv1d_transpose assert len(self.shape_of(bias)) == 1 @@ -812,7 +828,7 @@ def _conv_transpose2d_impl( ) ) - if bias is None: + if self._is_no_bias(bias): return conv2d_transpose assert len(self.shape_of(bias)) == 1 @@ -864,7 +880,7 @@ def _conv1d_impl( ) ) - if bias is None: + if self._is_no_bias(bias): return conv1d assert len(self.shape_of(bias)) == 1 bias = relax.op.reshape(bias, (1, -1, 1)) @@ -913,7 +929,7 @@ def _conv2d_impl( ) ) - if bias is None: + if self._is_no_bias(bias): return conv2d assert len(self.shape_of(bias)) == 1 bias = relax.op.reshape(bias, (1, -1, 1, 1)) @@ -962,7 +978,7 @@ def _conv3d_impl( ) ) - if bias is None: + if self._is_no_bias(bias): return conv3d assert len(self.shape_of(bias)) == 1 bias = relax.op.reshape(bias, (1, -1, 1, 1, 1)) From 443801d08021d1a33def9030d753605ca69a43db Mon Sep 17 00:00:00 2001 From: cchung100m Date: Mon, 20 Oct 2025 23:58:50 +0800 Subject: [PATCH 2/2] [#18373] refactor the _normalize_python_tuple --- python/tvm/relax/block_builder.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/python/tvm/relax/block_builder.py b/python/tvm/relax/block_builder.py index 26a8346b0a9e..8c777eb53756 100644 --- a/python/tvm/relax/block_builder.py +++ b/python/tvm/relax/block_builder.py @@ -299,6 +299,10 @@ def _normalize_python_tuple(self, expr: Union[Expr, Sequence[Expr]]): """ if isinstance(expr, (list, tuple)): return Tuple([self._normalize_python_tuple(element) for element in expr]) + elif expr is None: + from . import op + + return op.null_value() else: return expr