code: def get_gru_grad(
      xs_np,
      h0_np,
      w0_np,
      w_np,
      b_np,
      dy,
      dh,
      num_layers=1,
      dropout=0.0,
      bidirectional=False,
      training=True,
      **kw,
  ):
      # Inputs are numpy arrays
      num_directions = 2 if bidirectional else 1
      seq_len = xs_np.shape[0]
      batch_size = xs_np.shape[1]
      hidden_size = h0_np.shape[3]
  
      xs = nn.Variable.from_numpy_array(xs_np, need_grad=True)
      h0 = nn.Variable.from_numpy_array(h0_np, need_grad=True)
      w0 = nn.Variable.from_numpy_array(w0_np, need_grad=True)
      w = None
      b = None
      with_bias = False
      if num_layers > 1:
          w = nn.Variable.from_numpy_array(w_np, need_grad=True)
      if type(b_np) == np.ndarray:
          b = nn.Variable.from_numpy_array(b_np, need_grad=True)
          with_bias = True
      xs.grad.zero()
      h0.grad.zero()
      w0.grad.zero()
      if num_layers > 1:
          w.grad.zero()
      if with_bias:
          b.grad.zero()
  
      ys, hn = _create_fixed_length_gru(
          xs, h0, w0, w, b, num_layers, num_directions, with_bias
      )  # returns Variables
  
      dummy = F.sink(ys, hn, one_input_grad=False)
      dummy.forward()
      ys.g = np.reshape(dy, ys.shape)
      hn.g = dh
      dummy.backward()
  
      if num_layers > 1 and with_bias:
          return np.concatenate(
              (xs.g.flat, h0.g.flat, w0.g.flat, w.g.flat, b.g.flat)
          )
      elif num_layers > 1 and not with_bias:
          return np.concatenate(
              (xs.g.flat, h0.g.flat, w0.g.flat, w.g.flat)
          )
      elif num_layers == 1 and with_bias:
          return np.concatenate(
              (xs.g.flat, h0.g.flat, w0.g.flat, b.g.flat)
          )
      else:
          return np.concatenate((xs.g.flat, h0.g.flat, w0.g.flat))
  
file_path: nnabla/python/test/function/test_gru.py
imports: import pytest
  import numpy
  import nnabla
  import nnabla.functions
  from nnabla.utils.rnn import _create_fixed_length_gru
  from nbla_test_utils import list_context
label_desc: Use image node_id 2 for calling a global function with example usage: get_gru_grad(xs_np, h0_np, w0_np, w_np, b_np, dy, dh, num_layers, dropout, bidirectional, training) and returns: np, np, np, np