code: def filter(
      self, request_ids: List[int]
  ) -> Optional["Seq2SeqLMBatch"]:
      if len(request_ids) == 0:
          raise ValueError("Batch must have at least one request")
      if len(request_ids) == len(self):
          return self
  
      keep_indices = []
  
      # New values after filtering
      requests_idx_mapping = {}
      requests = []
      input_lengths = []
      decoder_input_lengths = []
      prefix_offsets = []
      read_offsets = []
  
      all_decoder_input_ids = []
  
      next_token_choosers = []
      stopping_criterias = []
      top_n_tokens = []
  
      max_input_length = 0
      max_decoder_input_length = 0
      padding_right_offset = 0
  
      total_remaining_decode_tokens = 0
  
      for i, request_id in enumerate(request_ids):
          idx = self.requests_idx_mapping[request_id]
          requests_idx_mapping[request_id] = i
          keep_indices.append(idx)
  
          requests.append(self.requests[idx])
          prefix_offsets.append(self.prefix_offsets[idx])
          read_offsets.append(self.read_offsets[idx])
  
          all_decoder_input_ids.append(self.all_decoder_input_ids[idx])
  
          request_input_length = self.input_lengths[idx]
          input_lengths.append(request_input_length)
          max_input_length = max(max_input_length, request_input_length)
  
          request_decoder_input_length = self.decoder_input_lengths[idx]
          decoder_input_lengths.append(request_decoder_input_length)
          max_decoder_input_length = max(
              max_decoder_input_length, request_decoder_input_length
          )
  
          next_token_choosers.append(self.next_token_choosers[idx])
          stopping_criteria = self.stopping_criterias[idx]
          stopping_criterias.append(stopping_criteria)
          top_n_tokens.append(self.top_n_tokens[idx])
          remaining_decode_tokens = (
              stopping_criteria.max_new_tokens
              - stopping_criteria.current_tokens
          )
          total_remaining_decode_tokens += remaining_decode_tokens
          padding_right_offset = max(
              padding_right_offset, remaining_decode_tokens
          )
  
      # Apply indices to input_ids, attention mask, past key values and other items that need to be cached
      self.decoder_input_ids = self.decoder_input_ids[keep_indices]
      self.attention_mask = self.attention_mask[
          keep_indices, -max_input_length:
      ]
      if self.decoder_attention_mask is not None:
          self.decoder_attention_mask = self.decoder_attention_mask[
              keep_indices,
              -(
                  self.padding_right_offset + max_decoder_input_length
              ) : (
                  self.decoder_attention_mask.shape[1]
                  - self.padding_right_offset
              )
              + padding_right_offset,
          ]
  
      self.encoder_last_hidden_state = self.encoder_last_hidden_state[
          keep_indices, -max_input_length:
      ]
  
      # Ensure that past_key_values tensors can be updated in-place
      if type(self.past_key_values[0]) == tuple:
          self.past_key_values = [
              [t for t in layer] for layer in self.past_key_values
          ]
  
      decoder_past_seq_len = max_decoder_input_length - 1
      for layer in self.past_key_values:
          layer[0] = layer[0][keep_indices, :, -decoder_past_seq_len:]
          layer[1] = layer[1][keep_indices, :, -decoder_past_seq_len:]
          layer[2] = layer[2][keep_indices, :, -max_input_length:]
          layer[3] = layer[3][keep_indices, :, -max_input_length:]
  
      top_n_tokens_tensor = self.top_n_tokens_tensor[keep_indices]
      max_tokens = (
          len(request_ids)
          * (max_input_length + max_decoder_input_length)
          + remaining_decode_tokens
      )
  
      self.requests = requests
      self.requests_idx_mapping = requests_idx_mapping
      self.input_ids = None
      self.all_decoder_input_ids = all_decoder_input_ids
      self.input_lengths = input_lengths
      self.decoder_input_lengths = decoder_input_lengths
      self.prefix_offsets = prefix_offsets
      self.read_offsets = read_offsets
      self.next_token_choosers = next_token_choosers
      self.stopping_criterias = stopping_criterias
      self.top_n_tokens = top_n_tokens
      self.top_n_tokens_tensor = top_n_tokens_tensor
      self.max_input_length = max_input_length
      self.max_decoder_input_length = max_decoder_input_length
      self.padding_right_offset = padding_right_offset
      self.max_tokens = max_tokens
  
      return self
  
imports: import torch
  import time
  from dataclasses import dataclass
  from opentelemetry import trace
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, PreTrainedTokenizerBase
  from typing import Optional, Tuple, List, Type, Dict
  from text_generation_server.utils.tokens import batch_top_tokens
  from text_generation_server.models import Model
  from text_generation_server.models.types import GeneratedText, Batch, Generation, Tokens
  from text_generation_server.pb import generate_pb2
  from text_generation_server.utils import NextTokenChooser, StoppingCriteria, Sampling
label_desc: Use image node_id 3 for calling the Seq2SeqLMBatch obj's underlying member method code with example usage: obj.filter(request_ids) and returns: self, self