From 36823e8dd2aa673703c93b9c525dc78cf6b60f29 Mon Sep 17 00:00:00 2001 From: gs-olive <113141689+gs-olive@users.noreply.github.com> Date: Tue, 25 Jul 2023 14:56:30 -0700 Subject: [PATCH] fix: Update file and reference naming for new API --- docsrc/index.rst | 6 ++--- examples/dynamo/README.rst | 6 ++--- ...age.py => torch_compile_advanced_usage.py} | 5 ++-- ...ple.py => torch_compile_resnet_example.py} | 10 +++---- ... => torch_compile_transformers_example.py} | 27 +++++++++++-------- 5 files changed, 30 insertions(+), 24 deletions(-) rename examples/dynamo/{dynamo_compile_advanced_usage.py => torch_compile_advanced_usage.py} (97%) rename examples/dynamo/{dynamo_compile_resnet_example.py => torch_compile_resnet_example.py} (83%) rename examples/dynamo/{dynamo_compile_transformers_example.py => torch_compile_transformers_example.py} (78%) diff --git a/docsrc/index.rst b/docsrc/index.rst index ace492c84f..eee62bc2f7 100644 --- a/docsrc/index.rst +++ b/docsrc/index.rst @@ -70,9 +70,9 @@ Tutorials tutorials/serving_torch_tensorrt_with_triton tutorials/notebooks - tutorials/_rendered_examples/dynamo/dynamo_compile_resnet_example - tutorials/_rendered_examples/dynamo/dynamo_compile_transformers_example - tutorials/_rendered_examples/dynamo/dynamo_compile_advanced_usage + tutorials/_rendered_examples/dynamo/torch_compile_resnet_example + tutorials/_rendered_examples/dynamo/torch_compile_transformers_example + tutorials/_rendered_examples/dynamo/torch_compile_advanced_usage Python API Documenation ------------------------ diff --git a/examples/dynamo/README.rst b/examples/dynamo/README.rst index d3b6f9ddcf..fa863952e7 100644 --- a/examples/dynamo/README.rst +++ b/examples/dynamo/README.rst @@ -1,4 +1,4 @@ -.. _dynamo_compile: +.. _torch_compile: Dynamo / ``torch.compile`` ---------------------------- @@ -6,6 +6,6 @@ Dynamo / ``torch.compile`` Torch-TensorRT provides a backend for the new ``torch.compile`` API released in PyTorch 2.0. In the following examples we describe a number of ways you can leverage this backend to accelerate inference. -* :ref:`dynamo_compile_resnet`: Compiling a ResNet model using the Dynamo Compile Frontend for ``torch_tensorrt.compile`` +* :ref:`torch_compile_resnet`: Compiling a ResNet model using the Torch Compile Frontend for ``torch_tensorrt.compile`` * :ref:`torch_compile_transformer`: Compiling a Transformer model using ``torch.compile`` -* :ref:`dynamo_compile_advanced_usage`: Advanced usage including making a custom backend to use directly with the ``torch.compile`` API +* :ref:`torch_compile_advanced_usage`: Advanced usage including making a custom backend to use directly with the ``torch.compile`` API diff --git a/examples/dynamo/dynamo_compile_advanced_usage.py b/examples/dynamo/torch_compile_advanced_usage.py similarity index 97% rename from examples/dynamo/dynamo_compile_advanced_usage.py rename to examples/dynamo/torch_compile_advanced_usage.py index dec7e3a544..cce9d9baaa 100644 --- a/examples/dynamo/dynamo_compile_advanced_usage.py +++ b/examples/dynamo/torch_compile_advanced_usage.py @@ -1,7 +1,7 @@ """ -.. _dynamo_compile_advanced_usage: +.. _torch_compile_advanced_usage: -Dynamo Compile Advanced Usage +Torch Compile Advanced Usage ====================================================== This interactive script is intended as an overview of the process by which `torch_tensorrt.dynamo.compile` works, and how it integrates with the new `torch.compile` API.""" @@ -11,6 +11,7 @@ # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ import torch +import torch_tensorrt # %% diff --git a/examples/dynamo/dynamo_compile_resnet_example.py b/examples/dynamo/torch_compile_resnet_example.py similarity index 83% rename from examples/dynamo/dynamo_compile_resnet_example.py rename to examples/dynamo/torch_compile_resnet_example.py index 51bd7fe78e..acdde241f8 100644 --- a/examples/dynamo/dynamo_compile_resnet_example.py +++ b/examples/dynamo/torch_compile_resnet_example.py @@ -1,10 +1,10 @@ """ -.. _dynamo_compile_resnet: +.. _torch_compile_resnet: -Compiling ResNet using the Torch-TensorRT Dyanmo Frontend +Compiling ResNet using the Torch-TensorRT Dynamo Backend ========================================================== -This interactive script is intended as a sample of the `torch_tensorrt.compile` workflow with `torch.compile` on a ResNet model.""" +This interactive script is intended as a sample of the Torch-TensorRT workflow with `torch.compile` on a ResNet model.""" # %% # Imports and Model Definition @@ -57,8 +57,8 @@ ) # %% -# Equivalently, we could have run the above via the convenience frontend, as so: -# `torch_tensorrt.compile(model, ir="dynamo_compile", inputs=inputs, ...)` +# Equivalently, we could have run the above via the torch.compile frontend, as so: +# `optimized_model = torch.compile(model, backend="torch_tensorrt", options={"enabled_precisions": enabled_precisions, ...}); optimized_model(*inputs)` # %% # Inference diff --git a/examples/dynamo/dynamo_compile_transformers_example.py b/examples/dynamo/torch_compile_transformers_example.py similarity index 78% rename from examples/dynamo/dynamo_compile_transformers_example.py rename to examples/dynamo/torch_compile_transformers_example.py index b43e022ae0..5422f9cc1d 100644 --- a/examples/dynamo/dynamo_compile_transformers_example.py +++ b/examples/dynamo/torch_compile_transformers_example.py @@ -4,7 +4,7 @@ Compiling a Transformer using torch.compile and TensorRT ============================================================== -This interactive script is intended as a sample of the `torch_tensorrt.compile` workflow with `torch.compile` on a transformer-based model.""" +This interactive script is intended as a sample of the Torch-TensorRT workflow with `torch.compile` on a transformer-based model.""" # %% # Imports and Model Definition @@ -45,24 +45,29 @@ torch_executed_ops = {} # %% -# Compilation with `torch_tensorrt.compile` +# Compilation with `torch.compile` # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +# Define backend compilation keyword arguments +compilation_kwargs = { + "enabled_precisions": enabled_precisions, + "debug": debug, + "workspace_size": workspace_size, + "min_block_size": min_block_size, + "torch_executed_ops": torch_executed_ops, +} + # Build and compile the model with torch.compile, using Torch-TensorRT backend -optimized_model = torch_tensorrt.compile( +optimized_model = torch.compile( model, - ir="torch_compile", - inputs=inputs, - enabled_precisions=enabled_precisions, - debug=debug, - workspace_size=workspace_size, - min_block_size=min_block_size, - torch_executed_ops=torch_executed_ops, + backend="torch_tensorrt", + options=compilation_kwargs, ) +optimized_model(*inputs) # %% # Equivalently, we could have run the above via the convenience frontend, as so: -# `torch_tensorrt.compile(model, ir="dynamo_compile", inputs=inputs, ...)` +# `torch_tensorrt.compile(model, ir="torch_compile", inputs=inputs, **compilation_kwargs)` # %% # Inference