Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions python/tvm/relax/block_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 22 additions & 6 deletions python/tvm/relax/frontend/torch/base_fx_graph_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down