Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TVMC][TensorRT] Enable TensorRT target through TVMC #7658

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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: 2 additions & 2 deletions python/tvm/driver/tvmc/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ def compile_model(
for codegen_from_cli in extra_targets:
codegen = composite_target.get_codegen_by_target(codegen_from_cli["name"])
partition_function = codegen["pass_pipeline"]
mod = partition_function(mod, params, **codegen_from_cli["opts"])
mod, codegen_config = partition_function(mod, params, **codegen_from_cli["opts"])
if codegen["config_key"] is not None:
config[codegen["config_key"]] = codegen_from_cli["opts"]
config[codegen["config_key"]] = codegen_config if codegen_config else codegen_from_cli["opts"]

if tuning_records and os.path.exists(tuning_records):
logger.debug("tuning records file provided: %s", tuning_records)
Expand Down
6 changes: 5 additions & 1 deletion python/tvm/driver/tvmc/composite_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from tvm.relay.op.contrib.ethosn import partition_for_ethosn
from tvm.relay.op.contrib.bnns import partition_for_bnns
from tvm.relay.op.contrib.vitis_ai import partition_for_vitis_ai

from tvm.relay.op.contrib.tensorrt import partition_for_tensorrt

from .common import TVMCException

Expand Down Expand Up @@ -61,6 +61,10 @@
"config_key": "relay.ext.vitis_ai.options",
"pass_pipeline": partition_for_vitis_ai,
},
"tensorrt": {
"config_key": "relay.ext.tensorrt.options",
"pass_pipeline": partition_for_tensorrt,
},
}


Expand Down
14 changes: 14 additions & 0 deletions tests/python/driver/tvmc/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,20 @@ def test_compile_tflite_module_with_external_codegen_vitis_ai(tflite_mobilenet_v
assert type(tvmc_package.params) is bytearray
assert os.path.exists(dumps_path)

def test_compile_tflite_module_with_external_codegen_tensorrt(tflite_mobilenet_v1_0_25_128):
pytest.importorskip("tflite")

tvmc_model = tvmc.load(tflite_mobilenet_v1_0_25_128)
tvmc_package = tvmc.compiler.compile_model(
tvmc_model, target="tensorrt, llvm", dump_code="relay")
dumps_path = tvmc_package.package_path + ".relay"

# check for output types
assert type(tvmc_package) is TVMCPackage
assert type(tvmc_package.graph) is str
assert type(tvmc_package.lib_path) is str
assert type(tvmc_package.params) is bytearray
assert os.path.exists(dumps_path)

@mock.patch("tvm.relay.build")
@mock.patch("tvm.driver.tvmc.composite_target.get_codegen_by_target")
Expand Down
1 change: 1 addition & 0 deletions tests/python/driver/tvmc/test_composite_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def test_get_codegen_names():

assert "ethos-n77" in names
assert "vitis-ai" in names
assert "tensorrt" in names
assert len(names) > 0


Expand Down