code: def test_graph_model(model, seed):
      np.random.seed(313)
      rng = np.random.RandomState(seed)
      x = nn.Variable([2, 3, 4, 4], need_grad=True)
      t = nn.Variable([2, 1])
      x.d = rng.randn(*x.shape)
      t.d = rng.randint(0, 5, size=t.shape)
  
      nn.set_default_context(nn.Context())
  
      # Forwardprop by definition
      nn.clear_parameters()
      if model == "mlp":
          with nn.parameter_scope("fc1"):
              z = PF.affine(x, 3)
          z2 = F.relu(z, inplace=True)
          with nn.parameter_scope("fc2"):
              z3 = PF.affine(z2, 5)
              z4 = PF.affine(z2, 5)
      elif model == "recurrent":
          with nn.parameter_scope("fc1"):
              z = PF.affine(x, 4)
              z2 = F.relu(z, inplace=True)
          h = z2
          for _ in range(2):
              with nn.parameter_scope("fc2"):
                  h = PF.affine(h, 4)
                  h = F.relu(h, inplace=True)
          with nn.parameter_scope("fc3"):
              z3 = PF.affine(h, 5)
              z4 = PF.affine(h, 5)
      elif model == "convolution":
          with nn.parameter_scope("conv1"):
              z = PF.convolution(x, 3, (2, 2))
              z2 = F.relu(z, inplace=True)
          with nn.parameter_scope("fc2"):
              z3 = PF.affine(z2, 5)
              z4 = PF.affine(z2, 5)
      else:
          raise ValueError()
      l1 = F.softmax_cross_entropy(z3, t, 1)
      L1 = F.mean(l1)
      l2 = F.softmax_cross_entropy(z4, t, 1)
      L2 = F.mean(l2)
  
      # Forwardprop
      nn.forward_all([L1, L2])
  
      parameters = nn.get_parameters()
  
      # Backprop for L1
      # Diff should be initialized since they are always accumulated
      x.grad.zero()
      initialize_grad(parameters)
      L1.backward(clear_buffer=True)
      inputs = [x] + list(parameters.values())
  
      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=1.05e-2)
  
      # Backprop for L2
      # Diff should be initialized since they are always accumulated
      x.grad.zero()
      initialize_grad(parameters)
      L2.backward(clear_buffer=True)
      inputs = [x] + list(parameters.values())
  
      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=1.05e-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 3 for calling a global function with example usage: test_graph_model(model, seed) without return types