code: def gumbel_softmax(logits, tau=1, hard=False, eps=1e-10, dim=-1):
      gumbels = -ivy.empty_like(logits).exponential().log()
      gumbels = (logits + gumbels) / tau
      y_soft = ivy.softmax(gumbels, axis=dim)
  
      if hard:
          indices = y_soft.max(axis=dim, keepdims=True)[1]
          y_hard = ivy.zeros_like(logits)
          updates = ivy.ones_like(indices)
          y_hard = ivy.scatter_nd(
              indices, updates, reduction="replace", out=y_hard
          )
  
          ret = (
              y_hard - y_soft.stop_gradient(preserve_type=True) + y_soft
          )
      else:
          ret = y_soft
  
      return ret
  
imports: import ivy
  from ivy.func_wrapper import with_unsupported_dtypes, with_supported_dtypes
  from ivy.functional.frontends.torch.func_wrapper import to_ivy_arrays_and_back
label_desc: Use image node_id 7 for calling a global function with example usage: gumbel_softmax(logits, tau, hard, eps, dim) and returns: ret