Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
fix flaky test for hard_sigmoid (#10759)
Browse files Browse the repository at this point in the history
  • Loading branch information
haojin2 authored and szha committed May 2, 2018
1 parent defb8fe commit 65df1ee
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tests/python/unittest/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,18 +601,18 @@ def fhardsigmoid_grad(a, out_grad, alpha=0.2, beta=0.5):
for dtype in [np.float16, np.float32, np.float64]:
if dtype is np.float16:
rtol = 1e-2
atol = 1e-3
else:
rtol = 1e-3
atol = 1e-5
atol = 1e-3
eps = 1e-3
xa = np.random.uniform(low=-3.0,high=3.0,size=shape).astype(dtype)
# function not differentiable at x=2.5 and -2.5
xa[xa == 2.5] = xa[xa == 2.5] - 1e-2
xa[xa == -2.5] = xa[xa == -2.5] - 1e-2
xa[abs(xa-2.5) < eps] -= 2 * eps
xa[abs(xa+2.5) < eps] += 2 * eps
ya = fhardsigmoid(xa)
grad_xa = fhardsigmoid_grad(xa, np.ones(shape))
if dtype is not np.float16:
check_numeric_gradient(y, [xa], numeric_eps=1e-3, rtol=rtol, atol=atol, dtype=dtype)
check_numeric_gradient(y, [xa], numeric_eps=eps, rtol=rtol, atol=atol, dtype=dtype)
check_symbolic_forward(y, [xa], [ya], rtol=rtol, atol=atol, dtype=dtype)
check_symbolic_backward(y, [xa], [np.ones(shape)], [grad_xa], rtol=rtol, atol=atol, dtype=dtype)

Expand Down

0 comments on commit 65df1ee

Please sign in to comment.