code: def _check_backward(
      fprop, xs, expected_gxs, gys=None, backprop_id=None
  ):
      # Checks for test validity.
      assert callable(fprop)
      assert isinstance(xs, tuple)
      assert isinstance(expected_gxs, tuple)
      assert len(xs) == len(expected_gxs)
      assert all([isinstance(a, chainerx.ndarray) for a in xs])
      assert all(
          [
              isinstance(a, chainerx.ndarray) or a is None
              for a in expected_gxs
          ]
      )
  
      # Forward.
      ys = fprop(*xs)
  
      # Set output gradients.
      if gys is not None:
          assert len(gys) == len(ys)
          for y, gy in zip(ys, gys):
              assert not y.is_grad_required()
              y.set_grad(gy, backprop_id)
  
      # Backward.
      chainerx.backward(ys, backprop_id)
  
      # Check gradients of input arrays.
      for x, expected_gx in zip(xs, expected_gxs):
          if expected_gx is None:
              with pytest.raises(chainerx.ChainerxError):
                  x.get_grad(backprop_id)
          else:
              gx = x.get_grad(backprop_id)
              _assert_arrays_equal(gx, expected_gx)
  
      # Check gradients of output arrays.
      if gys is None:
          gys = (None,) * len(xs)
      for y, gy in zip(ys, gys):
          if gy is None:
              assert not y.is_grad_required(backprop_id)
              with pytest.raises(chainerx.ChainerxError):
                  y.get_grad(backprop_id)
          else:
              assert y.is_grad_required(backprop_id)
              _assert_arrays_equal(gy, y.get_grad(backprop_id))
  
imports: import chainerx
  import pytest
label_desc: Use image node_id 2 for calling a global function with example usage: _check_backward(fprop, xs, expected_gxs, gys, backprop_id) without return types