code: def _sequential_logmatmulexp(logits):
      """
      For a tensor ``x`` whose time dimension is -3, computes::
  
          x[..., 0, :, :] @ x[..., 1, :, :] @ ... @ x[..., T-1, :, :]
  
      but does so numerically stably in log space.
      """
      batch_shape = logits.shape[:-3]
      state_dim = logits.size(-1)
      while logits.size(-3) > 1:
          time = logits.size(-3)
          even_time = time // 2 * 2
          even_part = logits[..., :even_time, :, :]
          x_y = even_part.reshape(
              batch_shape + (even_time // 2, 2, state_dim, state_dim)
          )
          x, y = x_y.unbind(-3)
          contracted = _logmatmulexp(x, y)
          if time > even_time:
              contracted = torch.cat(
                  (contracted, logits[..., -1:, :, :]), dim=-3
              )
          logits = contracted
      return logits.squeeze(-3)
  
imports: import torch
  import torch.nn.functional
  from pyro.ops.gamma_gaussian import GammaGaussian, gamma_and_mvn_to_gamma_gaussian, gamma_gaussian_tensordot, matrix_and_mvn_to_gamma_gaussian
  from pyro.ops.gaussian import Gaussian, gaussian_tensordot, matrix_and_mvn_to_gaussian, mvn_to_gaussian, sequential_gaussian_filter_sample, sequential_gaussian_tensordot
  from pyro.ops.indexing import Vindex
  from pyro.ops.special import safe_log
  from pyro.ops.tensor_utils import cholesky_solve, safe_cholesky
  from .None import constraints
  from .torch import Categorical, Gamma, Independent, MultivariateNormal
  from .torch_distribution import TorchDistribution
  from .util import broadcast_shape, torch_jit_script_if_tracing
label_desc: Use image node_id 3 for calling a global function with example usage: _sequential_logmatmulexp(logits) and returns: logits