Skip to content

Cherrypick #3424 for release/2.7 #3484

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

Open
wants to merge 2 commits into
base: release/2.7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build-test-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ jobs:
python -m pytest -ra --junitxml=${RUNNER_TEST_RESULTS_DIR}/dynamo_converters_test_results.xml -n 4 conversion/
python -m pytest -ra --junitxml=${RUNNER_TEST_RESULTS_DIR}/dynamo_converters_test_results.xml automatic_plugin/test_automatic_plugin.py
python -m pytest -ra --junitxml=${RUNNER_TEST_RESULTS_DIR}/dynamo_converters_test_results.xml automatic_plugin/test_automatic_plugin_with_attrs.py
python -m pytest -ra --junitxml=${RUNNER_TEST_RESULTS_DIR}/dynamo_converters_test_results.xml automatic_plugin/test_flashinfer_rmsnorm.py
popd

tests-py-dynamo-fe:
Expand Down
9 changes: 0 additions & 9 deletions tests/py/dynamo/automatic_plugin/test_automatic_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,3 @@ def forward(self, lhs, rhs):

if __name__ == "__main__":
run_tests()

# Example Usage
# A = torch.full((64, 64), 2, device="cuda", dtype=torch.float)
# B = torch.full((64, 64), 3, device="cuda", dtype=torch.float)

# C, D = torch.ops.torchtrt_ex.elementwise_add_mul.default(A, B)

# print("C (Addition):", C)
# print("D (Multiplication):", D)
52 changes: 52 additions & 0 deletions tests/py/dynamo/automatic_plugin/test_flashinfer_rmsnorm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import pytest

flashinfer = pytest.importorskip("flashinfer")
import torch
import torch.nn as nn
import torch_tensorrt
from parameterized import parameterized
from torch.testing._internal.common_utils import run_tests
from torch_tensorrt._enums import dtype

from ..conversion.harness import DispatchTestCase


@torch.library.custom_op("flashinfer::rmsnorm", mutates_args=()) # type: ignore[misc]
def flashinfer_rmsnorm(
input: torch.Tensor, weight: torch.Tensor, eps: float = 1e-6
) -> torch.Tensor:
return flashinfer.norm.rmsnorm(input, weight)


@torch.library.register_fake("flashinfer::rmsnorm")
def _(input: torch.Tensor, weight: torch.Tensor, b: float = 1e-6) -> torch.Tensor:
return input


torch_tensorrt.dynamo.conversion.plugins.custom_op(
"flashinfer::rmsnorm", supports_dynamic_shapes=True
)


class TestAutomaticPlugin(DispatchTestCase):
@parameterized.expand(
[
((64, 64), (64,), torch.float16),
((256, 256), (256,), torch.float16),
]
)
def test_rmsnorm_float(self, input_shape, weight_shape, data_type):
class rmsnorm(nn.Module):
def forward(self, input, weight):
return torch.ops.flashinfer.rmsnorm.default(input, weight)

inputs = [
torch.randn(input_shape, device="cuda", dtype=data_type),
torch.randn(weight_shape, device="cuda", dtype=data_type),
]

self.run_test(rmsnorm(), inputs, precision=dtype.f16)


if __name__ == "__main__":
run_tests()
4 changes: 2 additions & 2 deletions tests/py/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ pytest>=8.2.1
pytest-xdist>=3.6.1
pyyaml
timm>=1.0.3
transformers==4.40.2
nvidia-modelopt[deploy,hf,torch]~=0.17.0
transformers==4.49.0
nvidia-modelopt[deploy,hf,torch]~=0.17.0; python_version < "3.13"
--extra-index-url https://pypi.nvidia.com
Loading