Skip to content

Commit be5e353

Browse files
author
shoumikhin
committed
[executorch][nvidia][tensorrt][14/n] Add additional converters (mul, sub, div, mm, relu)
Add converters for mul, sub, div, mm, and relu operations. These arithmetic and activation operations are fundamental building blocks used across virtually all neural network architectures. Differential Revision: [D93275045](https://our.internmc.facebook.com/intern/diff/D93275045/) [ghstack-poisoned]
1 parent 353a33a commit be5e353

5 files changed

Lines changed: 34 additions & 4 deletions

File tree

backends/nvidia/tensorrt/converters/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@
88

99
# Import converters to trigger registration via @converter decorator
1010
from executorch.backends.nvidia.tensorrt.converters import add # noqa: F401
11+
from executorch.backends.nvidia.tensorrt.converters import div # noqa: F401
12+
from executorch.backends.nvidia.tensorrt.converters import mm # noqa: F401
13+
from executorch.backends.nvidia.tensorrt.converters import mul # noqa: F401
14+
from executorch.backends.nvidia.tensorrt.converters import relu # noqa: F401
15+
from executorch.backends.nvidia.tensorrt.converters import sub # noqa: F401

backends/nvidia/tensorrt/converters/targets.bzl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ def define_common_targets():
1212
srcs = [
1313
"__init__.py",
1414
"add.py",
15+
"div.py",
16+
"mm.py",
17+
"mul.py",
18+
"relu.py",
19+
"sub.py",
1520
],
1621
visibility = ["PUBLIC"],
1722
deps = [

backends/nvidia/tensorrt/partitioner/operator_support.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,19 @@ class TensorRTOperatorSupport(OperatorSupportBase):
2222
3. Its output dtype is in SUPPORTED_DTYPES
2323
"""
2424

25-
# Operations that have TensorRT converters.
26-
# Format: "op_name.overload" (e.g., "add.Tensor")
25+
# Operations that have TensorRT converters (sorted alphabetically).
2726
SUPPORTED_OPS: Set[str] = {
2827
"add.Tensor",
28+
"add_.Tensor",
29+
"div.Tensor",
30+
"div.Tensor_mode",
31+
"mm.default",
32+
"mul.Scalar",
33+
"mul.Tensor",
34+
"mul_.Tensor",
35+
"relu.default",
36+
"relu_.default",
37+
"sub.Tensor",
2938
}
3039

3140
# Glue operations that don't compute but are needed to keep partitions connected.
@@ -86,8 +95,15 @@ def _get_op_name(self, node: torch.fx.Node) -> str:
8695
if hasattr(target, "_schema"):
8796
schema = target._schema
8897
base_name = schema.name.replace("::", ".")
89-
if hasattr(schema, "overload_name") and schema.overload_name:
90-
return f"{base_name}.{schema.overload_name}"
98+
# Note: For the "default" overload, overload_name is an empty string "",
99+
# so we need to check for that and use "default" as the overload name.
100+
if hasattr(schema, "overload_name"):
101+
overload_name = schema.overload_name
102+
if overload_name:
103+
return f"{base_name}.{overload_name}"
104+
else:
105+
# Empty overload_name means "default" overload
106+
return f"{base_name}.default"
91107
return base_name
92108

93109
# Callable with module info (e.g., operator.getitem)

examples/nvidia/tensorrt/export.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"add",
3737
"add_mul",
3838
"mul",
39+
"softmax",
3940
}
4041

4142

examples/nvidia/tensorrt/tests/test_export.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,6 @@ def test_add_bf16(self) -> None:
9595
exec_prog = edge.to_executorch()
9696
self.assertIsNotNone(exec_prog)
9797
logger.info("PASS: add model exported with BF16 precision")
98+
99+
def test_softmax(self) -> None:
100+
_export_and_verify("softmax")

0 commit comments

Comments
 (0)