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 new autotest #5588

Merged
merged 28 commits into from
Jul 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
34ee0a6
fix upsample nearest bug
BBuf Jun 29, 2021
0219f8f
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow
BBuf Jun 30, 2021
c822046
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow
BBuf Jul 1, 2021
0106b53
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow
BBuf Jul 1, 2021
267d4ca
fix upsample nearest bug (#5347)
BBuf Jun 30, 2021
205c7fb
fix upsample bilinear bug
BBuf Jun 30, 2021
38f6dfd
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow
BBuf Jul 1, 2021
318ef54
fix conflict
BBuf Jul 2, 2021
544e107
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow
BBuf Jul 4, 2021
5f98a22
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow
BBuf Jul 16, 2021
3bde816
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow
BBuf Jul 18, 2021
0e4db3b
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow
BBuf Jul 19, 2021
aaf901b
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow
BBuf Jul 20, 2021
6c15c98
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow
BBuf Jul 21, 2021
95ca5f0
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow
BBuf Jul 21, 2021
86f1eab
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow
BBuf Jul 22, 2021
1474b80
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow
BBuf Jul 22, 2021
c8592f1
fix export bug
BBuf Jul 22, 2021
52d822f
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow
BBuf Jul 23, 2021
ffd8e34
add new_autotest_part1
BBuf Jul 23, 2021
b0a0e57
add new_autotest_part1
BBuf Jul 23, 2021
002e5dd
add squeeze test
BBuf Jul 23, 2021
77a998b
add permute test
BBuf Jul 23, 2021
b2fe7f3
add hardswish test
BBuf Jul 23, 2021
e4e8746
add prelu
BBuf Jul 23, 2021
69db6fb
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow
BBuf Jul 24, 2021
6b58701
fix conflict
BBuf Jul 24, 2021
871b316
fix bug
BBuf Jul 24, 2021
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: 0 additions & 1 deletion oneflow/python/nn/modules/squeeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def squeeze_op(input, dim: Optional[Sequence[int]] = None):
dim = [dim]
elif dim is None:
dim = range(input.ndim)

dim = list(filter(lambda i: input.size(i) == 1, dim))
return Squeeze(dim=dim)(input)

Expand Down
6 changes: 5 additions & 1 deletion oneflow/python/nn/modules/transpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@

class Transpose(Module):
def __init__(
self, dim0, dim1, conjugate: bool = False, batch_axis_non_change: bool = False,
self,
dim0: int,
dim1: int,
conjugate: bool = False,
batch_axis_non_change: bool = False,
) -> None:
super().__init__()

Expand Down
10 changes: 8 additions & 2 deletions oneflow/python/test/modules/test_activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,9 +737,15 @@ def test_hardswish(test_case):
for arg in GenArgList(arg_dict):
_test_hardswish_impl(test_case, *arg)

@autotest()
def test_hardswish_module_with_random_data(test_case):
for device in ["cpu", "cuda"]:
test_module_against_pytorch(test_case, "nn.Hardswish", device=device, n=2)
m = torch.nn.Hardswish()
m.train(random())
device = random_device()
m.to(device)
x = random_pytorch_tensor().to(device)
y = m(x)
return y


def _np_hardtanh_grad(x):
Expand Down
12 changes: 12 additions & 0 deletions oneflow/python/test/modules/test_prelu.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import oneflow as flow
from test_util import GenArgList
from automated_test_util import *


def _prelu(input, alpha):
Expand Down Expand Up @@ -85,6 +86,17 @@ def test_prelu(test_case):
_test_prelu_ndims(test_case, *arg)
_test_prelu_grad(test_case, *arg)

@unittest.skip("prelu has bug")
@autotest()
def test_prelu_module_with_random_data(test_case):
m = torch.nn.PReLU(num_parameters=random().to(int), init=random().to(float))
m.train(random())
device = random_device()
m.to(device)
x = random_pytorch_tensor().to(device)
y = m(x)
return y


if __name__ == "__main__":
unittest.main()
19 changes: 8 additions & 11 deletions oneflow/python/test/modules/test_reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import oneflow as flow
from test_util import GenArgList
from automated_test_util import *


def _test_reshape(test_case, device):
Expand All @@ -42,16 +43,6 @@ def _test_reshape_tuple(test_case, device):
test_case.assertTrue(np.array_equal(of_shape, np_shape))


def _test_tensor_reshape(test_case, device):
x = np.array(
[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]
).astype(np.float32)
input = flow.Tensor(x, device=flow.device(device))
of_shape = input.reshape(shape=[2, 2, 2, -1]).numpy().shape
np_shape = (2, 2, 2, 2)
test_case.assertTrue(np.array_equal(of_shape, np_shape))


def _test_reshape_backward(test_case, device):
x = np.array(
[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]
Expand All @@ -77,13 +68,19 @@ def test_reshape(test_case):
arg_dict["test_fun"] = [
_test_reshape,
_test_reshape_tuple,
_test_tensor_reshape,
_test_reshape_backward,
]
arg_dict["device"] = ["cpu", "cuda"]
for arg in GenArgList(arg_dict):
arg[0](test_case, *arg[1:])

@autotest()
def test_reshape_flow_with_random_data(test_case):
device = random_device()
x = random_pytorch_tensor(ndim=4).to(device)
y = torch.reshape(x, shape=(-1,))
return y


if __name__ == "__main__":
unittest.main()
23 changes: 5 additions & 18 deletions oneflow/python/test/modules/test_squeeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,25 +99,12 @@ def test_squeeze(test_case):
for arg in GenArgList(arg_dict):
arg[0](test_case, *arg[1:])

@autotest()
def test_flow_squeeze_with_random_data(test_case):
for device in ["cpu", "cuda"]:
test_flow_against_pytorch(
test_case,
"squeeze",
extra_annotations={"dim": int,},
extra_generators={"dim": random(0, 6)},
device=device,
)

def test_flow_tensor_squeeze_with_random_data(test_case):
for device in ["cpu", "cuda"]:
test_tensor_against_pytorch(
test_case,
"squeeze",
extra_annotations={"dim": int},
extra_generators={"dim": random(0, 6)},
device=device,
)
device = random_device()
x = random_pytorch_tensor().to(device)
y = torch.squeeze(x, random(1, 3).to(int))
return y


if __name__ == "__main__":
Expand Down
8 changes: 8 additions & 0 deletions oneflow/python/test/modules/test_transpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import oneflow as flow
from test_util import GenArgList
from automated_test_util import *


def _test_transpose(test_case, device):
Expand Down Expand Up @@ -88,6 +89,13 @@ def test_transpose(test_case):
for arg in GenArgList(arg_dict):
arg[0](test_case, *arg[1:])

@autotest()
def test_transpose_flow_with_random_data(test_case):
device = random_device()
x = random_pytorch_tensor(ndim=4).to(device)
y = torch.transpose(x, dim0=random(1, 3).to(int), dim1=random(1, 3).to(int))
return y


if __name__ == "__main__":
unittest.main()
8 changes: 8 additions & 0 deletions oneflow/python/test/modules/test_unsqueeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import oneflow as flow
from test_util import GenArgList
from automated_test_util import *


def _test_unsqueeze(test_case, device):
Expand Down Expand Up @@ -69,6 +70,13 @@ def test_unsqueeze(test_case):
for arg in GenArgList(arg_dict):
arg[0](test_case, *arg[1:])

@autotest()
def test_flow_unsqueeze_with_random_data(test_case):
device = random_device()
x = random_pytorch_tensor().to(device)
y = torch.unsqueeze(x, random(1, 3).to(int))
return y


if __name__ == "__main__":
unittest.main()
49 changes: 49 additions & 0 deletions oneflow/python/test/tensor/test_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,55 @@ def test_tensor_round(test_case):
np.allclose(of_input.grad.numpy(), np.zeros(shape), 1e-4, 1e-4)
)

def _test_tensor_reshape(test_case):
x = np.array(
[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]
).astype(np.float32)
input = flow.Tensor(x)
of_shape = input.reshape(shape=[2, 2, 2, -1]).numpy().shape
np_shape = (2, 2, 2, 2)
test_case.assertTrue(np.array_equal(of_shape, np_shape))

@autotest()
def test_reshape_tensor_with_random_data(test_case):
device = random_device()
x = random_pytorch_tensor(ndim=4).to(device)
y = x.reshape(shape=(-1,))
return y

@autotest()
def test_tensor_squeeze_with_random_data(test_case):
device = random_device()
x = random_pytorch_tensor().to(device)
y = x.squeeze(random().to(int))
return y

@autotest()
def test_flow_unsqueeze_with_random_data(test_case):
device = random_device()
x = random_pytorch_tensor().to(device)
y = x.unsqueeze(random(1, 3).to(int))
return y

@autotest()
def test_permute_flow_with_random_data(test_case):
device = random_device()
x = random_pytorch_tensor(ndim=4).to(device)
y = x.permute(
random(0, 4).to(int),
random(0, 4).to(int),
random(0, 4).to(int),
random(0, 4).to(int),
)
return y

@autotest()
def test_transpose_tensor_with_random_data(test_case):
device = random_device()
x = random_pytorch_tensor(ndim=4).to(device)
y = x.transpose(dim0=random(1, 3).to(int), dim1=random(1, 3).to(int))
return y

def test_tensor_where(test_case):
x = flow.Tensor(
np.array([[-0.4620, 0.3139], [0.3898, -0.7197], [0.0478, -0.1657]]),
Expand Down