code: def apply(self, logits: Tensor, tokens: Tensor):
      # suppress <|notimestamps|> which is handled by without_timestamps
      if self.tokenizer.no_timestamps is not None:
          logits[:, self.tokenizer.no_timestamps] = -np.inf
  
      # timestamps have to appear in pairs, except directly before EOT; mask logits accordingly
      for k in range(tokens.shape[0]):
          sampled_tokens = tokens[k, self.sample_begin :]
          seq = [t for t in sampled_tokens.tolist()]
          last_was_timestamp = (
              len(seq) >= 1
              and seq[-1] >= self.tokenizer.timestamp_begin
          )
          penultimate_was_timestamp = (
              len(seq) < 2 or seq[-2] >= self.tokenizer.timestamp_begin
          )
  
          if last_was_timestamp:
              if penultimate_was_timestamp:  # has to be non-timestamp
                  logits[k, self.tokenizer.timestamp_begin :] = -np.inf
              else:  # cannot be normal text tokens
                  logits[k, : self.tokenizer.eot] = -np.inf
  
          timestamps = sampled_tokens[
              sampled_tokens.ge(self.tokenizer.timestamp_begin)
          ]
          if timestamps.numel() > 0:
              # timestamps shouldn't decrease; forbid timestamp tokens smaller than the last
              # also force each segment to have a nonzero length, to prevent infinite looping
              if last_was_timestamp and not penultimate_was_timestamp:
                  timestamp_last = timestamps[-1]
              else:
                  timestamp_last = timestamps[-1] + 1
              logits[
                  k, self.tokenizer.timestamp_begin : timestamp_last
              ] = -np.inf
  
      if tokens.shape[1] == self.sample_begin:
          # suppress generating non-timestamp tokens at the beginning
          logits[:, : self.tokenizer.timestamp_begin] = -np.inf
  
          # apply the `max_initial_timestamp` option
          if self.max_initial_timestamp_index is not None:
              last_allowed = (
                  self.tokenizer.timestamp_begin
                  + self.max_initial_timestamp_index
              )
              logits[:, last_allowed + 1 :] = -np.inf
  
      # if sum of probability over timestamps is above any other token, sample timestamp
      logprobs = F.log_softmax(logits.float(), dim=-1)
      for k in range(tokens.shape[0]):
          timestamp_logprob = logprobs[
              k, self.tokenizer.timestamp_begin :
          ].logsumexp(dim=-1)
          max_text_token_logprob = logprobs[
              k, : self.tokenizer.timestamp_begin
          ].max()
          if timestamp_logprob > max_text_token_logprob:
              logits[k, : self.tokenizer.timestamp_begin] = -np.inf
  
imports: from dataclasses import dataclass, field, replace
  from typing import TYPE_CHECKING, Dict, Iterable, List, Optional, Sequence, Tuple, Union
  import numpy
  import torch
  import torch.nn.functional
  from torch import Tensor
  from torch.distributions import Categorical
  from .audio import CHUNK_LENGTH
  from .tokenizer import Tokenizer, get_tokenizer
  from .utils import compression_ratio
label_desc: Use image node_id 2 for calling the ApplyTimestampRules obj's underlying member method code with example usage: obj.apply(logits, tokens) without return types