Skip to content

Conversation

@zewenli98
Copy link
Collaborator

Description

Support aten.roll dynamo converter.

Fixes #2567

Type of change

  • 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: api [Python] Issues re: Python API component: conversion Issues re: Conversion stage component: converters Issues re: Specific op converters component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: tests Issues re: Tests labels Jan 2, 2024
@github-actions github-actions bot requested a review from peri044 January 2, 2024 08:55
@zewenli98 zewenli98 self-assigned this Jan 3, 2024
@zewenli98 zewenli98 force-pushed the roll_dynamo_converter branch from 5bc8314 to 5be128d Compare January 14, 2024 16:28
@zewenli98 zewenli98 force-pushed the roll_dynamo_converter branch from 5be128d to d58f865 Compare January 17, 2024 05:50
from .harness import DispatchTestCase


class TestRollConverter(DispatchTestCase):
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding a case where both shifts and dims are single integers, which is a supported case in the docstring. These may be casted to lists in the operator before the converter ever gets them, but it is still a valid input I believe.

Copy link
Collaborator Author

@zewenli98 zewenli98 Jan 19, 2024

Choose a reason for hiding this comment

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

Thanks for your review! I found the schema is:

- func: roll(Tensor self, SymInt[1] shifts, int[1] dims=[]) -> Tensor

Does this mean shifts and dims should be a 1d list?

Copy link
Contributor

Choose a reason for hiding this comment

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

roll(tensor, 2, 3) --> roll(tensor, [2], [3])
pool(3) --> pool([3, 3])
To share additional documentation

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@gs-olive Thanks for the details!
Unfortunately, when testing shifts=2, dims=0, I got error:

File "<eval_with_key>.0 from /home/zewenl/TensorRT/tests/py/dynamo/conversion/test_roll_aten.py:35 in forward", line 5, in forward
    roll_default = torch.ops.aten.roll.default(x, 2, 0);  x = None
  File "/home/zewenl/.local/lib/python3.10/site-packages/torch/_ops.py", line 571, in __call__
    return self_._op(*args, **(kwargs or {}))
RuntimeError: aten::roll() Expected a value of type 'List[int]' for argument 'shifts' but instead found type 'int'.
Position: 1
Value: 2
Declaration: aten::roll(Tensor self, SymInt[1] shifts, int[1] dims=[]) -> Tensor
 Python error details: TypeError: 'int' object is not iterable

Then, I also tested shifts=(2,), dims=0, it works.

It seems that pytorch requires shifts to be a list.

According to the schema - func: roll(Tensor self, SymInt[1] shifts, int[1] dims=[]) -> Tensor, I guess SymInt[1] and int[1] may have different behaviors?

Copy link
Contributor

Choose a reason for hiding this comment

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

It might be so, yes, though that is strange - thanks for the update.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I'm working on adaptive_avg_pool2d(Tensor self, SymInt[2] output_size) -> Tensor converter, output_size expects List[int] as well:

RuntimeError: aten::adaptive_avg_pool2d() Expected a value of type 'List[int]' for argument 'output_size' but instead found type 'int'.
Position: 1
Value: 3
Declaration: aten::adaptive_avg_pool2d(Tensor self, SymInt[2] output_size) -> Tensor

@zewenli98 zewenli98 force-pushed the roll_dynamo_converter branch from d58f865 to 6e19c81 Compare January 20, 2024 07:06
@zewenli98 zewenli98 requested a review from gs-olive January 23, 2024 14:12
@zewenli98 zewenli98 force-pushed the roll_dynamo_converter branch from 6e19c81 to a10ac64 Compare January 23, 2024 14:33
@zewenli98 zewenli98 merged commit 3390e24 into pytorch:main Feb 2, 2024
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: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: tests Issues re: Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

aten.roll

3 participants