Skip to content

Conversation

narendasan
Copy link
Collaborator

Signed-off-by: Naren Dasan naren@narendasan.com
Signed-off-by: Naren Dasan narens@nvidia.com

Description

Adds support for int64 as a native type in TensorRT

Fixes # (issue)

Type of change

Please delete options that are not relevant and/or add your own.

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the style guidelines of this project (You can use the linters)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas and hacks
  • I have made corresponding changes to the documentation
  • I have added tests to verify my fix or my feature
  • New and existing unit tests pass locally with my changes
  • I have added the relevant labels to my PR in so that relevant reviewers are notified

@github-actions github-actions bot added component: tests Issues re: Tests component: conversion Issues re: Conversion stage component: core Issues re: The core compiler component: api [Python] Issues re: Python API component: runtime component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths labels Apr 27, 2024
@github-actions github-actions bot requested a review from bowang007 April 27, 2024 01:14
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some changes that do not conform to C++ style guidelines:

diff --git a/home/runner/work/TensorRT/TensorRT/core/util/trt_util.cpp b/tmp/changes.txt
index 503b88e..3ca5780 100644
--- a/home/runner/work/TensorRT/TensorRT/core/util/trt_util.cpp
+++ b/tmp/changes.txt
@@ -164,8 +164,8 @@ nvinfer1::Dims unsqueezeDims(const nvinfer1::Dims& d, int pos, int val, bool use
  // Acceptable range for pos is [-d.nbDims - 1, d.nbDims]
  TORCHTRT_ASSERT(
      pos >= (-d.nbDims - 1) && pos <= d.nbDims,
-      "ERROR: Index to unsqueeze is out of bounds. " << "Expected value in range [" << (-d.nbDims - 1) << ", "
-                                                     << d.nbDims << "], but got " << pos);
+      "ERROR: Index to unsqueeze is out of bounds. "
+          << "Expected value in range [" << (-d.nbDims - 1) << ", " << d.nbDims << "], but got " << pos);

  // Unsqueeze with negative dimensions creates a new dimension at that index
  pos = (pos < 0) ? (pos + d.nbDims + 1) : pos;
ERROR: Some files do not conform to style guidelines

@narendasan narendasan requested review from peri044 and gs-olive and removed request for bowang007 April 27, 2024 01:18
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some changes that do not conform to C++ style guidelines:

diff --git a/home/runner/work/TensorRT/TensorRT/core/util/trt_util.cpp b/tmp/changes.txt
index 503b88e..3ca5780 100644
--- a/home/runner/work/TensorRT/TensorRT/core/util/trt_util.cpp
+++ b/tmp/changes.txt
@@ -164,8 +164,8 @@ nvinfer1::Dims unsqueezeDims(const nvinfer1::Dims& d, int pos, int val, bool use
  // Acceptable range for pos is [-d.nbDims - 1, d.nbDims]
  TORCHTRT_ASSERT(
      pos >= (-d.nbDims - 1) && pos <= d.nbDims,
-      "ERROR: Index to unsqueeze is out of bounds. " << "Expected value in range [" << (-d.nbDims - 1) << ", "
-                                                     << d.nbDims << "], but got " << pos);
+      "ERROR: Index to unsqueeze is out of bounds. "
+          << "Expected value in range [" << (-d.nbDims - 1) << ", " << d.nbDims << "], but got " << pos);

  // Unsqueeze with negative dimensions creates a new dimension at that index
  pos = (pos < 0) ? (pos + d.nbDims + 1) : pos;
ERROR: Some files do not conform to style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some changes that do not conform to C++ style guidelines:

