code: def compute_betas_kernel(
      acts: torch.Tensor,
      denom: torch.Tensor,
      betas: torch.Tensor,
      llBackward: torch.Tensor,
      xlen: torch.Tensor,
      ylen: torch.Tensor,
      mlabels: torch.Tensor,  # [B, U]
      minibatch: int,
      maxT: int,
      maxU: int,
      alphabet_size: int,
      blank_: int,
  ):
      """
      Compute beta (backward variable) probabilities over the transduction step.
  
      Args:
          acts: Tensor of shape [B, T, U, V+1] flattened.
              Represents the logprobs activation tensor.
          denom: Tensor of shape [B, T, U] flattened. Represents the denominator
              of the logprobs activation tensor across entire vocabulary.
          betas: Zero tensor of shape [B, T, U]. Will be updated inside the kernel
              with the backward variable probabilities.
          llBackward: Zero tensor of shape [B]. Represents the log-likelihood
              of the backward pass. Returned as the backward pass loss that
              is reduced by the optimizer.
          xlen: Vector of length B which contains the actual acoustic
              sequence lengths in the padded activation tensor.
          ylen: Vector of length B which contains the actual target sequence
              lengths in the padded activation tensor.
          mlabels: Matrix of shape [B, U+1] (+1 here is due to <SOS> token
              - usually the RNNT blank). The matrix contains the padded target
              transcription that must be predicted.
          minibatch: Int representing the batch size.
          maxT: The maximum possible acoustic sequence length.
              Represents T in the logprobs tensor.
          maxU: The maximum possible target sequence length.
              Represents U in the logprobs tensor.
          alphabet_size: The vocabulary dimension V+1 (inclusive of RNNT blank).
          blank_: Index of the RNNT blank token in the vocabulary.
              Generally the first or last token in the vocab.
  
      Updates:
          Kernel inplace updates the following inputs:
          -   betas: backward variable scores.
          -   llBackward: log-likelihood of backward variable.
      """
  
      # // launch B blocks, each block has U threads
      b = cuda.blockIdx.x  # // batch id
      u = cuda.threadIdx.x  # label id, u
      T = xlen[b]  # select AM length of current sample
      U = (
          ylen[b] + 1
      )  # select target length of current sample, +1 for the blank token
  
      labels: torch.Tensor = mlabels[
          b
      ]  # mb label start point, equivalent to mlabels + b * (maxU - 1)
      offset = b * maxT * maxU  # pointer indexing offset
  
      # betas += offset # pointer offset, ignored since we explicitly add offset
  
      # Initilize beta[b, t=T-1, u=U-1] for all b in B
      # with log_probs[b, t=T-1, u=U-1, blank]
      if u == 0:
          betas[offset + (T - 1) * maxU + U - 1] = logp(
              denom,
              acts,
              maxT,
              maxU,
              alphabet_size,
              b,
              T - 1,
              U - 1,
              blank_,
          )
  
      # sync until all betas are initialized
      cuda.syncthreads()
  
      # Ordinary beta calculations, broadcast across B=b and U=u
      # Look up backward variable calculation from rnnt_numpy.backward_pass()
      for n in range(T + U - 2, -1, -1):
          t = n - u
  
          if u == (U - 1):
              # for t in reversed(range(T - 1)) step to initialize betas[b, t, U-1]
              if t >= 0 and t < (T - 1):
                  betas[offset + t * maxU + U - 1] = betas[
                      offset + (t + 1) * maxU + U - 1
                  ] + logp(
                      denom,
                      acts,
                      maxT,
                      maxU,
                      alphabet_size,
                      b,
                      t,
                      U - 1,
                      blank_,
                  )
          elif u < U:
              if t == T - 1:
                  # for u in reversed(range(U - 1)) step to initialize betas[b, T-1, u]
                  betas[offset + (T - 1) * maxU + u] = betas[
                      offset + (T - 1) * maxU + u + 1
                  ] + logp(
                      denom,
                      acts,
                      maxT,
                      maxU,
                      alphabet_size,
                      b,
                      T - 1,
                      u,
                      labels[u],
                  )
              elif (t >= 0) and (t < T - 1):
                  # for t in reversed(range(T - 1)) for u in reversed(range(U - 1))
                  # step to compute betas[b, t, u]
                  no_emit = betas[offset + (t + 1) * maxU + u] + logp(
                      denom,
                      acts,
                      maxT,
                      maxU,
                      alphabet_size,
                      b,
                      t,
                      u,
                      blank_,
                  )
                  emit = betas[offset + t * maxU + u + 1] + logp(
                      denom,
                      acts,
                      maxT,
                      maxU,
                      alphabet_size,
                      b,
                      t,
                      u,
                      labels[u],
                  )
                  betas[
                      offset + t * maxU + u
                  ] = rnnt_helper.log_sum_exp(emit, no_emit)
  
          # sync across all B=b and U=u
          cuda.syncthreads()
  
      # After final sync, betas[b, 0, 0] gives
      # log-likelihood of backward pass.
      if u == 0:
          llBackward[b] = betas[offset]
  
file_path: espnet/espnet2/asr/transducer/rnnt_multi_blank/utils/cuda_utils/gpu_rnnt_kernel.py
imports: import math
  import torch
  from numba import cuda
  from espnet2.asr.transducer.rnnt_multi_blank.utils import rnnt_helper
label_desc: Use image node_id 3 for calling a global function with example usage: compute_betas_kernel(acts, denom, betas, llBackward, xlen, ylen, mlabels, minibatch, maxT, maxU, alphabet_size, blank_) without return types