code: def sum_rightmost(value, dim):
      """
      Sum out ``dim`` many rightmost dimensions of a given tensor.
  
      If ``dim`` is 0, no dimensions are summed out.
      If ``dim`` is ``float('inf')``, then all dimensions are summed out.
      If ``dim`` is 1, the rightmost 1 dimension is summed out.
      If ``dim`` is 2, the rightmost two dimensions are summed out.
      If ``dim`` is -1, all but the leftmost 1 dimension is summed out.
      If ``dim`` is -2, all but the leftmost 2 dimensions are summed out.
      etc.
  
      :param torch.Tensor value: A tensor of ``.dim()`` at least ``dim``.
      :param int dim: The number of rightmost dims to sum out.
      """
      if isinstance(value, numbers.Number):
          return value
      if dim < 0:
          dim += value.dim()
      if dim == 0:
          return value
      if dim >= value.dim():
          return value.sum()
      return value.reshape(value.shape[:-dim] + (-1,)).sum(-1)
  
imports: import copy
  import ctypes
  import functools
  import numbers
  import weakref
  from contextlib import contextmanager
  import torch
  import torch.distributions
  from torch import logsumexp
  from torch.distributions.utils import broadcast_all
  from pyro.util import ignore_jit_warnings
  from ..None import settings
label_desc: Use image node_id 9 for calling a global function with example usage: sum_rightmost(value, dim) and returns: value, value, value, value