Skip to content

[feat] add support for aten::reciprocal(int) #1308

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

Conversation

mfeliz-cruise
Copy link
Contributor

Description

The unary layer does not support integer inputs to RECIP. Pytorch implicitly casts integer inputs to float for aten::reciprocal so we can add the same cast here to add support.

Fixes # (issue)

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

@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 Aug 25, 2022
auto reciprocal_registration TORCHTRT_UNUSED = RegisterNodeConversionPatterns().pattern(
{"aten::reciprocal(Tensor self) -> Tensor", [](ConversionCtx* ctx, const torch::jit::Node* n, args& args) -> bool {
auto in = args[0].ITensorOrFreeze(ctx);
if (in->getType() == nvinfer1::DataType::kINT32) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This might be a large change but would it make sense to just add this to the macro for other unary ops? @peri044 thoughts on what the repercussions would be?

Copy link
Contributor Author

@mfeliz-cruise mfeliz-cruise Aug 25, 2022

Choose a reason for hiding this comment

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

In this case the behavior matches pytorch. For other ops (ex. abs implemented element-wise above) this behavior would be incorrect. I have not checked any of the other ops.

Copy link
Collaborator

Choose a reason for hiding this comment

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

There are two ops which have some restrictions according to the doc but other unary ops must have floating point inputs. https://docs.nvidia.com/deeplearning/tensorrt/api/c_api/classnvinfer1_1_1_i_network_definition.html#a77831224c9a72ad02587a56ded93c672

Generally the input must have a floating-point type (or kINT8 as a quantized float), except for the following operations:
kSIGN accepts a floating-point or Int32 tensor.
kNOT requires a Bool tensor.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We could add the above restrictions in the code in addition to what Michael added, to cover the cases in the doc completely.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was mostly talking from the pytorch perspective since seems like theres at least a few ops where int inputs are valid

@narendasan narendasan merged commit 096fd41 into pytorch:master Sep 8, 2022
narendasan added a commit that referenced this pull request Sep 9, 2022
* chore: additional options for perf_run tool

Signed-off-by: dperi <[email protected]>

* feat: Add fx2trt backend and revamp current perf utility to accept CLI arguments

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

* chore: Refactor fx2trt functionality

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

* chore: Fix fp16 functionality for fx2trt backend

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

* chore: refactor

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

* chore: minor change

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

* refactor: Refactor perf_run and add internal benchmark scripts

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

* chore : minor refactor

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

* chore: Apply precommit tooling

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

* chore: Fix data loader issues and nox file paths

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

* chore: rebase and minor changes

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

* chore: Fix reporting to a file setting

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

* Update lower.py (#1324)

* docs: [Automated] Regenerating documenation for e374eb1

Signed-off-by: Torch-TensorRT Github Bot <[email protected]>

* refactor: Refactor testing to use cosine similarity, remove redundancy models and restructuring

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

* chore: move to cosine similarity comparison

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

* refactor: Refactor nox file testing

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

* chore: add missing scripts

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

* chore: Linter fixes

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

* fix!: Fixed Windows compilation failures

Signed-off-by: Anurag Dixit <[email protected]>

* chore: Minor fix

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

* chore: use rn18 instead of rn50

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

* docs: [Automated] Regenerating documenation for a1a4786

Signed-off-by: Torch-TensorRT Github Bot <[email protected]>

* chore: Add cpp tests with cosine sim

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

* chore: linter fixes

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

* [feat] Add support for argmax and argmin (#1312)

* [feat] Add support for argmax and argmin

Adds support for aten::argmax and aten::argmin.

Fixes # (issue)

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

- [ ] 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

* move max.cpp tests to test_max.cpp no functional change

* fix permissions on max.cpp

* docs: [Automated] Regenerating documenation for 9db2852

Signed-off-by: Torch-TensorRT Github Bot <[email protected]>

* chore: Deepcopy other objects

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

* fix: Fix deepcopy issues of PTQ calibrators

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

* chore: linter fixes

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

* chore: Adding a guideline to build on Windows platform (#1337)

* chore: Adding Windows build guideline

Signed-off-by: Anurag Dixit <[email protected]>

* chore: Fix formatting

Signed-off-by: Anurag Dixit <[email protected]>

Signed-off-by: Anurag Dixit <[email protected]>

* docs: [Automated] Regenerating documenation for 00a1f03

Signed-off-by: Torch-TensorRT Github Bot <[email protected]>

* chore: minor fixes

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

* chore: Linter fixes

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

* chore: Linter fixes

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

* docs: [Automated] Regenerating documenation for 1efe4b1

Signed-off-by: Torch-TensorRT Github Bot <[email protected]>

* docs: [Automated] Regenerating documenation for 10b9ecd

Signed-off-by: Torch-TensorRT Github Bot <[email protected]>

* add support for aten::reciprocal(int) (#1308)

* docs: [Automated] Regenerating documenation for 096fd41

Signed-off-by: Torch-TensorRT Github Bot <[email protected]>

Signed-off-by: dperi <[email protected]>
Signed-off-by: Dheeraj Peri <[email protected]>
Signed-off-by: Torch-TensorRT Github Bot <[email protected]>
Signed-off-by: Anurag Dixit <[email protected]>
Co-authored-by: dperi <[email protected]>
Co-authored-by: Dheeraj Peri <[email protected]>
Co-authored-by: Wei <[email protected]>
Co-authored-by: Torch-TensorRT Github Bot <[email protected]>
Co-authored-by: Anurag Dixit <[email protected]>
Co-authored-by: Michael Feliz <[email protected]>
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.

4 participants