code: def _log_factorial_sum(x: torch.Tensor) -> torch.Tensor:
      if x.requires_grad:
          return (x + 1).lgamma().sum()
      key = id(x)
      if key not in _log_factorial_cache:
          weakref.finalize(x, _log_factorial_cache.pop, key, None)  # type: ignore
          _log_factorial_cache[key] = (x + 1).lgamma().sum()
      return _log_factorial_cache[key]
  
file_path: pyro/pyro/ops/special.py
imports: import functools
  import math
  import operator
  import weakref
  from typing import Dict
  import numpy
  import torch
  from numpy.polynomial.hermite import hermgauss
label_desc: Use image node_id 7 for calling a global function with example usage: _log_factorial_sum(x) and returns: _log_factorial_cache, unknown