Skip to content

fix(aten::instance_norm): Handle optional inputs in instance norm con… #3367

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

Merged
merged 7 commits into from
Jan 30, 2025
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
1 change: 0 additions & 1 deletion .github/scripts/generate_binary_build_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,6 @@ def generate_wheels_matrix(
ret: List[Dict[str, Any]] = []
for python_version in python_versions:
for arch_version in arches:

# TODO: Enable Python 3.13 support for ROCM
if arch_version in ROCM_ARCHES and python_version == "3.13":
continue
Expand Down
15 changes: 11 additions & 4 deletions core/conversion/converters/impl/batch_norm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,14 @@ auto batch_norm_registrations TORCHTRT_UNUSED =

auto eps = static_cast<float>(args[7].unwrapToDouble(1e-5f));

auto scales = args[1].unwrapToTensor(at::ones(shape[1], options)).cpu().contiguous();
auto bias = args[2].unwrapToTensor(at::zeros(shape[1], options)).cpu().contiguous();

auto scales = at::ones(shape[1], options);
if (!args[1].IValue()->isNone()) {
scales = args[1].unwrapToTensor(at::ones(shape[1], options)).cpu().contiguous();
}
auto bias = at::zeros(shape[1], options);
if (!args[2].IValue()->isNone()) {
bias = args[2].unwrapToTensor(at::zeros(shape[1], options)).cpu().contiguous();
}
// track_running_stats=True
if (!args[3].IValue()->isNone() || !args[4].IValue()->isNone()) {
auto running_mean = args[3].unwrapToTensor();
Expand All @@ -154,6 +159,8 @@ auto batch_norm_registrations TORCHTRT_UNUSED =
return true;
}

// Not sure this actually does something since the cudnn_enabled is from the PyTorch context.
// We need cuDNN either way to run this converter
auto cudnn_enabled = static_cast<bool>(args[8].unwrapToBool(false));
if (!cudnn_enabled) {
LOG_DEBUG(
Expand All @@ -162,7 +169,7 @@ auto batch_norm_registrations TORCHTRT_UNUSED =
so for some functionalities, users need to install correct \
cuDNN version by themselves. Please see our support matrix \
here: https://docs.nvidia.com/deeplearning/tensorrt/support-matrix/index.html.");
return false;
// return false;
}

const int relu = 0;
Expand Down
1 change: 1 addition & 0 deletions core/util/prelude.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

// A collection of headers from util that will typically get included in most
// files
#include <cstdint>
#include "core/util/Exception.h"
#include "core/util/build_info.h"
#include "core/util/jit_util.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
Torch Compile Advanced Usage
======================================================

This interactive script is intended as an overview of the process by which `torch_tensorrt.compile(..., ir="torch_compile", ...)` works, and how it integrates with the `torch.compile` API."""
This interactive script is intended as an overview of the process by which `torch_tensorrt.compile(..., ir="torch_compile", ...)` works, and how it integrates with the `torch.compile` API.
"""

# %%
# Imports and Model Definition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
Compiling GPT2 using the dynamo backend
==========================================================

This script illustrates Torch-TensorRT workflow with dynamo backend on popular GPT2 model."""
This script illustrates Torch-TensorRT workflow with dynamo backend on popular GPT2 model.
"""

# %%
# Imports and Model Definition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
Torch Export with Cudagraphs
======================================================

This interactive script is intended as an overview of the process by which the Torch-TensorRT Cudagraphs integration can be used in the `ir="dynamo"` path. The functionality works similarly in the `torch.compile` path as well."""
This interactive script is intended as an overview of the process by which the Torch-TensorRT Cudagraphs integration can be used in the `ir="dynamo"` path. The functionality works similarly in the `torch.compile` path as well.
"""

# %%
# Imports and Model Definition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
Compiling ResNet using the Torch-TensorRT Dyanmo Frontend
==========================================================

This interactive script is intended as a sample of the `torch_tensorrt.dynamo.compile` workflow on a ResNet model."""
This interactive script is intended as a sample of the `torch_tensorrt.dynamo.compile` workflow on a ResNet model.
"""

# %%
# Imports and Model Definition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
Compiling Llama2 using the dynamo backend
==========================================================

This script illustrates Torch-TensorRT workflow with dynamo backend on popular Llama2 model."""
This script illustrates Torch-TensorRT workflow with dynamo backend on popular Llama2 model.
"""

# %%
# Imports and Model Definition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:

import cupy as cp # Needed to work around API gaps in PyTorch to build torch.Tensors around preallocated CUDA memory
import numpy as np

import tensorrt as trt


Expand Down Expand Up @@ -348,7 +347,6 @@ def get_output_dimensions(
inputs: List[trt.DimsExprs],
exprBuilder: trt.IExprBuilder,
) -> trt.DimsExprs:

output_dims = trt.DimsExprs(inputs[0])

for i in range(np.size(self.pads) // 2):
Expand Down Expand Up @@ -404,7 +402,6 @@ def enqueue(
workspace: int,
stream: int,
) -> None:

# Host code is slightly different as this will be run as part of the TRT execution
in_dtype = torchtrt.dtype.try_from(input_desc[0].type).to(np.dtype)

Expand Down Expand Up @@ -528,7 +525,6 @@ def circular_padding_converter(
kwargs: Dict[str, Argument],
name: str,
):

# How to retrieve a plugin if it is defined elsewhere (e.g. linked library)
plugin_registry = trt.get_plugin_registry()
plugin_creator = plugin_registry.get_plugin_creator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
Compiling ResNet with dynamic shapes using the `torch.compile` backend
==========================================================

This interactive script is intended as a sample of the Torch-TensorRT 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
Compiling BERT using the `torch.compile` backend
==============================================================

This interactive script is intended as a sample of the Torch-TensorRT workflow with `torch.compile` on a BERT model."""
This interactive script is intended as a sample of the Torch-TensorRT workflow with `torch.compile` on a BERT model.
"""

# %%
# Imports and Model Definition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
Dynamo 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."""
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.
"""

# %%
# Imports and Model Definition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
Compiling a Transformer using torch.compile and TensorRT
==============================================================

This interactive script is intended as a sample of the `torch_tensorrt.dynamo.compile` workflow on a transformer-based model."""
This interactive script is intended as a sample of the `torch_tensorrt.dynamo.compile` workflow on a transformer-based model.
"""

# %%
# Imports and Model Definition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
Compiling ResNet using the Torch-TensorRT Dyanmo Frontend
==========================================================

This interactive script is intended as a sample of the `torch_tensorrt.dynamo.compile` workflow on a ResNet model."""
This interactive script is intended as a sample of the `torch_tensorrt.dynamo.compile` workflow on a ResNet model.
"""

# %%
# Imports and Model Definition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
Dynamo 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."""
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.
"""

# %%
# Imports and Model Definition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
Compiling a Transformer using torch.compile and TensorRT
==============================================================

This interactive script is intended as a sample of the `torch_tensorrt.dynamo.compile` workflow on a transformer-based model."""
This interactive script is intended as a sample of the `torch_tensorrt.dynamo.compile` workflow on a transformer-based model.
"""

# %%
# Imports and Model Definition
Expand Down
4 changes: 0 additions & 4 deletions examples/dynamo/custom_kernel_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:

import cupy as cp # Needed to work around API gaps in PyTorch to build torch.Tensors around preallocated CUDA memory
import numpy as np

import tensorrt as trt


Expand Down Expand Up @@ -348,7 +347,6 @@ def get_output_dimensions(
inputs: List[trt.DimsExprs],
exprBuilder: trt.IExprBuilder,
) -> trt.DimsExprs:

output_dims = trt.DimsExprs(inputs[0])

for i in range(np.size(self.pads) // 2):
Expand Down Expand Up @@ -404,7 +402,6 @@ def enqueue(
workspace: int,
stream: int,
) -> None:

# Host code is slightly different as this will be run as part of the TRT execution
in_dtype = torchtrt.dtype.try_from(input_desc[0].type).to(np.dtype)

Expand Down Expand Up @@ -528,7 +525,6 @@ def circular_padding_converter(
kwargs: Dict[str, Argument],
name: str,
):

# How to retrieve a plugin if it is defined elsewhere (e.g. linked library)
plugin_registry = trt.get_plugin_registry()
plugin_creator = plugin_registry.get_plugin_creator(
Expand Down
3 changes: 2 additions & 1 deletion examples/dynamo/torch_compile_advanced_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
Torch Compile Advanced Usage
======================================================

This interactive script is intended as an overview of the process by which `torch_tensorrt.compile(..., ir="torch_compile", ...)` works, and how it integrates with the `torch.compile` API."""
This interactive script is intended as an overview of the process by which `torch_tensorrt.compile(..., ir="torch_compile", ...)` works, and how it integrates with the `torch.compile` API.
"""

# %%
# Imports and Model Definition
Expand Down
3 changes: 2 additions & 1 deletion examples/dynamo/torch_compile_resnet_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
Compiling ResNet with dynamic shapes using the `torch.compile` backend
==========================================================

This interactive script is intended as a sample of the Torch-TensorRT 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
Expand Down
3 changes: 2 additions & 1 deletion examples/dynamo/torch_compile_transformers_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
Compiling BERT using the `torch.compile` backend
==============================================================

This interactive script is intended as a sample of the Torch-TensorRT workflow with `torch.compile` on a BERT model."""
This interactive script is intended as a sample of the Torch-TensorRT workflow with `torch.compile` on a BERT model.
"""

# %%
# Imports and Model Definition
Expand Down
3 changes: 2 additions & 1 deletion examples/dynamo/torch_export_cudagraphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
Torch Export with Cudagraphs
======================================================

This interactive script is intended as an overview of the process by which the Torch-TensorRT Cudagraphs integration can be used in the `ir="dynamo"` path. The functionality works similarly in the `torch.compile` path as well."""
This interactive script is intended as an overview of the process by which the Torch-TensorRT Cudagraphs integration can be used in the `ir="dynamo"` path. The functionality works similarly in the `torch.compile` path as well.
"""

# %%
# Imports and Model Definition
Expand Down
3 changes: 2 additions & 1 deletion examples/dynamo/torch_export_gpt2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
Compiling GPT2 using the dynamo backend
==========================================================

This script illustrates Torch-TensorRT workflow with dynamo backend on popular GPT2 model."""
This script illustrates Torch-TensorRT workflow with dynamo backend on popular GPT2 model.
"""

# %%
# Imports and Model Definition
Expand Down
3 changes: 2 additions & 1 deletion examples/dynamo/torch_export_llama2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
Compiling Llama2 using the dynamo backend
==========================================================

This script illustrates Torch-TensorRT workflow with dynamo backend on popular Llama2 model."""
This script illustrates Torch-TensorRT workflow with dynamo backend on popular Llama2 model.
"""

# %%
# Imports and Model Definition
Expand Down
14 changes: 4 additions & 10 deletions notebooks/CitriNet-example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -384,12 +384,11 @@
"metadata": {},
"outputs": [],
"source": [
"import nemo\n",
"import torch\n",
"\n",
"import nemo.collections.asr as nemo_asr\n",
"from nemo.core import typecheck\n",
"typecheck.set_typecheck_enabled(False) "
"typecheck.set_typecheck_enabled(False)"
]
},
{
Expand Down Expand Up @@ -572,11 +571,8 @@
"from __future__ import absolute_import\n",
"from __future__ import division\n",
"\n",
"import argparse\n",
"import timeit\n",
"import numpy as np\n",
"import torch\n",
"import torch_tensorrt as trtorch\n",
"import torch.backends.cudnn as cudnn\n",
"\n",
"def benchmark(model, input_tensor, num_loops, model_name, batch_size):\n",
Expand Down Expand Up @@ -632,7 +628,7 @@
" else:\n",
" model_name = f\"{variant}.ts\"\n",
"\n",
" print(f\"Loading model: {model_name}\") \n",
" print(f\"Loading model: {model_name}\")\n",
" # Load traced model to CPU first\n",
" model = torch.jit.load(model_name).cuda()\n",
" cudnn.benchmark = True\n",
Expand Down Expand Up @@ -727,9 +723,7 @@
],
"source": [
"import torch\n",
"import torch.nn as nn\n",
"import torch_tensorrt as torchtrt\n",
"import argparse\n",
"\n",
"variant = \"stt_en_citrinet_256\"\n",
"precisions = [torch.float, torch.half]\n",
Expand Down Expand Up @@ -827,7 +821,7 @@
" else:\n",
" model_name = f\"{variant}.ts\"\n",
"\n",
" print(f\"Loading model: {model_name}\") \n",
" print(f\"Loading model: {model_name}\")\n",
" # Load traced model to CPU first\n",
" model = torch.jit.load(model_name).cuda()\n",
" cudnn.benchmark = True\n",
Expand Down Expand Up @@ -906,7 +900,7 @@
" else:\n",
" model_name = f\"{variant}.ts\"\n",
"\n",
" print(f\"Loading model: {model_name}\") \n",
" print(f\"Loading model: {model_name}\")\n",
" # Load traced model to CPU first\n",
" model = torch.jit.load(model_name).cuda()\n",
" cudnn.benchmark = True\n",
Expand Down
Loading
Loading