8000 Support broadcast index put by chohk88 · Pull Request #3421 · pytorch/TensorRT · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Support broadcast index put #3421

8000 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
merged 3 commits into from
Mar 14, 2025
Merged

Support broadcast index put #3421

merged 3 commits into from
Mar 14, 2025

Conversation

chohk88
Copy link
Collaborator
@chohk88 chohk88 commented Feb 27, 2025

Description

  • I modified it to support all cases, including when broadcasting is required for value and when indices contain None, and removed the validator.

The following code tests whether index_put causes an engine break in Paligemma.

import torch
import torch_tensorrt
import torch.nn as nn

class ExplicitIndexPutModule(nn.Module):
    def forward(self, x: torch.Tensor) -> torch.Tensor:
        cache_position = 2
        idx = torch.tensor(cache_position, device=x.device, dtype=torch.int32)
        indices = [None, None, idx]
        key_states = torch.tensor([[[10., 20., 30.],
                                     [40., 50., 60.]]],
                                    dtype=x.dtype, device=x.device)
        out = torch.ops.aten.index_put.default(x, indices, key_states)
        return out
        # x[:,:,idx] = key_states
        # return x
if __name__ == "__main__":
    model = ExplicitIndexPutModule().eval().cuda().half()

    inp = torch.zeros((1, 2, 5, 3), device="cuda", dtype=torch.half)
    out = model(inp)
    
    compiled_model = torch.compile(
        model,
        backend="tensorrt",
        dynamic=None,
        options={
            "enabled_precisions": {torch.float16},
            "disable_tf32": True,
            "min_block_size": 1,
            "debug": True,
        },
    )
    compiled_out = compiled_model(inp)

    torch.testing.assert_close(compiled_out, out, rtol=1e-3, atol=1e-3)
    
    print("result shape:", out.shape)
    print("result tensor:", out)

Fixes # ([issue](https://github.com/pytorch/TensorRT/issues/3432))

## Type of change

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

- New feature (non-breaking change which adds functionality)

# Checklist:

- [x] My code follows the style guidelines of this project (You can use the linters)
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas and hacks
- [ ] I have made corresponding changes to the documentation
- [x] I have added tests to verify my fix or my feature
- [x] New and existing unit tests pass locally with my changes
- [x] I have added the relevant labels to my PR in so that relevant reviewers are notified

@chohk88 chohk88 self-assigned this Feb 27, 2025
@github-actions github-actions bot added component: tests Issues re: Tests component: conversion Issues re: Conversion stage component: converters Issues re: Specific op converters component: api [Python] Issues re: Python API component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths labels Feb 27, 2025
@github-actions github-actions bot requested a review from narendasan February 27, 2025 21:13
github-actions[bot]

This comment was marked as resolved.

@chohk88 chohk88 force-pushed the support_broadcast_index_put branch from 80bef6e to 175f191 Compare February 28, 2025 01:35
github-actions[bot]

This comment was marked as resolved.

@chohk88 chohk88 marked this pull request as draft February 28, 2025 05:45
@chohk88 chohk88 requested review from narendasan and peri044 March 11, 2025 12:39
@chohk88 chohk88 marked this pull request as ready for review March 11, 2025 12:41
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 1f8a158 into main Mar 14, 2025
74 checks passed
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.

🐛 [Bug] Unsupported ops : torch.ops.aten.index_put.default - validator: False
4 participants
0