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: Added support for aten::unflatten converter #2097

Merged
merged 5 commits into from
Aug 2, 2023

Conversation

andi4191
Copy link
Contributor

@andi4191 andi4191 commented Jul 10, 2023

Description

Added a converter support for aten::unflatten.

Created a separate PR for #1808
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

Anurag Dixit added 2 commits July 10, 2023 13:36
Signed-off-by: Anurag Dixit <anurag.dixit@getcruise.com>
Signed-off-by: Anurag Dixit <anurag.dixit@getcruise.com>
@github-actions github-actions bot added component: conversion Issues re: Conversion stage component: converters Issues re: Specific op converters component: core Issues re: The core compiler component: tests Issues re: Tests labels Jul 10, 2023
@github-actions github-actions bot requested a review from peri044 July 10, 2023 23:45
@andi4191
Copy link
Contributor Author

@peri044 : Following commands have no impact on the linting of my code changes:

bazel run //tools/linter:cpplint
bazel run //tools/linter:pylint

I don't see buildifier triggering auto lint with commits. Can you please share the instructions for the same?

Signed-off-by: Anurag Dixit <anurag.dixit@getcruise.com>
Signed-off-by: Anurag Dixit <anurag.dixit@getcruise.com>
Comment on lines 127 to 183

TEST(Converters, ATenUnflattenDynShapeShapeCorrectly) {
const auto graph = R"IR(
graph(%x.1 : Tensor):
%2 : int = prim::Constant[value=1]()
%3 : int = prim::Constant[value=512]()
%4 : int = prim::Constant[value=1]()
%5 : int = prim::Constant[value=1]()
%6 : int[] = prim::ListConstruct(%3, %4, %5)
%7 : Tensor = aten::unflatten(%x.1, %2, %6)
return (%7))IR";

auto g = std::make_shared<torch::jit::Graph>();

torch::jit::parseIR(graph, g.get());

auto in = at::randint(0, 10, {1, 512}, {at::kCUDA});

auto jit_in = at::clone(in);
auto params = torch_tensorrt::core::ir::get_static_params(g->inputs(), {});
auto jit_results = torch_tensorrt::tests::util::RunGraph(g, params, {jit_in});

auto trt_in = at::clone(in);
params = torch_tensorrt::core::ir::get_static_params(g->inputs(), {});
auto trt_results = torch_tensorrt::tests::util::RunGraphEngineDynamic(g, params, {in}, true);

ASSERT_TRUE(torch_tensorrt::tests::util::almostEqual(jit_results[0], trt_results[0], 2e-6));
}

TEST(Converters, ATenUnflattenDynShapeNegativeDimsShapeCorrectly) {
const auto graph = R"IR(
graph(%x.1 : Tensor):
%2 : int = prim::Constant[value=-2]()
%3 : int = prim::Constant[value=512]()
%4 : int = prim::Constant[value=1]()
%5 : int = prim::Constant[value=1]()
%6 : int[] = prim::ListConstruct(%3, %4, %5)
%7 : Tensor = aten::unflatten(%x.1, %2, %6)
return (%7))IR";

auto g = std::make_shared<torch::jit::Graph>();

torch::jit::parseIR(graph, g.get());

auto in = at::randint(0, 10, {1, 512, 2}, {at::kCUDA});

auto jit_in = at::clone(in);
auto params = torch_tensorrt::core::ir::get_static_params(g->inputs(), {});
auto jit_results = torch_tensorrt::tests::util::RunGraph(g, params, {jit_in});

auto trt_in = at::clone(in);
params = torch_tensorrt::core::ir::get_static_params(g->inputs(), {});
auto trt_results = torch_tensorrt::tests::util::RunGraphEngineDynamic(g, params, {in}, true);

ASSERT_TRUE(torch_tensorrt::tests::util::almostEqual(jit_results[0], trt_results[0], 2e-6));
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you move these to test_shuffle.cpp since these are not ITensor based (aten::size + dyn_shapes) ? The aten::size + aten::unflatten.cpp tests can be left in this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed redundant test cases. Mentioned test case variants are already present in test_shuffle.

@peri044
Copy link
Collaborator

peri044 commented Jul 11, 2023

@peri044 : Following commands have no impact on the linting of my code changes:

bazel run //tools/linter:cpplint bazel run //tools/linter:pylint

I don't see buildifier triggering auto lint with commits. Can you please share the instructions for the same?

We use pre-commit linting now. Here's a reference : https://github.com/pytorch/TensorRT/blob/main/CONTRIBUTING.md#commits-and-prs
We can lint files now by running pre-commit run --all-files before committing the code

Signed-off-by: Anurag Dixit <anurag.dixit@getcruise.com>
@andi4191 andi4191 requested a review from peri044 July 12, 2023 21:02
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

@peri044 peri044 merged commit 3c49608 into pytorch:main Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla signed component: conversion Issues re: Conversion stage component: converters Issues re: Specific op converters component: core Issues re: The core compiler component: tests Issues re: Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants