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

Revert "Dev sin loop grad" #13

Merged
merged 1 commit into from
May 24, 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
53 changes: 0 additions & 53 deletions oneflow/core/autograd/gradient_funcs/cos.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion oneflow/core/autograd/gradient_funcs/math_unary_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class UnaryMathOp : public OpExprGradFunction<UnaryMathCaptureState> {
class op_cls##Cls final : public UnaryMathOp<functional::op_cls##Grad> {}; \
REGISTER_OP_EXPR_GRAD_FUNCTION(op_type_name, op_cls##Cls);

OF_PP_FOR_EACH_TUPLE(INSTANTIAT_AND_REGISTER_UNARY_MATHOP_CLASS, MATH_UNARY_ELEMENTWISE_GRAD_SEQ);
OF_PP_FOR_EACH_TUPLE(INSTANTIAT_AND_REGISTER_UNARY_MATHOP_CLASS, MATH_UNARY_ELEMENTWISE_FUNC_SEQ);

// higher order derivative
OF_PP_FOR_EACH_TUPLE(INSTANTIAT_AND_REGISTER_UNARY_MATHOP_CLASS,
Expand Down
49 changes: 0 additions & 49 deletions oneflow/core/autograd/gradient_funcs/negative.cpp

This file was deleted.

52 changes: 0 additions & 52 deletions oneflow/core/autograd/gradient_funcs/sin.cpp

This file was deleted.

32 changes: 0 additions & 32 deletions oneflow/user/ops/math_unary_elementwise_seq.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,38 +92,6 @@ namespace oneflow {
OF_PP_MAKE_TUPLE_SEQ("tan", Tan) \
OF_PP_MAKE_TUPLE_SEQ("not_equal_zero", NotEqualZero)

#define MATH_UNARY_ELEMENTWISE_GRAD_SEQ \
OF_PP_MAKE_TUPLE_SEQ("abs", Abs) \
OF_PP_MAKE_TUPLE_SEQ("acos", Acos) \
OF_PP_MAKE_TUPLE_SEQ("acosh", Acosh) \
OF_PP_MAKE_TUPLE_SEQ("asin", Asin) \
OF_PP_MAKE_TUPLE_SEQ("asinh", Asinh) \
OF_PP_MAKE_TUPLE_SEQ("atan", Atan) \
OF_PP_MAKE_TUPLE_SEQ("atanh", Atanh) \
OF_PP_MAKE_TUPLE_SEQ("ceil", Ceil) \
OF_PP_MAKE_TUPLE_SEQ("cosh", Cosh) \
OF_PP_MAKE_TUPLE_SEQ("erf", Erf) \
OF_PP_MAKE_TUPLE_SEQ("erfc", Erfc) \
OF_PP_MAKE_TUPLE_SEQ("exp", Exp) \
OF_PP_MAKE_TUPLE_SEQ("expm1", Expm1) \
OF_PP_MAKE_TUPLE_SEQ("floor", Floor) \
OF_PP_MAKE_TUPLE_SEQ("lgamma", Lgamma) \
OF_PP_MAKE_TUPLE_SEQ("log", Log) \
OF_PP_MAKE_TUPLE_SEQ("log2", Log2) \
OF_PP_MAKE_TUPLE_SEQ("log1p", Log1p) \
OF_PP_MAKE_TUPLE_SEQ("log_sigmoid", LogSigmoid) \
OF_PP_MAKE_TUPLE_SEQ("reciprocal", Reciprocal) \
OF_PP_MAKE_TUPLE_SEQ("reciprocal_no_nan", ReciprocalNoNan) \
OF_PP_MAKE_TUPLE_SEQ("rint", Rint) \
OF_PP_MAKE_TUPLE_SEQ("round", Round) \
OF_PP_MAKE_TUPLE_SEQ("rsqrt", Rsqrt) \
OF_PP_MAKE_TUPLE_SEQ("sigmoid_v2", Sigmoid) \
OF_PP_MAKE_TUPLE_SEQ("sign", Sign) \
OF_PP_MAKE_TUPLE_SEQ("sinh", Sinh) \
OF_PP_MAKE_TUPLE_SEQ("sqrt", Sqrt) \
OF_PP_MAKE_TUPLE_SEQ("square", Square) \
OF_PP_MAKE_TUPLE_SEQ("tan", Tan) \
OF_PP_MAKE_TUPLE_SEQ("not_equal_zero", NotEqualZero)
} // namespace oneflow

#endif // ONEFLOW_USER_OPS_MATH_UNARY_ELEMENTWISE_SEQ_H_
28 changes: 1 addition & 27 deletions python/oneflow/test/modules/test_math_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,38 +82,12 @@ def _test_cos_backward(test_case, shape, device):
np_grad = -np.sin(x.numpy())
test_case.assertTrue(np.allclose(x.grad.numpy(), np_grad, 1e-05, 1e-05))

def _test_cos_higher_order_backward(test_case, shape, device):
x = flow.tensor(
np.random.randn(*shape),
dtype=flow.float32,
device=flow.device(device),
requires_grad=True,
)
y = flow.cos(x)
x_grad = flow.autograd.grad(
outputs=y,
inputs=x,
grad_outputs=flow.ones_like(y),
create_graph = True
)[0]
np_grad = -np.sin(x.numpy())
test_case.assertTrue(np.allclose(x_grad, np_grad, 1e-05, 1e-05))

x_grad_grad = flow.autograd.grad(
outputs=x_grad,
inputs=x,
grad_outputs=flow.ones_like(y),
create_graph = True
)[0]
np_grad_grad = -np.cos(x.numpy())
test_case.assertTrue(np.allclose(x_grad_grad, np_grad_grad, 1e-05, 1e-05))


@flow.unittest.skip_unless_1n1d()
class TestCos(flow.unittest.TestCase):
def test_cos(test_case):
arg_dict = OrderedDict()
arg_dict["test_fun"] = [_test_cos, _test_cos_backward, _test_cos_higher_order_backward]
arg_dict["test_fun"] = [_test_cos, _test_cos_backward]
arg_dict["shape"] = [(2, 3), (2, 3, 4), (2, 3, 4, 5)]
arg_dict["device"] = ["cpu", "cuda"]
for arg in GenArgList(arg_dict):
Expand Down