code: def _mha_helper(draw, same_pre_embed_dim=False, batch_second=False):
      _qkv_same_dim = draw(st.booleans())
      _self_attention = draw(st.booleans())
      _same_pre_embed_dim = (
          _self_attention or same_pre_embed_dim or draw(st.booleans())
      )
      batch_first = draw(st.booleans()) and not batch_second
      num_heads = draw(helpers.ints(min_value=1, max_value=3))
      _embed_dim = (
          draw(helpers.ints(min_value=4, max_value=16)) * num_heads
      )
      _batch_dim = draw(st.sampled_from([(), (1,)]))
      _num_batches = _batch_dim[0] if len(_batch_dim) else 1
      dtype = draw(helpers.get_dtypes("valid", full=False))
      _num_queries = draw(helpers.ints(min_value=2, max_value=8))
      _num_keys = draw(helpers.ints(min_value=2, max_value=8))
      in_proj_weights = None
      q_proj_weights = None
      k_proj_weights = None
      v_proj_weights = None
  
      if _qkv_same_dim:
          if _same_pre_embed_dim:
              _pre_embed_dim = _embed_dim
          else:
              _pre_embed_dim = draw(
                  helpers.ints(min_value=4, max_value=16)
              )
          q = draw(
              helpers.array_values(
                  shape=(*_batch_dim, _num_queries, _pre_embed_dim),
                  dtype=dtype[0],
                  max_value=1000,
                  min_value=-1000,
                  abs_smallest_val=1e-06,
              )
          )
          k = draw(
              helpers.array_values(
                  shape=(*_batch_dim, _num_keys, _pre_embed_dim),
                  dtype=dtype[0],
                  max_value=1000,
                  min_value=-1000,
                  abs_smallest_val=1e-06,
              )
              if not _self_attention
              else st.none()
          )
          v = draw(
              helpers.array_values(
                  shape=(*_batch_dim, _num_keys, _pre_embed_dim),
                  dtype=dtype[0],
                  max_value=1000,
                  min_value=-1000,
                  abs_smallest_val=1e-06,
              )
              if not _self_attention
              else st.none()
          )
          in_proj_weights = draw(
              helpers.array_values(
                  dtype=dtype[0],
                  shape=(3 * _embed_dim, _pre_embed_dim),
                  min_value=-10,
                  max_value=10,
              )
              if not _same_pre_embed_dim or draw(st.booleans())
              else st.none()
          )
      else:
          if not same_pre_embed_dim:
              _q_dim = draw(helpers.ints(min_value=2, max_value=8))
          else:
              _q_dim = _embed_dim
          _k_dim = draw(helpers.ints(min_value=2, max_value=8))
          _v_dim = draw(helpers.ints(min_value=2, max_value=8))
          q = draw(
              helpers.array_values(
                  shape=(*_batch_dim, _num_queries, _q_dim),
                  dtype=dtype[0],
                  max_value=1000,
                  min_value=-1000,
                  abs_smallest_val=1e-06,
              )
          )
          k = draw(
              helpers.array_values(
                  shape=(*_batch_dim, _num_keys, _k_dim),
                  dtype=dtype[0],
                  max_value=1000,
                  min_value=-1000,
                  abs_smallest_val=1e-06,
              )
          )
          v = draw(
              helpers.array_values(
                  shape=(*_batch_dim, _num_keys, _v_dim),
                  dtype=dtype[0],
                  max_value=1000,
                  min_value=-1000,
                  abs_smallest_val=1e-06,
              )
          )
          q_proj_weights = draw(
              helpers.array_values(
                  dtype=dtype[0],
                  shape=(_embed_dim, _q_dim),
                  min_value=-5,
                  max_value=5,
              )
          )
          k_proj_weights = draw(
              helpers.array_values(
                  dtype=dtype[0],
                  shape=(_embed_dim, _k_dim),
                  min_value=-5,
                  max_value=5,
              )
          )
          v_proj_weights = draw(
              helpers.array_values(
                  dtype=dtype[0],
                  shape=(_embed_dim, _v_dim),
                  min_value=-5,
                  max_value=5,
              )
          )
      in_proj_bias = draw(
          st.one_of(
              helpers.array_values(
                  dtype=dtype[0],
                  shape=(3 * _embed_dim,),
                  min_value=-10,
                  max_value=10,
              ),
              st.none(),
          )
      )
  
      _out_dim = draw(helpers.ints(min_value=4, max_value=16))
      out_proj_weights = draw(
          st.one_of(
              helpers.array_values(
                  dtype=dtype[0],
                  shape=(_out_dim, _embed_dim),
                  min_value=-5,
                  max_value=5,
              ),
              st.none(),
          )
      )
      out_proj_bias = draw(
          st.one_of(
              helpers.array_values(
                  dtype=dtype[0],
                  shape=(_out_dim,),
                  min_value=-10,
                  max_value=10,
              ),
              st.none(),
          )
      )
  
      if _self_attention and _qkv_same_dim:
          _num_keys = _num_queries
      _static_shape = (
          _num_batches * num_heads,
          _num_keys,
          int(_embed_dim // num_heads),
      )
      static_k = draw(
          st.one_of(
              helpers.array_values(
                  shape=_static_shape,
                  dtype=dtype[0],
                  max_value=1000,
                  min_value=-1000,
                  abs_smallest_val=1e-06,
              ),
              st.none(),
          )
      )
      static_v = draw(
          st.one_of(
              helpers.array_values(
                  shape=_static_shape,
                  dtype=dtype[0],
                  max_value=1000,
                  min_value=-1000,
                  abs_smallest_val=1e-06,
              ),
              st.none(),
          )
      )
  
      _mask_shape = (_num_queries, _num_keys)
      if len(_batch_dim) and draw(st.booleans()):
          _mask_shape = (_num_batches * num_heads, *_mask_shape)
      attention_mask = draw(
          st.one_of(
              helpers.array_values(
                  dtype=draw(st.sampled_from(["bool", dtype[0]])),
                  allow_inf=True,
                  shape=_mask_shape,
              ),
              st.none(),
          )
      )
  
      key_padding_mask = draw(
          st.one_of(
              helpers.array_values(
                  dtype="bool",
                  shape=(*_batch_dim, _num_keys),
              ),
              st.none(),
          )
      )
  
      _extra_bias = (
          (not _qkv_same_dim or _pre_embed_dim == _embed_dim)
          and static_k is None
          and static_v is None
          and draw(st.booleans())
      )
      bias_k = draw(
          helpers.array_values(
              dtype=dtype[0],
              shape=(_embed_dim,),
              min_value=-10,
              max_value=10,
          )
          if _extra_bias
          else st.none()
      )
      bias_v = draw(
          helpers.array_values(
              dtype=dtype[0],
              shape=(_embed_dim,),
              min_value=-10,
              max_value=10,
          )
          if _extra_bias
          else st.none()
      )
  
      scale = draw(st.one_of(st.floats(min_value=0.001), st.none()))
      add_zero_attn = draw(st.booleans())
      dropout = draw(st.floats(min_value=0, max_value=0.99))
      training = draw(st.booleans())
      is_causal = draw(st.booleans())
      return_attention_weights = draw(st.booleans())
      average_attention_weights = draw(st.booleans())
  
      if len(q.shape) == 3 and not batch_first:
          q, k, v = (
              np.swapaxes(x, 0, 1) if x is not None else x
              for x in [q, k, v]
          )
  
      ret = (
          q,
          k,
          v,
          num_heads,
          attention_mask,
          in_proj_weights,
          q_proj_weights,
          k_proj_weights,
          v_proj_weights,
          out_proj_weights,
          in_proj_bias,
          out_proj_bias,
          key_padding_mask,
          bias_k,
          bias_v,
          static_k,
          static_v,
          scale,
          add_zero_attn,
          dropout,
          training,
          is_causal,
          return_attention_weights,
          average_attention_weights,
          batch_first,
      )
      ret_dtypes = [str(r.dtype) for r in ret if ivy.is_array(r)]
      return ret_dtypes, *ret
  
imports: from hypothesis import strategies, assume
  import ivy
  import numpy
  import ivy_tests.test_ivy.helpers
  from ivy_tests.test_ivy.helpers import handle_test
  from ivy.functional.ivy.layers import _deconv_length, _pack_padded_sequence
label_desc: Use image node_id 5 for calling a global function with example usage: _mha_helper(draw, same_pre_embed_dim, batch_second) and returns: ret_dtypes,  unknown