code: def test_backward(
      input_shape, input_dim, dtype, indices_dtype, combiner
  ):
      indices = np.random.randint(
          low=0, high=input_dim, size=input_shape
      ).astype(indices_dtype)
      params = np.random.random(size=(input_dim, 16)).astype(dtype)
      if combiner == "sum":
          weights = np.random.random(size=indices.shape).astype(dtype)
      else:
          weights = None
  
      indices = tf.convert_to_tensor(indices)
      params = tf.convert_to_tensor(params)
      if weights is not None:
          weights = tf.convert_to_tensor(weights)
  
      embedding_bag_fn = tf.function(_embedding_bag)
  
      if combiner == "sum":
          with tf.GradientTape(persistent=True) as tape:
              tape.watch([params, weights])
              output = embedding_bag_fn(
                  indices, params, weights, combiner="sum"
              )
              expected = manual_embedding_bag(
                  indices, params, weights, combiner="sum"
              )
  
          grads = tape.gradient(output, [params, weights])
          expected_grads = tape.gradient(expected, [params, weights])
          # Gather returns sparse IndexedSlices so we have to sum them together.
          test_utils.assert_allclose_according_to_type(
              tf.convert_to_tensor(expected_grads[0]),
              tf.convert_to_tensor(grads[0]),
              half_rtol=1e-2,
              half_atol=1e-2,
          )
          test_utils.assert_allclose_according_to_type(
              expected_grads[1],
              grads[1],
              half_rtol=1e-2,
              half_atol=1e-2,
          )
      else:
          with tf.GradientTape(persistent=True) as tape:
              tape.watch(params)
              output = embedding_bag_fn(
                  indices, params, combiner=combiner
              )
              expected = manual_embedding_bag(
                  indices, params, combiner=combiner
              )
  
          grads = tape.gradient(output, [params])
          expected_grads = tape.gradient(expected, [params])
          # Gather returns sparse IndexedSlices so we have to sum them together.
          test_utils.assert_allclose_according_to_type(
              tf.convert_to_tensor(expected_grads[0]),
              tf.convert_to_tensor(grads[0]),
              half_rtol=1e-2,
              half_atol=1e-2,
          )
  
file_path: addons/tensorflow_addons/layers/tests/embedding_bag_test.py
imports: import pytest
  import numpy
  import tensorflow
  from tensorflow_addons.layers.embedding_bag import EmbeddingBag, _embedding_bag
  from tensorflow_addons.utils import test_utils
label_desc: Use image node_id 3 for calling a global function with example usage: test_backward(input_shape, input_dim, dtype, indices_dtype, combiner) without return types