code: def sum_leftmost(value, dim):
      """
      Sum out ``dim`` many leftmost 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 leftmost 1 dimension is summed out.
      If ``dim`` is 2, the leftmost two dimensions are summed out.
      If ``dim`` is -1, all but the rightmost 1 dimension is summed out.
      If ``dim`` is -2, all but the rightmost 2 dimensions are summed out.
      etc.
  
      Example::
  
          x = torch.ones(2, 3, 4)
          assert sum_leftmost(x, 1).shape == (3, 4)
          assert sum_leftmost(x, -1).shape == (4,)
  
      :param torch.Tensor value: A tensor
      :param int dim: Specifies the number of 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(-1, *value.shape[dim:]).sum(0)
  
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 10 for calling a global function with example usage: sum_leftmost(value, dim) and returns: value, value, value, value