code: def multinomial(
      population_size: int,
      num_samples: int,
      /,
      *,
      batch_size: int = 1,
      probs: Optional[Union[tf.Tensor, tf.Variable]] = None,
      replace: bool = True,
      device: Optional[str] = None,
      seed: Optional[int] = None,
      out: Optional[Union[tf.Tensor, tf.Variable]] = None,
  ) -> Union[tf.Tensor, tf.Variable]:
      if probs is None:
          probs = (
              tf.ones(
                  (
                      batch_size,
                      population_size,
                  )
              )
              / population_size
          )
  
      # We set the global seed, but not the operation seeds below. In this way, we
      # get different results for every random op call but the same sequence for
      # every re-run of the program
      if seed:
          tf.random.set_seed(seed)
  
      if not replace:
          orig_probs_shape = list(probs.shape)
          probs_flat = tf.reshape(probs, (-1, orig_probs_shape[-1]))
          probs_flat = probs_flat / tf.math.reduce_sum(
              probs_flat, axis=-1, keepdims=True
          )
          probs_stack = tf.split(probs_flat, probs_flat.shape[0])
          samples_stack = []
          for prob in probs_stack:
              logits = tf.dtypes.cast(tf.math.log(prob), tf.float64)
              # Gumbel-max trick
              # https://github.com/tensorflow/tensorflow/issues/9260
              z = tf.dtypes.cast(
                  -tf.math.log(
                      -tf.math.log(
                          tf.random.uniform(tf.shape(logits), 0, 1)
                      )
                  ),
                  tf.float64,
              )
              _, indices = tf.nn.top_k(logits + z, k=num_samples)
              samples_stack.append(indices)
          samples_flat = tf.stack(samples_stack)
          return tf.convert_to_tensor(
              tf.reshape(
                  samples_flat, orig_probs_shape[:-1] + [num_samples]
              )
          )
      else:
          if len(probs.numpy().shape) == 1:
              probs = tf.expand_dims(probs, axis=0)
          return tf.random.categorical(tf.math.log(probs), num_samples)
  
file_path: ivy/ivy/functional/backends/tensorflow/random.py
imports: from typing import Optional, Union, Sequence
  import tensorflow
  from tensorflow.python.framework.dtypes import DType
  import ivy
  from ivy.func_wrapper import with_unsupported_dtypes, with_supported_dtypes
  from ivy.functional.ivy.random import _check_bounds_and_get_shape, _randint_check_dtype_and_bound, _check_valid_scale
  from .None import backend_version
label_desc: Use image node_id 3 for calling a global function with example usage: multinomial() and returns: tf, tf