diff --git a/home/runner/work/TensorRT/TensorRT/core/util/trt_util.cpp b/tmp/changes.txt
index 503b88e..3ca5780 100644
--- a/home/runner/work/TensorRT/TensorRT/core/util/trt_util.cpp
+++ b/tmp/changes.txt
@@ -164,8 +164,8 @@ nvinfer1::Dims unsqueezeDims(const nvinfer1::Dims& d, int pos, int val, bool use
  // Acceptable range for pos is [-d.nbDims - 1, d.nbDims]
  TORCHTRT_ASSERT(
      pos >= (-d.nbDims - 1) && pos <= d.nbDims,
-      "ERROR: Index to unsqueeze is out of bounds. " << "Expected value in range [" << (-d.nbDims - 1) << ", "
-                                                     << d.nbDims << "], but got " << pos);
+      "ERROR: Index to unsqueeze is out of bounds. "
+          << "Expected value in range [" << (-d.nbDims - 1) << ", " << d.nbDims << "], but got " << pos);

  // Unsqueeze with negative dimensions creates a new dimension at that index
  pos = (pos < 0) ? (pos + d.nbDims + 1) : pos;
ERROR: Some files do not conform to style guidelines

Copy link
Collaborator

@gs-olive gs-olive left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good! May need modification to this file as well:

if (
isinstance(input_val, torch.Tensor)
and ctx.compilation_settings.truncate_long_and_double
):
if input_val.dtype == torch.int64:
input_val = input_val.to(torch.int32)
elif input_val.dtype == torch.float64:
input_val = input_val.to(torch.float32)
elif (
isinstance(input_val, np.ndarray)
and ctx.compilation_settings.truncate_long_and_double
):
if input_val.dtype == np.int64:
input_val = input_val.astype(np.int32)
elif input_val.dtype == np.float64:
input_val = input_val.astype(np.float32)

@github-actions github-actions bot added the component: converters Issues re: Specific op converters label Apr 29, 2024
github-actions[bot]

This comment was marked as outdated.

github-actions[bot]

This comment was marked as outdated.

@narendasan narendasan force-pushed the native_i64_support branch 3 times, most recently from 7b6bdcd to ff2f9ae Compare April 30, 2024 02:03
Copy link
Collaborator

@peri044 peri044 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Minor changes

@narendasan narendasan force-pushed the native_i64_support branch 2 times, most recently from 9e839df to 2d0fa75 Compare April 30, 2024 21:04
Copy link
Collaborator

@gs-olive gs-olive left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

Comment on lines +149 to +153
warnings.warn(
'Compiler option "truncate_long_and_double" is deprecated in favor of "truncate_double" as int64 is now natively supported, this option will be removed in the next version',
DeprecationWarning,
stacklevel=2,
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for not using logger here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is apparently the recommended way to handle deprecation warnings, iirc I configured the logger to pull these messages in in an earlier PR

Signed-off-by: Naren Dasan <naren@narendasan.com>
Signed-off-by: Naren Dasan <narens@nvidia.com>
`truncate_long_and_double` has been deprecated in favor of
`truncate_double` as int64 is natively supported

Signed-off-by: Naren Dasan <naren@narendasan.com>
Signed-off-by: Naren Dasan <narens@nvidia.com>
all layers

Signed-off-by: Naren Dasan <naren@narendasan.com>
Signed-off-by: Naren Dasan <narens@nvidia.com>
@gs-olive
Copy link
Collaborator

  • Verified functional compilation on Stable Diffusion example

@narendasan narendasan merged commit 717e11b into main Apr 30, 2024
@narendasan narendasan deleted the native_i64_support branch April 30, 2024 22:57
narendasan added a commit that referenced this pull request Apr 30, 2024
Signed-off-by: Naren Dasan <naren@narendasan.com>
Signed-off-by: Naren Dasan <narens@nvidia.com>
narendasan added a commit that referenced this pull request May 1, 2024
Signed-off-by: Naren Dasan <naren@narendasan.com>
Signed-off-by: Naren Dasan <narens@nvidia.com>
laikhtewari pushed a commit that referenced this pull request May 24, 2024
Signed-off-by: Naren Dasan <naren@narendasan.com>
Signed-off-by: Naren Dasan <narens@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla signed component: api [Python] Issues re: Python API component: conversion Issues re: Conversion stage component: converters Issues re: Specific op converters component: core Issues re: The core compiler component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: runtime component: tests Issues re: Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants