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

remove redundant assert and check #5264

Merged
merged 24 commits into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9176505
remove redundant assert and check
MARD1NO Jun 22, 2021
6916fb4
split to 3 ops file
MARD1NO Jun 22, 2021
3a9d46f
remove useless header file
MARD1NO Jun 22, 2021
5034179
Merge branch 'master' into fix_wrong_assert_in_pad
MARD1NO Jun 22, 2021
b49e459
merge ops into single file
MARD1NO Jun 22, 2021
0b2238e
Merge branch 'fix_wrong_assert_in_pad' of https://github.com/Oneflow-…
MARD1NO Jun 22, 2021
aacb7c0
Merge branch 'master' into fix_wrong_assert_in_pad
MARD1NO Jun 23, 2021
ad15bc2
Merge branch 'master' into fix_wrong_assert_in_pad
oneflow-ci-bot Jun 23, 2021
552ddf9
Merge branch 'master' into fix_wrong_assert_in_pad
oneflow-ci-bot Jun 23, 2021
52a2560
Merge branch 'master' into fix_wrong_assert_in_pad
oneflow-ci-bot Jun 23, 2021
95d0567
Merge branch 'master' into fix_wrong_assert_in_pad
oneflow-ci-bot Jun 23, 2021
2c86d37
Merge branch 'master' into fix_wrong_assert_in_pad
oneflow-ci-bot Jun 23, 2021
451616f
Merge branch 'master' into fix_wrong_assert_in_pad
oneflow-ci-bot Jun 23, 2021
6c3c9e3
Merge branch 'master' into fix_wrong_assert_in_pad
oneflow-ci-bot Jun 24, 2021
6405953
Merge branch 'master' into fix_wrong_assert_in_pad
oneflow-ci-bot Jun 24, 2021
fdcc6c1
remove useless params
MARD1NO Jun 24, 2021
4f71743
Merge branch 'fix_wrong_assert_in_pad' of https://github.com/Oneflow-…
MARD1NO Jun 24, 2021
36de34f
Merge branch 'master' into fix_wrong_assert_in_pad
oneflow-ci-bot Jun 24, 2021
51feed6
Merge branch 'master' into fix_wrong_assert_in_pad
oneflow-ci-bot Jun 24, 2021
ac7374b
Merge branch 'master' into fix_wrong_assert_in_pad
oneflow-ci-bot Jun 24, 2021
403b197
Merge branch 'master' into fix_wrong_assert_in_pad
oneflow-ci-bot Jun 24, 2021
aefe5a4
Merge branch 'master' into fix_wrong_assert_in_pad
oneflow-ci-bot Jun 24, 2021
71792dc
Merge branch 'master' into fix_wrong_assert_in_pad
oneflow-ci-bot Jun 24, 2021
7e29622
Merge branch 'master' into fix_wrong_assert_in_pad
oneflow-ci-bot Jun 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
48 changes: 18 additions & 30 deletions oneflow/python/nn/modules/constantpad2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,37 +100,25 @@ def __init__(self, padding: Union[int, tuple, list], value: Union[int, float] =
def forward(self, x):
_, _, h, w = x.shape

if (
self.padding[2] < h
and self.padding[3] < h
and self.padding[0] < w
and self.padding[1] < w
):

if x.dtype in [flow.float32, flow.float16, flow.float64]:
floating_value = float(self.value)
integral_value = int(0)
else:
floating_value = float(0)
integral_value = int(self.value)

self._op = (
flow.builtin_op("constant_pad2d")
.Input("x")
.Output("y")
.Attr("padding", self.padding)
.Attr("floating_value", floating_value)
.Attr("integral_value", integral_value)
.Build()
)

res = self._op(x)[0]
return res

if x.dtype in [flow.float32, flow.float16, flow.float64]:
floating_value = float(self.value)
integral_value = int(0)
else:
raise AssertionError(
"Padding size should be less than the corresponding input dimension. Please check."
)
floating_value = float(0)
integral_value = int(self.value)

self._op = (
flow.builtin_op("constant_pad2d")
.Input("x")
.Output("y")
.Attr("padding", self.padding)
.Attr("floating_value", floating_value)
.Attr("integral_value", integral_value)
.Build()
)

res = self._op(x)[0]
return res


if __name__ == "__main__":
Expand Down
4 changes: 0 additions & 4 deletions oneflow/python/nn/modules/padding.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ def __init__(self, padding: Union[int, tuple, list]):
.Input("x")
.Output("y")
.Attr("padding", self.padding)
.Attr("floating_value", float(1.0))
.Attr("integral_value", int(0))
.Build()
)

Expand Down Expand Up @@ -183,8 +181,6 @@ def __init__(self, padding: Union[int, tuple]) -> None:
.Input("x")
.Output("y")
.Attr("padding", boundary)
.Attr("floating_value", float(1.0))
.Attr("integral_value", int(0))
.Build()
)

Expand Down
16 changes: 0 additions & 16 deletions oneflow/python/ops/pad.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,16 +372,8 @@ def pad_Job(x: tp.Numpy.Placeholder((1, 2, 3, 3))
assert len(padding) == len(x.shape), ValueError(
"padding boundry must be the same size of input dims"
)
assert (
padding[2] < H and padding[3] < H and padding[0] < W and padding[1] < W
), ValueError(
"Padding size should be less than the corresponding input dimension!"
)
boundry = [padding[0], padding[1], padding[2], padding[3]]
elif isinstance(padding, int):
assert padding < H and padding < W, ValueError(
"Padding size should be less than the corresponding input dimension!"
)
boundry = [padding, padding, padding, padding]
else:
raise ValueError("padding must be in or list or tuple!")
Expand Down Expand Up @@ -456,16 +448,8 @@ def pad_Job(x: tp.Numpy.Placeholder((1, 2, 3, 3), const_value)
assert len(padding) == len(x.shape), ValueError(
"padding boundry must be the same size of input dims"
)
assert (
padding[2] < H and padding[3] < H and padding[0] < W and padding[1] < W
), ValueError(
"Padding size should be less than the corresponding input dimension!"
)
boundry = [padding[0], padding[1], padding[2], padding[3]]
elif isinstance(padding, int):
assert padding < H and padding < W, ValueError(
"Padding size should be less than the corresponding input dimension!"
)
boundry = [padding, padding, padding, padding]
else:
raise ValueError("padding must be in or list or tuple!")
Expand Down
Loading