Skip to content

Commit

Permalink
Deprecate torchscript frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
narendasan committed Jan 31, 2025
1 parent 1fb79d0 commit d707352
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
exclude: ^.github/actions/assigner/dist
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v5.0.0
hooks:
- id: check-yaml
- id: trailing-whitespace
Expand Down Expand Up @@ -32,7 +32,7 @@ repos:
hooks:
- id: validate-pyproject
- repo: https://github.com/pycqa/isort
rev: 5.13.2
rev: 6.0.0
hooks:
- id: isort
name: isort (python)
Expand All @@ -52,7 +52,7 @@ repos:
- id: black
exclude: ^examples/custom_converters/elu_converter/setup.py|^docs
- repo: https://github.com/crate-ci/typos
rev: v1.22.9
rev: typos-dict-v0.12.4
hooks:
- id: typos
- repo: https://github.com/astral-sh/uv-pre-commit
Expand Down
1 change: 1 addition & 0 deletions cpp/include/torch_tensorrt/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
STR(TORCH_TENSORRT_MAJOR_VERSION) \
"." STR(TORCH_TENSORRT_MINOR_VERSION) "." STR(TORCH_TENSORRT_PATCH_VERSION)

#define TORCH_TENSORRT_PTQ_DEPRECATION [[deprecated("Int8 PTQ Calibrator has been deprecated by TensorRT, please plan on porting to a NVIDIA Model Optimizer Toolkit based workflow. See: https://pytorch.org/TensorRT/tutorials/_rendered_examples/dynamo/vgg16_ptq.html for more details")]]
// Setup namespace aliases for ease of use
namespace torch_tensorrt {
namespace torchscript {}
Expand Down
7 changes: 3 additions & 4 deletions cpp/include/torch_tensorrt/ptq.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Int8Calibrator : Algorithm {
* calibration cache
* @param use_cache : bool - Whether to use the cache (if it exists)
*/
Int8Calibrator(DataLoaderUniquePtr dataloader, const std::string& cache_file_path, bool use_cache)
Int8Calibrator(DataLoaderUniquePtr dataloader, const std::string& cache_file_path, bool use_cache)
: dataloader_(dataloader.get()), cache_file_path_(cache_file_path), use_cache_(use_cache) {
for (auto batch : *dataloader_) {
batched_data_.push_back(batch.data);
Expand Down Expand Up @@ -308,9 +308,8 @@ class Int8CacheCalibrator : Algorithm {
* @param use_cache: bool - use calibration cache
* @return Int8Calibrator<Algorithm, DataLoader>
*/

template <typename Algorithm = nvinfer1::IInt8EntropyCalibrator2, typename DataLoader>
inline Int8Calibrator<Algorithm, DataLoader> make_int8_calibrator(
TORCH_TENSORRT_PTQ_DEPRECATION inline Int8Calibrator<Algorithm, DataLoader> make_int8_calibrator(
DataLoader dataloader,
const std::string& cache_file_path,
bool use_cache) {
Expand Down Expand Up @@ -344,7 +343,7 @@ inline Int8Calibrator<Algorithm, DataLoader> make_int8_calibrator(
* @return Int8CacheCalibrator<Algorithm>
*/
template <typename Algorithm = nvinfer1::IInt8EntropyCalibrator2>
inline Int8CacheCalibrator<Algorithm> make_int8_cache_calibrator(const std::string& cache_file_path) {
TORCH_TENSORRT_PTQ_DEPRECATION inline Int8CacheCalibrator<Algorithm> make_int8_cache_calibrator(const std::string& cache_file_path) {
return Int8CacheCalibrator<Algorithm>(cache_file_path);
}

Expand Down
13 changes: 13 additions & 0 deletions py/torch_tensorrt/ts/_compiler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import warnings
from typing import Any, List, Optional, Sequence, Set, Tuple

import torch
Expand Down Expand Up @@ -102,6 +103,12 @@ def compile(
torch.jit.ScriptModule: Compiled TorchScript Module, when run it will execute via TensorRT
"""

warnings.warn(
'The torchscript frontend for Torch-TensorRT has been deprecated, please plan on porting to the dynamo frontend (torch_tensorrt.compile(..., ir="dynamo"). Torchscript will continue to be a supported deployment format via post compilation torchscript tracing, see: https://pytorch.org/TensorRT/user_guide/saving_models.html for more details',
DeprecationWarning,
stacklevel=2
)

input_list = list(inputs) if inputs is not None else []
enabled_precisions_set = (
enabled_precisions if enabled_precisions is not None else set()
Expand Down Expand Up @@ -240,6 +247,12 @@ def convert_method_to_trt_engine(
Returns:
bytes: Serialized TensorRT engine, can either be saved to a file or deserialized via TensorRT APIs
"""
warnings.warn(
'The torchscript frontend for Torch-TensorRT has been deprecated, please plan on porting to the dynamo frontend (torch_tensorrt.convert_method_to_trt_engine(..., ir="dynamo"). Torchscript will continue to be a supported deployment format via post compilation torchscript tracing, see: https://pytorch.org/TensorRT/user_guide/saving_models.html for more details',
DeprecationWarning,
stacklevel=2
)

input_list = list(inputs) if inputs is not None else []
enabled_precisions_set = (
enabled_precisions if enabled_precisions is not None else {torch.float}
Expand Down
12 changes: 12 additions & 0 deletions py/torch_tensorrt/ts/ptq.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from torch_tensorrt import _C
from torch_tensorrt.ts.logging import Level, log

import warnings


class CalibrationAlgo(Enum):
ENTROPY_CALIBRATION = _C.CalibrationAlgo.ENTROPY_CALIBRATION
Expand Down Expand Up @@ -88,6 +90,11 @@ def __init__(self, **kwargs: Any):
pass

def __new__(cls, *args: Any, **kwargs: Any) -> Self:
warnings.warn(
"Int8 PTQ Calibrator has been deprecated by TensorRT, please plan on porting to a NVIDIA Model Optimizer Toolkit based workflow. See: https://pytorch.org/TensorRT/tutorials/_rendered_examples/dynamo/vgg16_ptq.html for more details",
DeprecationWarning,
stacklevel=2
)
dataloader = args[0]
algo_type = kwargs.get("algo_type", CalibrationAlgo.ENTROPY_CALIBRATION_2)
cache_file = kwargs.get("cache_file", None)
Expand Down Expand Up @@ -175,6 +182,11 @@ def __init__(self, **kwargs: Any):
pass

def __new__(cls, *args: Any, **kwargs: Any) -> Self:
warnings.warn(
"Int8 PTQ Calibrator has been deprecated by TensorRT, please plan on porting to a NVIDIA Model Optimizer Toolkit based workflow. See: https://pytorch.org/TensorRT/tutorials/_rendered_examples/dynamo/vgg16_ptq.html for more details",
DeprecationWarning,
stacklevel=2
)
cache_file = args[0]
algo_type = kwargs.get("algo_type", CalibrationAlgo.ENTROPY_CALIBRATION_2)

Expand Down

0 comments on commit d707352

Please sign in to comment.