code: def _bincount(x: Tensor, minlength: Optional[int] = None) -> Tensor:
      """Implement custom bincount.
  
      PyTorch currently does not support ``torch.bincount`` when running in deterministic mode on GPU or when running
      MPS devices or when running on XLA device. This implementation therefore falls back to using a combination of
      `torch.arange` and `torch.eq` in these scenarios. A small performance hit can expected and higher memory consumption
      as `[batch_size, mincount]` tensor needs to be initialized compared to native ``torch.bincount``.
  
      Args:
          x: tensor to count
          minlength: minimum length to count
  
      Returns:
          Number of occurrences for each unique element in x
  
      Example:
          >>> x = torch.tensor([0,0,0,1,1,2,2,2,2])
          >>> _bincount(x, minlength=3)
          tensor([3, 2, 4])
  
      """
      if minlength is None:
          minlength = len(torch.unique(x))
  
      if (
          torch.are_deterministic_algorithms_enabled()
          or _XLA_AVAILABLE
          or _TORCH_GREATER_EQUAL_1_12
          and x.is_mps
      ):
          mesh = torch.arange(minlength, device=x.device).repeat(
              len(x), 1
          )
          return torch.eq(x.reshape(-1, 1), mesh).sum(dim=0)
  
      return torch.bincount(x, minlength=minlength)
  
imports: import sys
  from typing import Any, Dict, List, Optional, Sequence, Tuple, Union
  import torch
  from lightning_utilities import apply_to_collection
  from torch import Tensor
  from torchmetrics.utilities.exceptions import TorchMetricsUserWarning
  from torchmetrics.utilities.imports import _TORCH_GREATER_EQUAL_1_12, _TORCH_GREATER_EQUAL_1_13, _XLA_AVAILABLE
  from torchmetrics.utilities.prints import rank_zero_warn
label_desc: Use image node_id 14 for calling a global function with example usage: _bincount(x, minlength) and returns: torch, torch