code: def logsumexp(
      x: Tensor, dim: Union[int, Tuple[int, ...]], keepdim: bool = False
  ) -> Tensor:
      """Version of logsumexp that has a well-behaved backward pass when
      x contains infinities.
  
      In particular, the gradient of the standard torch version becomes NaN
      1) for any element that is positive infinity, and 2) for any slice that
      only contains negative infinities.
  
      This version returns a gradient of 1 for any positive infinities in case 1, and
      for all elements of the slice in case 2, in agreement with the asymptotic behavior
      of the function.
  
      Args:
          x: The Tensor to which to apply `logsumexp`.
          dim: An integer or a tuple of integers, representing the dimensions to reduce.
          keepdim: Whether to keep the reduced dimensions. Defaults to False.
  
      Returns:
          A Tensor representing the log of the summed exponentials of `x`.
      """
      return _inf_max_helper(
          torch.logsumexp, x=x, dim=dim, keepdim=keepdim
      )
  
imports: from __future__ import annotations
  import math
  from typing import Callable, Tuple, Union
  import torch
  from botorch.exceptions import UnsupportedError
  from botorch.utils.constants import get_constants_like
  from torch import finfo, Tensor
  from torch.nn.functional import softplus
label_desc: Use image node_id 12 for calling a global function with example usage: logsumexp(x, dim, keepdim) and returns: _inf_max_helper