code: def test_pf_multi_head_attention_execution(
      g_rng,
      src_len,
      tgt_len,
      batch_size,
      q_input_dim,
      k_input_dim,
      v_input_dim,
      k_embed_dim,
      v_embed_dim,
      out_dim,
      num_heads,
      dropout,
      rng,
      with_bias,
      add_attn_bias,
      fix_parameters,
      param_init,
      ctx,
      func_name,
  ):
      q_shape = (q_input_dim, k_embed_dim)
      k_shape = (k_input_dim, k_embed_dim)
      v_shape = (v_input_dim, v_embed_dim)
      o_shape = (v_embed_dim, out_dim)
  
      q_weight = process_param_init(
          I.NormalInitializer(), q_shape, g_rng
      )
      k_weight = process_param_init(
          I.NormalInitializer(), k_shape, g_rng
      )
      v_weight = process_param_init(
          I.NormalInitializer(), v_shape, g_rng
      )
      out_weight = process_param_init(
          I.NormalInitializer(), o_shape, g_rng
      )
  
      param_init = dict(
          q_weight=q_weight,
          k_weight=k_weight,
          v_weight=v_weight,
          out_weight=out_weight,
      )
  
      if with_bias:
          qb_shape = (k_embed_dim,)
          kb_shape = (k_embed_dim,)
          vb_shape = (v_embed_dim,)
          ob_shape = (out_dim,)
          q_bias = process_param_init(
              I.ConstantInitializer(), qb_shape, g_rng
          )
          k_bias = process_param_init(
              I.ConstantInitializer(), kb_shape, g_rng
          )
          v_bias = process_param_init(
              I.ConstantInitializer(), vb_shape, g_rng
          )
          out_bias = process_param_init(
              I.ConstantInitializer(), ob_shape, g_rng
          )
  
          param_init["q_bias"] = q_bias
          param_init["k_bias"] = k_bias
          param_init["v_bias"] = v_bias
          param_init["out_bias"] = out_bias
  
      if add_attn_bias:
          attnk_shape = (1, 1, k_embed_dim)
          attnv_shape = (1, 1, v_embed_dim)
          attn_bias_k = process_param_init(
              I.NormalInitializer(), attnk_shape, g_rng
          )
          attn_bias_v = process_param_init(
              I.NormalInitializer(), attnv_shape, g_rng
          )
  
          param_init["attn_bias_k"] = attn_bias_k
          param_init["attn_bias_v"] = attn_bias_v
  
      rng = process_rng(rng)
  
      kw = {}
      insert_if_not_none(kw, "num_heads", num_heads)
      insert_if_not_default(kw, "dropout", dropout, 0.0)
      insert_if_not_none(kw, "k_embed_dim", k_embed_dim)
      insert_if_not_none(kw, "v_embed_dim", v_embed_dim)
      insert_if_not_none(kw, "out_dim", out_dim)
      insert_if_not_none(kw, "rng", rng)
      insert_if_not_default(kw, "with_bias", with_bias, True)
      insert_if_not_default(kw, "add_attn_bias", add_attn_bias, False)
      insert_if_not_default(kw, "fix_parameters", fix_parameters, False)
      insert_if_not_none(kw, "param_init", param_init)
  
      q = nn.Variable.from_numpy_array(
          g_rng.randn(tgt_len, batch_size, q_input_dim).astype(
              np.float32
          ),
          need_grad=True,
      )
      k = nn.Variable.from_numpy_array(
          g_rng.randn(src_len, batch_size, k_input_dim).astype(
              np.float32
          ),
          need_grad=True,
      )
      v = nn.Variable.from_numpy_array(
          g_rng.randn(src_len, batch_size, v_input_dim).astype(
              np.float32
          ),
          need_grad=True,
      )
  
      # Check execution
      y, w = PF.multi_head_attention(q, k, v, **kw)
      y.forward()
      y.backward()
  
      if with_bias:
          if add_attn_bias:
              assert len(nn.get_parameters()) == 10
          else:
              assert len(nn.get_parameters()) == 8
      else:
          if add_attn_bias:
              assert len(nn.get_parameters()) == 6
          else:
              assert len(nn.get_parameters()) == 4
  
      if with_bias:
          if add_attn_bias:
              qw, kw, vw, ow, qb, kb, vb, ob, abk, abv = [
                  nn.get_parameters(grad_only=False)[
                      "multi_head_attention/" + name
                  ]
                  for name in [
                      "q_weight",
                      "k_weight",
                      "v_weight",
                      "out_weight",
                      "q_bias",
                      "k_bias",
                      "v_bias",
                      "out_bias",
                      "attn_bias_k",
                      "attn_bias_v",
                  ]
              ]
          else:
              qw, kw, vw, ow, qb, kb, vb, ob = [
                  nn.get_parameters(grad_only=False)[
                      "multi_head_attention/" + name
                  ]
                  for name in [
                      "q_weight",
                      "k_weight",
                      "v_weight",
                      "out_weight",
                      "q_bias",
                      "k_bias",
                      "v_bias",
                      "out_bias",
                  ]
              ]
      else:
          if add_attn_bias:
              qw, kw, vw, ow, abk, abv = [
                  nn.get_parameters(grad_only=False)[
                      "multi_head_attention/" + name
                  ]
                  for name in [
                      "q_weight",
                      "k_weight",
                      "v_weight",
                      "out_weight",
                      "attn_bias_k",
                      "attn_bias_v",
                  ]
              ]
          else:
              qw, kw, vw, ow = [
                  nn.get_parameters(grad_only=False)[
                      "multi_head_attention/" + name
                  ]
                  for name in [
                      "q_weight",
                      "k_weight",
                      "v_weight",
                      "out_weight",
                  ]
              ]
  
      assert qw.shape == q_shape
      assert kw.shape == k_shape
      assert vw.shape == v_shape
      assert ow.shape == o_shape
      assert qw.need_grad
      assert kw.need_grad
      assert vw.need_grad
      assert ow.need_grad
  
      if with_bias:
          assert qb.shape == qb_shape
          assert kb.shape == kb_shape
          assert vb.shape == vb_shape
          assert ob.shape == ob_shape
          assert qb.need_grad
          assert kb.need_grad
          assert vb.need_grad
          assert ob.need_grad
  
      if add_attn_bias:
          assert abk.shape == attnk_shape
          assert abv.shape == attnv_shape
          assert abk.need_grad
          assert abv.need_grad
  
imports: import pytest
  import numpy
  import nnabla
  import nnabla.functions
  import nnabla.parametric_functions
  import nnabla.initializer
  from nnabla.testing import assert_allclose
  from nbla_test_utils import list_context
label_desc: Use image node_id 27 for calling a global function with example usage: test_pf_multi_head_attention_execution(g_rng, src_len, tgt_len, batch_size, q_input_dim, k_input_dim, v_input_dim, k_embed_dim, v_embed_dim, out_dim, num_heads, dropout, rng, with_bias, add_attn_bias, fix_parameters, param_init, ctx, func_name) without return types