-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
122 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import pytest | ||
import torch | ||
from torch import nn | ||
from torch2trt_dynamic import module2trt | ||
|
||
|
||
class _TestModel(nn.Module): | ||
|
||
def __init__(self, num, dim) -> None: | ||
super().__init__() | ||
self.embeding = nn.Embedding(num, dim) | ||
|
||
def forward(self, input): | ||
return self.embeding(input) | ||
|
||
|
||
class TestGather: | ||
|
||
@pytest.fixture | ||
def dim(self): | ||
yield 4 | ||
|
||
@pytest.fixture | ||
def num(self): | ||
yield 10 | ||
|
||
@pytest.fixture | ||
def batch(self): | ||
yield 2 | ||
|
||
@pytest.fixture | ||
def input(self, batch, num): | ||
yield torch.randint(num, (batch, 6)).cuda() | ||
|
||
def test_gather(self, input, dim, num): | ||
model = _TestModel(num, dim).eval().cuda() | ||
dummy_input = torch.zeros_like(input) | ||
trt_model = module2trt(model, | ||
args=[dummy_input]) | ||
|
||
with torch.inference_mode(): | ||
gt = model(input) | ||
out = trt_model(input) | ||
torch.testing.assert_close(out, gt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import pytest | ||
import torch | ||
from torch import nn | ||
from torch2trt_dynamic import module2trt | ||
|
||
|
||
class _TestModel(nn.Module): | ||
|
||
def __init__(self, dim: int) -> None: | ||
super().__init__() | ||
self.dim = dim | ||
|
||
def forward(self, input, index): | ||
return torch.gather(input, self.dim, index) | ||
|
||
|
||
class TestGather: | ||
|
||
@pytest.fixture | ||
def input(self): | ||
yield torch.rand(3, 4, 5).cuda() | ||
|
||
@pytest.fixture | ||
def dim(self, request): | ||
yield request.param | ||
|
||
@pytest.fixture | ||
def index(self, input, dim): | ||
max_val = input.size(dim) | ||
yield torch.randint(max_val, (3, 4, 5)).cuda() | ||
|
||
@pytest.mark.parametrize('dim', [0, 1, 2]) | ||
def test_gather(self, input, dim, index): | ||
model = _TestModel(dim) | ||
dummy_input = torch.zeros_like(input) | ||
dummy_index = torch.zeros_like(index) | ||
trt_model = module2trt(model, | ||
args=[dummy_input, dummy_index]) | ||
|
||
with torch.inference_mode(): | ||
gt = model(input, index) | ||
out = trt_model(input, index) | ||
torch.testing.assert_close(out, gt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters