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

Add TestUtils.randint + replace torch.randint with tu.randint #1276

Merged
merged 1 commit into from
Aug 26, 2022
Merged
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
72 changes: 36 additions & 36 deletions python/torch_mlir_e2e_test/test_suite/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def forward(self, x):

@register_test_case(module_factory=lambda: IsFloatingPointInt())
def IsFloatingPointInt_False(module, tu: TestUtils):
module.forward(torch.randint(100, (3, 3)))
module.forward(tu.randint(3, 3, high=100))


# ==============================================================================
Expand Down Expand Up @@ -736,7 +736,7 @@ def forward(self, indices):

@register_test_case(module_factory=lambda: EmbeddingModuleI64())
def EmbeddingModuleI64_basic(module, tu: TestUtils):
module.forward(torch.randint(100, (3, 3)))
module.forward(tu.randint(3, 3, high=100))


# ==============================================================================
Expand All @@ -762,7 +762,7 @@ def forward(self, indices):

@register_test_case(module_factory=lambda: EmbeddingModuleI32())
def EmbeddingModuleI32_basic(module, tu: TestUtils):
module.forward(torch.randint(100, (3, 3)).to(torch.int32))
module.forward(tu.randint(3, 3, high=100).to(torch.int32))


# ==============================================================================
Expand All @@ -787,7 +787,7 @@ def forward(self, indices):

@register_test_case(module_factory=lambda: EmbeddingModuleI32Static())
def EmbeddingModuleI32Static_basic(module, tu: TestUtils):
module.forward(torch.randint(100, (3, 3)).to(torch.int32))
module.forward(tu.randint(3, 3, high=100).to(torch.int32))


# ==============================================================================
Expand All @@ -813,7 +813,7 @@ def forward(self, indices):

@register_test_case(module_factory=lambda: EmbeddingModule1DIndices())
def EmbeddingModule1DIndices_basic(module, tu: TestUtils):
module.forward(torch.randint(100, (3,)).to(torch.int32))
module.forward(tu.randint(3, high=100).to(torch.int32))


# ==============================================================================
Expand Down Expand Up @@ -1331,7 +1331,7 @@ def forward(self, x):

@register_test_case(module_factory=lambda: DropoutEvalIntModule())
def DropoutEvalIntModule_basic(module, tu: TestUtils):
module.forward(torch.randint(5, 10, (3, 4)))
module.forward(tu.randint(3, 4, low=5, high=10))


# ==============================================================================
Expand Down Expand Up @@ -1420,7 +1420,7 @@ def forward(self, input):

@register_test_case(module_factory=lambda: NumelZeroRankModule())
def NumelZeroRankModule_basic(module, tu: TestUtils):
module.forward(torch.randint(10, []))
module.forward(tu.randint(high=10))


# ==============================================================================
Expand Down Expand Up @@ -1646,7 +1646,7 @@ def forward(self, a, b):

@register_test_case(module_factory=lambda: ReturnTwoTensorF32I64())
def ReturnTwoTensorF32I64_basic(module, tu: TestUtils):
module.forward(tu.rand(2, 3), torch.randint(5, (2, 3)))
module.forward(tu.rand(2, 3), tu.randint(2, 3, high=5))


# ==============================================================================
Expand All @@ -1669,7 +1669,7 @@ def forward(self, x, index):

@register_test_case(module_factory=lambda: IndexTensorModule())
def IndexTensorModule_basic(module, tu: TestUtils):
module.forward(tu.rand(5), torch.randint(4, (2, 3)))
module.forward(tu.rand(5), tu.randint(2, 3, high=4))


# ==============================================================================
Expand All @@ -1692,7 +1692,7 @@ def forward(self, x, index):

@register_test_case(module_factory=lambda: IndexTensorModule3dInput())
def IndexTensorModule3dInput_basic(module, tu: TestUtils):
module.forward(tu.rand(5, 4, 3), torch.randint(3, (2, 3)))
module.forward(tu.rand(5, 4, 3), tu.randint(2, 3, high=3))


# ==============================================================================
Expand All @@ -1715,7 +1715,7 @@ def forward(self, a, ind):

@register_test_case(module_factory=lambda: IndexTensorSelectDimModule())
def IndexTensorSelectDimModule_basic(module, tu: TestUtils):
module.forward(tu.rand(2, 4, 6), torch.randint(3, (2, 3)))
module.forward(tu.rand(2, 4, 6), tu.randint(2, 3, high=3))

# ==============================================================================

Expand All @@ -1738,7 +1738,7 @@ def forward(self, x, index1, index2):

@register_test_case(module_factory=lambda: IndexTensorMultiInput())
def IndexTensorMultiInput_basic(module, tu: TestUtils):
module.forward(tu.rand(5, 4, 3), torch.randint(3, (3, 3)), torch.randint(3, (3,)))
module.forward(tu.rand(5, 4, 3), tu.randint(3, 3, high=3), tu.randint(3, high=3))


# ==============================================================================
Expand All @@ -1762,7 +1762,7 @@ def forward(self, x, index1, index2):

@register_test_case(module_factory=lambda: IndexTensorMultiInputOneDim())
def IndexTensorMultiInputOneDim_basic(module, tu: TestUtils):
module.forward(tu.rand(5, 4, 3), torch.randint(4, (6, 1)), torch.randint(3, (3,)))
module.forward(tu.rand(5, 4, 3), tu.randint(6, 1, high=4), tu.randint(3, high=3))


# ==============================================================================
Expand Down Expand Up @@ -1791,8 +1791,8 @@ def forward(self, x, index1, index2):
@register_test_case(
module_factory=lambda: IndexTensorMultiInputContiguousOneDimDynamic())
def IndexTensorMultiInputContiguousOneDimDynamic_basic(module, tu: TestUtils):
module.forward(tu.rand(5, 4, 3), torch.randint(4, (6, 1)),
torch.randint(3, (3, )))
module.forward(tu.rand(5, 4, 3), tu.randint(6, 1, high=4),
tu.randint(3, high=3))


# ==============================================================================
Expand Down Expand Up @@ -1822,8 +1822,8 @@ def forward(self, x, index1, index2):
module_factory=lambda: IndexTensorMultiInputNonContiguousOneDimDynamic())
def IndexTensorMultiInputNonContiguousOneDimDynamic_basic(
module, tu: TestUtils):
module.forward(tu.rand(5, 4, 3), torch.randint(4, (6, 1)),
torch.randint(3, (3, )))
module.forward(tu.rand(5, 4, 3), tu.randint(6, 1, high=4),
tu.randint(3, high=3))


# ==============================================================================
Expand Down Expand Up @@ -1852,8 +1852,8 @@ def forward(self, x, index1, index2):
@register_test_case(
module_factory=lambda: IndexTensorMultiInputNonContiguousDynamic())
def IndexTensorMultiInputNonContiguousDynamic_basic(module, tu: TestUtils):
module.forward(tu.rand(5, 4, 3), torch.randint(2, (6, 2)),
torch.randint(3, (2, )))
module.forward(tu.rand(5, 4, 3), tu.randint(6, 2, high=2),
tu.randint(2, high=3))


# ==============================================================================
Expand All @@ -1880,8 +1880,8 @@ def forward(self, x, index1, index2, index3):
IndexTensorMultiInputNonContiguousMultipleStaticDims())
def IndexTensorMultiInputNonContiguousMultipleStaticDims_basic(
module, tu: TestUtils):
module.forward(tu.rand(5, 4, 3, 2), torch.randint(3, (4, 1)),
torch.randint(1, (1, 3)), torch.randint(1, (4, 3)))
module.forward(tu.rand(5, 4, 3, 2), tu.randint(4, 1, high=3),
tu.randint(1, 3, high=1), tu.randint(4, 3, high=1))


# ==============================================================================
Expand All @@ -1905,7 +1905,7 @@ def forward(self, x, index1, index2):

@register_test_case(module_factory=lambda: IndexTensorMultiInputNonContiguous())
def IndexTensorMultiInputNonContiguous_basic(module, tu: TestUtils):
module.forward(tu.rand(5, 4, 3, 2), torch.randint(3, (4, 2)), torch.randint(1, (4, 2,)))
module.forward(tu.rand(5, 4, 3, 2), tu.randint(4, 2, high=3), tu.randint(4, 2, high=1))


# ==============================================================================
Expand All @@ -1931,9 +1931,9 @@ def forward(self, x, index1, index2, index3):
@register_test_case(module_factory=lambda: IndexTensorMultiInputThreeIndexers())
def IndexTensorMultiInputThreeIndexers_basic(module, tu: TestUtils):
module.forward(tu.rand(1, 2, 4, 4, 5, 3),
torch.randint(3, (8, 4, 2,)),
torch.randint(4, (8, 1, 1,)),
torch.randint(2, (4, 2,)))
tu.randint(8, 4, 2, high=3),
tu.randint(8, 1, 1, high=4),
tu.randint(4, 2, high=2))


# ==============================================================================
Expand All @@ -1957,7 +1957,7 @@ def forward(self, x, index1, index2):

@register_test_case(module_factory=lambda: IndexTensorMultiInputContiguousCenter())
def IndexTensorMultiInputContiguousCenter_basic(module, tu: TestUtils):
module.forward(tu.rand(5, 4, 3, 2), torch.randint(3, (2, 2)), torch.randint(2, [2]))
module.forward(tu.rand(5, 4, 3, 2), tu.randint(2, 2, high=3), tu.randint(2, high=2))


