def test_backward():
    x = Tensor(np.array(1), mstype.int32)
    y = Tensor(np.array(3), mstype.int32)
    context.set_context(mode=context.GRAPH_MODE)
    graph_forward_net = ForwardNet(max_cycles=10)
    graph_backward_net = BackwardNet(graph_forward_net)
    graph_mode_grads = graph_backward_net(x, y)
    context.set_context(mode=context.PYNATIVE_MODE)
    pynative_forward_net = ForwardNet(max_cycles=10)
    pynative_backward_net = BackwardNet(pynative_forward_net)
    pynative_mode_grads = pynative_backward_net(x, y)
    assert (graph_mode_grads == pynative_mode_grads)
def test_backward():
    x = Tensor(np.array(1), mstype.int32)
    y = Tensor(np.array(3), mstype.int32)
    context.set_context(mode=context.GRAPH_MODE)
    graph_forward_net = ForwardNet(max_cycles=10)
    graph_backward_net = BackwardNet(graph_forward_net)
    graph_mode_grads = graph_backward_net(x, y)
    context.set_context(mode=context.PYNATIVE_MODE)
    pynative_forward_net = ForwardNet(max_cycles=10)
    pynative_backward_net = BackwardNet(pynative_forward_net)
    pynative_mode_grads = pynative_backward_net(x, y)
    assert (graph_mode_grads == pynative_mode_grads)