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

Fix l1loss ci error #5307

Merged
merged 23 commits into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
249d020
fix bert backward bug
BBuf Jun 8, 2021
72c3ec6
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow
BBuf Jun 9, 2021
aef184f
fix argwhere module bug
BBuf Jun 9, 2021
9274a82
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow
BBuf Jun 10, 2021
16cd4dd
align dropout module with torch
BBuf Jun 10, 2021
18b70d7
fix conflict
BBuf Jun 10, 2021
5c3e5fe
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow
BBuf Jun 13, 2021
7281b0e
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow
BBuf Jun 15, 2021
6842fa1
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow
BBuf Jun 17, 2021
0190aa0
fix acosh ci bug
BBuf Jun 17, 2021
2c3779f
fix conflict
BBuf Jun 18, 2021
3e0c27a
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow
BBuf Jun 18, 2021
e452c81
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow
BBuf Jun 18, 2021
00d33ce
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow
BBuf Jun 20, 2021
7333881
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow
BBuf Jun 21, 2021
1373ee8
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow
BBuf Jun 22, 2021
639f1de
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow
BBuf Jun 22, 2021
801acf7
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow
BBuf Jun 23, 2021
9057170
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow
BBuf Jun 24, 2021
38662c0
fix l1loss bug
BBuf Jun 24, 2021
180a47c
fix test bug
BBuf Jun 24, 2021
6847876
Merge branch 'master' into fix_l1loss_ci_error
BBuf Jun 24, 2021
8d418c6
Merge branch 'master' into fix_l1loss_ci_error
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
2 changes: 1 addition & 1 deletion oneflow/python/nn/modules/loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def forward(self, input, target):
input.shape == target.shape
), "The Input shape must be the same as Target shape"

l1_value = flow.experimental.abs(flow.experimental.sub(target, input))
l1_value = flow.experimental.abs(flow.experimental.sub(input, target))
if self.reduction == "mean":
return flow.experimental.mean(l1_value)
elif self.reduction == "sum":
Expand Down
7 changes: 4 additions & 3 deletions oneflow/python/test/modules/test_l1loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def _np_l1loss(np_input, np_target):

def _np_l1loss_grad(np_input, np_target):
elem_cnt = np_input.size
np_grad = np.where(np_target - np_input > 0, -1, 1)
np_grad = np.zeros_like(np_target)
np_grad = np.sign(np_input - np_target)
np_l1_grad_sum = np_grad
np_l1_grad_mean = np_l1_grad_sum / elem_cnt

Expand All @@ -48,8 +49,8 @@ def _np_l1loss_grad(np_input, np_target):


def _test_l1loss_impl(test_case, device, shape, reduction):
x = np.random.randn(*shape)
y = np.random.randn(*shape)
x = np.random.randn(*shape).astype(np.float32)
y = np.random.randn(*shape).astype(np.float32)
input = flow.Tensor(
x, dtype=flow.float32, requires_grad=True, device=flow.device(device)
)
Expand Down
7 changes: 6 additions & 1 deletion oneflow/user/kernels/math_unary_elementwise_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ template<typename T>
struct AbsFunctor {
static OF_DEVICE_FUNC const T Forward(const T x) { return x < T(0) ? -x : x; }

static OF_DEVICE_FUNC const T Backward(const T x, const T dy) { return x < T(0) ? -dy : dy; }
static OF_DEVICE_FUNC const T Backward(const T x, const T dy) {
if (x == T(0))
return T(0);
else
return x < T(0) ? -dy : dy;
}
};

template<typename T>
Expand Down