# ==============================================================================
Expand Down Expand Up @@ -2089,7 +2089,7 @@ def forward(self, x):

@register_test_case(module_factory=lambda: HardTanhIntModule())
def HardTanhIntModule_basic(module, tu: TestUtils):
module.forward(torch.randint(-5, 5, (100, 100)))
module.forward(tu.randint(100, 100, low=-5, high=5))


# ==============================================================================
Expand All @@ -2111,7 +2111,7 @@ def forward(self, x):

@register_test_case(module_factory=lambda: BincountModule())
def BincountModule_basic(module, tu: TestUtils):
module.forward(torch.randint(10, (1000, )))
module.forward(tu.randint(1000, high=10))


# ==============================================================================
Expand All @@ -2133,7 +2133,7 @@ def forward(self, x):

@register_test_case(module_factory=lambda: BincountStaticSizeModule())
def BincountStaticSizeModule_basic(module, tu: TestUtils):
module.forward(torch.randint(100, (200, )))
module.forward(tu.randint(200, high=100))


# ==============================================================================
Expand All @@ -2155,7 +2155,7 @@ def forward(self, x):

@register_test_case(module_factory=lambda: BincountMinlengthModule())
def BincountMinlengthModule_basic(module, tu: TestUtils):
module.forward(torch.randint(5, (20, )))
module.forward(tu.randint(20, high=5))


# ==============================================================================
Expand Down Expand Up @@ -2198,8 +2198,8 @@ def forward(self, x, y):

@register_test_case(module_factory=lambda: ExpandAsIntModule())
def ExpandAsIntModule_basic(module, tu: TestUtils):
module.forward(torch.randint(100, (1, 1, 1)),
torch.randint(200, (4, 5, 6)))
module.forward(tu.randint(1, 1, 1, high=100),
tu.randint(4, 5, 6, high=200))


# ==============================================================================
Expand Down Expand Up @@ -2262,7 +2262,7 @@ def forward(self, x, y):

@register_test_case(module_factory=lambda: CopyWithDifferentDTypesModule())
def CopyWithDifferentDTypesModule_basic(module, tu: TestUtils):
module.forward(torch.randint(100, (3, 2, 4)), tu.rand(3, 2, 4))
module.forward(tu.randint(3, 2, 4, high=100), tu.rand(3, 2, 4))


class CopyWithDifferentDTypesAndSizesModule(torch.nn.Module):
Expand All @@ -2283,7 +2283,7 @@ def forward(self, x, y):
@register_test_case(
module_factory=lambda: CopyWithDifferentDTypesAndSizesModule())
def CopyWithDifferentDTypesAndSizesModule_basic(module, tu: TestUtils):
module.forward(tu.rand(3, 2, 4), torch.randint(1000, (3, 2, 1)))
module.forward(tu.rand(3, 2, 4), tu.randint(3, 2, 1, high=1000))


# ==============================================================================
Expand Down Expand Up @@ -2451,7 +2451,7 @@ def forward(self, x):

@register_test_case(module_factory=lambda: ScalarImplicitIntModule())
def ScalarImplicitIntModule_basic(module, tu: TestUtils):
module.forward(torch.randint(-100, 100, ()))
module.forward(tu.randint(low=-100, high=100))


# ==============================================================================
Expand Down Expand Up @@ -2517,7 +2517,7 @@ def forward(self, input, batch1, batch2):

@register_test_case(module_factory=lambda: BaddbmmDifferentDtypesModule())
def BaddbmmDifferentDtypesModule_basic(module, tu: TestUtils):
module.forward(torch.randint(10, (3, 4, 5)), tu.rand(3, 4, 6),
module.forward(tu.randint(3, 4, 5, high=10), tu.rand(3, 4, 6),
tu.rand(3, 6, 5))


Expand Down
4 changes: 2 additions & 2 deletions python/torch_mlir_e2e_test/test_suite/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def forward(self, x):

@register_test_case(module_factory=lambda: TensorToIntZeroRank())
def TensorToIntZeroRank_basic(module, tu: TestUtils):
module.forward(torch.randint(10, ()))
module.forward(tu.randint(high=10))

# ==============================================================================

Expand All @@ -45,7 +45,7 @@ def forward(self, x):

@register_test_case(module_factory=lambda: TensorToInt())
def TensorToInt_basic(module, tu: TestUtils):
module.forward(torch.randint(10, (1, 1)))
module.forward(tu.randint(1, 1, high=10))

# ==============================================================================

Expand Down
Loading