code: def randomized_argmax(x: torch.Tensor) -> int:
      """
      Like argmax, but return a random (uniformly) index of the max element
      This function makes sense only if there are ties for the max element
      """
      if torch.isinf(x).any():
          # if some scores are inf, return the index for one of the infs
          best_indices = torch.nonzero(torch.isinf(x)).squeeze()
      else:
          max_value = torch.max(x)
          best_indices = torch.nonzero(x == max_value).squeeze()
      if best_indices.ndim == 0:
          # if there is a single argmax
          chosen_idx = int(best_indices)
      else:
          chosen_idx = int(
              best_indices[
                  torch.multinomial(
                      1.0
                      / len(best_indices)
                      * torch.ones(len(best_indices)),
                      1,
                  )[0]
              ]
          )
      return chosen_idx
  
imports: from abc import ABC, abstractmethod
  from typing import List, Optional, Tuple
  import torch
  from torch import Tensor
label_desc: Use image node_id 4 for calling a global function with example usage: randomized_argmax(x) and returns: chosen_idx