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

scatter_add_decomposition #2740

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

scatter_add_decomposition #2740

wants to merge 3 commits into from

Conversation

apbose
Copy link
Collaborator

@apbose apbose commented Apr 9, 2024

No description provided.

@apbose apbose self-assigned this Apr 9, 2024
@apbose apbose marked this pull request as draft April 9, 2024 21:12
@github-actions github-actions bot added component: tests Issues re: Tests component: lowering Issues re: The lowering / preprocessing passes component: api [Python] Issues re: Python API component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths labels Apr 9, 2024
@github-actions github-actions bot requested a review from peri044 April 9, 2024 21:12
@apbose apbose mentioned this pull request Apr 9, 2024
@apbose apbose removed the request for review from peri044 April 9, 2024 21:13
@apbose apbose force-pushed the scatter_add_decomposition branch from a49c420 to e8c7b50 Compare May 14, 2024 20:58
@apbose apbose marked this pull request as ready for review May 14, 2024 21:04
@apbose apbose requested a review from gs-olive May 14, 2024 21:04
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 Python style guidelines:

--- /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/lowering/_decompositions.py	2024-05-14 21:04:24.249027+00:00
+++ /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/lowering/_decompositions.py	2024-05-14 21:06:14.833958+00:00
@@ -181,13 +181,16 @@
    input_tensor: torch.Tensor,
    src_tensor: torch.Tensor,
    dim: int,
    index: torch.Tensor,
) -> torch.Tensor:
-    input_tensor_to_add = torch.scatter(torch.empty_like(input_tensor), dim, index, src_tensor)
+    input_tensor_to_add = torch.scatter(
+        torch.empty_like(input_tensor), dim, index, src_tensor
+    )
    scatter_add_tensor = torch.add(input_tensor, input_tensor_to_add.cuda())
    return scatter_add_tensor
+

def get_decompositions(
    enable_experimental_decompositions: bool = False,
) -> Dict[OpOverload, Callable[[Any], Any]]:
    if enable_experimental_decompositions:

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 Python style guidelines:

--- /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/lowering/_decompositions.py	2024-05-14 21:04:33.408462+00:00
+++ /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/lowering/_decompositions.py	2024-05-14 21:06:24.734368+00:00
@@ -181,13 +181,16 @@
    input_tensor: torch.Tensor,
    src_tensor: torch.Tensor,
    dim: int,
    index: torch.Tensor,
) -> torch.Tensor:
-    input_tensor_to_add = torch.scatter(torch.empty_like(input_tensor), dim, index, src_tensor)
+    input_tensor_to_add = torch.scatter(
+        torch.empty_like(input_tensor), dim, index, src_tensor
+    )
    scatter_add_tensor = torch.add(input_tensor, input_tensor_to_add.cuda())
    return scatter_add_tensor
+

def get_decompositions(
    enable_experimental_decompositions: bool = False,
) -> Dict[OpOverload, Callable[[Any], Any]]:
    if enable_experimental_decompositions:

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 Python style guidelines:

--- /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/lowering/_decompositions.py	2024-05-14 21:01:28.751182+00:00
+++ /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/lowering/_decompositions.py	2024-05-14 21:09:51.626381+00:00
@@ -181,13 +181,16 @@
    input_tensor: torch.Tensor,
    src_tensor: torch.Tensor,
    dim: int,
    index: torch.Tensor,
) -> torch.Tensor:
-    input_tensor_to_add = torch.scatter(torch.empty_like(input_tensor), dim, index, src_tensor)
+    input_tensor_to_add = torch.scatter(
+        torch.empty_like(input_tensor), dim, index, src_tensor
+    )
    scatter_add_tensor = torch.add(input_tensor, input_tensor_to_add.cuda())
    return scatter_add_tensor
+

def get_decompositions(
    enable_experimental_decompositions: bool = False,
) -> Dict[OpOverload, Callable[[Any], Any]]:
    if enable_experimental_decompositions:

dim: int,
index: torch.Tensor,
) -> torch.Tensor:
input_tensor_to_add = torch.scatter(torch.empty_like(input_tensor), dim, index, src_tensor)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could torch.empty_like(input_tensor) instead be just input_tensor, or is it required to be empty?

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 it would be required. The logic is like we would apply scatter with the indices to an empty tensor and then add it to the input tensor.

index: torch.Tensor,
) -> torch.Tensor:
input_tensor_to_add = torch.scatter(torch.empty_like(input_tensor), dim, index, src_tensor)
scatter_add_tensor = torch.add(input_tensor, input_tensor_to_add.cuda())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Without .cuda() does the decomposition fail?

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 in this case it complains that the two tensors are on different devices.

@apbose
Copy link
Collaborator Author

apbose commented May 16, 2024

@gs-olive though the test cases pass, I don't think that the decomposition is taking place.
It fails in the backend at aot_export_joint_simple. Shows me something like

CRITICAL:torch_tensorrt.dynamo.backend.backends:Halting compilation on build failure since pass_through_build_failures was specified as True. To
return the default Torch implementation and avoid halting compilation on engine build failures, specify pass_through_build_failures=False.
W0516 15:51:10.818862 139669023303488 torch/_dynamo/exc.py:201] [0/0] Backend compiler failed with a fake tensor exception at
W0516 15:51:10.818862 139669023303488 torch/_dynamo/exc.py:201] [0/0]   File "<eval_with_key>.5 from /home/abose/Documents/work/torchTRT_TRT10_scatter_5_2/TensorRT/tests/py/dynamo/lowering/test_decompositions.py:523 in forward", line 9, in forward
W0516 15:51:10.818862 139669023303488 torch/_dynamo/exc.py:201] [0/0]     return scatter_add_default
W0516 15:51:10.818862 139669023303488 torch/_dynamo/exc.py:201] [0/0] Adding a graph break.

Is this due to torch.unique?

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: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: lowering Issues re: The lowering / preprocessing passes component: tests Issues re: Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants