code: def test_graph_logreg(seed):
      rng = np.random.RandomState(seed)
      x = nn.Variable([2, 3, 4], need_grad=True)
      w1 = nn.Variable([12, 5], need_grad=True)
      w2 = nn.Variable([12, 5], need_grad=True)
      b1 = nn.Variable([5], need_grad=True)
      b2 = nn.Variable([5], need_grad=True)
      t = nn.Variable([2, 1])
      x.d = rng.randn(*x.shape)
      w1.d = rng.randn(*w1.shape)
      w2.d = rng.randn(*w2.shape)
      b1.d = rng.randn(*b1.shape)
      b2.d = rng.randn(*b2.shape)
      t.d = rng.randint(0, 5, size=t.shape)
  
      nn.set_default_context(nn.Context())
  
      # Forwardprop by definition
      z1 = F.affine(x, w1, b1, 1)
      z2 = F.affine(x, w2, b2, 1)
      l1 = F.softmax_cross_entropy(z1, t, 1)
      L1 = F.mean(l1)
      l2 = F.softmax_cross_entropy(z2, t, 1)
      L2 = F.mean(l2)
      nn.forward_all([L1, L2])
  
      # Backprop for z1
      # Diff should be initialized since they are always accumulated
      x.g = 0
      w1.g = 0
      b1.g = 0
      L1.backward(clear_buffer=True)
  
      inputs = [x, w1, b1]
  
      from nbla_test_utils import (
          compute_analytical_and_numerical_grad_graph as grads,
      )
  
      agrad, ngrad = grads(L1, inputs, 1e-3, False)
      assert_allclose(ngrad, agrad, atol=1e-2)
  
      # Backprop for z2
      # Diff should be initialized since they are always accumulated
      x.g = 0
      w2.g = 0
      b2.g = 0
      L2.backward(clear_buffer=True)
  
      inputs = [x, w2, b2]
  
      from nbla_test_utils import (
          compute_analytical_and_numerical_grad_graph as grads,
      )
  
      agrad, ngrad = grads(L2, inputs, 1e-3, False)
      assert_allclose(ngrad, agrad, atol=1e-2)
  
file_path: nnabla/python/test/test_forward_all.py
imports: from six.moves import range
  import pytest
  import numpy
  import nnabla
  import nnabla.functions
  import nnabla.parametric_functions
  from nnabla.testing import assert_allclose
label_desc: Use image node_id 2 for calling a global function with example usage: test_graph_logreg(seed) without return types