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

feat: Wrap dynamic size handling in a compilation flag #1851

Merged
merged 2 commits into from
May 15, 2023
Merged

Conversation

peri044
Copy link
Collaborator

@peri044 peri044 commented Apr 21, 2023

Description

This PR does the following

  1. The aten::size dynamic shape handling is now disabled by default. allow_shape_tensors=True will enable it.

  2. Modifications to aten::size include preserving the static dimensions in the input, thereby not converting any known types eg: Int into ITensors

Type of change

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

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

@peri044 peri044 requested a review from narendasan April 21, 2023 19:57
@github-actions github-actions bot added component: api [Python] Issues re: Python API component: api [C++] Issues re: C++ API component: conversion Issues re: Conversion stage component: core Issues re: The core compiler component: evaluators Issues re: Specific op evaluators component: tests Issues re: Tests labels Apr 21, 2023
github-actions[bot]

This comment was marked as resolved.

github-actions[bot]

This comment was marked as resolved.

github-actions[bot]

This comment was marked as resolved.

github-actions[bot]

This comment was marked as resolved.

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.

Code conforms to C++ 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.

Code conforms to Python 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.

Code conforms to Python 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.

Code conforms to C++ style guidelines

@Christina-Young-NVIDIA Christina-Young-NVIDIA added the release: v1.4 Tagged to be included in v1.4 label Apr 24, 2023
@github-actions github-actions bot requested a review from bowang007 April 24, 2023 20:28
Copy link
Collaborator

@bowang007 bowang007 left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -40,6 +40,8 @@ auto prim_registrations =
// Outputs is an IValue which has list of tensors which can be found in ctx->evaluated_value_map
const torch::jit::IValue* outputs = args.at(n->input()).IValue();
auto outputVec = outputs->toList().vec();
LOG_DEBUG("==== OUTPUT VEC: " << outputVec);
TORCHTRT_THROW_ERROR("========= FORCED ERROR ");
Copy link
Collaborator

Choose a reason for hiding this comment

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

These 2 lines need to be removed

@@ -40,6 +40,8 @@ auto prim_registrations =
// Outputs is an IValue which has list of tensors which can be found in ctx->evaluated_value_map
const torch::jit::IValue* outputs = args.at(n->input()).IValue();
auto outputVec = outputs->toList().vec();
LOG_DEBUG("==== OUTPUT VEC: " << outputVec);
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove this line

…en::size

Signed-off-by: Dheeraj Peri <[email protected]>

chore: Add allow-shape-tensors option to torchtrtc, preserve static dimensions in the aten::size layer

Signed-off-by: Dheeraj Peri <[email protected]>

chore: Linter fixes

Signed-off-by: Dheeraj Peri <[email protected]>

chore: remove debug throw error

Signed-off-by: Dheeraj Peri <[email protected]>
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.

Code conforms to Python 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.

Code conforms to C++ style guidelines

if (ctx->settings.allow_shape_tensors) {
return dynamic_size_layer(ctx, n, args);
} else {
LOG_WARNING("There may be undefined behavior using dynamic shape and aten::size ");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this undefined behavior due to using aten::size with dynamic shape without shape tensors or the other way around. Might need rewording

@@ -270,7 +270,11 @@ auto aten_registrations TORCHTRT_UNUSED =
if (tensor_var.isITensor()) {
auto tensor = tensor_var.ITensor();
if (ctx->input_is_dynamic) {
return dynamic_size_layer(ctx, n, args);
if (ctx->settings.allow_shape_tensors) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should be checking if input is dynamic, shape tensors are enabled and the input contains a placeholder dimension before using the shape tensor code path. Otherwise static aten size is sufficient and will cause less errors

@@ -286,7 +290,11 @@ auto aten_registrations TORCHTRT_UNUSED =
auto dim = args.at(n->input(1)).unwrapToInt();
if (tensor_var.isITensor()) {
if (ctx->input_is_dynamic) {
return dynamic_size_layer(ctx, n, args);
if (ctx->settings.allow_shape_tensors) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comments here from above about conditions and warnings

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.

Code conforms to Python 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.

Code conforms to C++ style guidelines

@bowang007 bowang007 merged commit fcb6890 into main May 15, 2023
bowang007 added a commit that referenced this pull request May 15, 2023
feat: Wrap dynamic size handling in a compilation flag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla signed component: api [C++] Issues re: C++ API component: api [Python] Issues re: Python API component: conversion Issues re: Conversion stage component: core Issues re: The core compiler component: evaluators Issues re: Specific op evaluators component: tests Issues re: Tests release: v1.4 Tagged to be included in v1.4
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants