code: def prepare_kv_cache(
      self,
      cur_seq_ids: List[int],
      seq_group_meta_data_lists: List[SequenceGroupMetadata],
      kv_cache: Dict,
      num_layers: int,
      kv_cache_size_1: int,
  ):
      max_seq_limit = self.max_seq_limit
      if (
          self.last_kv_cache is not None
      ) and cur_seq_ids == self.last_seq_ids:
          if self.last_kv_cache[0][0].size(2) < max_seq_limit * 1.5:
              bigdl_kv_cache = self.last_kv_cache
              # Immediately set it to None to decrease ref-count
              self.last_kv_cache = None
          else:
              bigdl_kv_cache = [
                  [
                      tmp.narrow(
                          2,
                          self.last_kv_cache[0][0].size(2)
                          - max_seq_limit,
                          max_seq_limit,
                      )
                      for tmp in tmp_list
                  ]
                  for tmp_list in self.last_kv_cache
              ]
              del self.last_kv_cache
              self.last_kv_cache = None
      else:
          del self.last_kv_cache
          bigdl_kv_cache = []
          max_kv_len = max(
              seq_group_meta_data.seq_data[
                  next(iter(seq_group_meta_data.seq_data))
              ].get_len()
              for seq_group_meta_data in seq_group_meta_data_lists
          )
          max_kv_len = min(max_kv_len, max_seq_limit)
  
          for i in range(num_layers):
              cur_list = []
              for j in range(kv_cache_size_1):
                  views = []
                  for seq_group_meta_data in seq_group_meta_data_lists:
                      seq_ids = list(
                          seq_group_meta_data.seq_data.keys()
                      )
                      seq_id = seq_ids[0]
                      view_size = [1] + list(
                          kv_cache[i][j][seq_id].shape
                      )
                      views.append(
                          kv_cache[i][j][seq_id].view(view_size)
                      )
  
                  views = [
                      _pad_kv_cache_view(v, max_kv_len, self.device)
                      for v in views
                  ]
                  cur_view = torch.cat(views, dim=0)
                  cur_list.append(cur_view)
  
                  for seq_group_meta_data in seq_group_meta_data_lists:
                      seq_ids = list(
                          seq_group_meta_data.seq_data.keys()
                      )
                      seq_id = seq_ids[0]
                      del kv_cache[i][j][seq_id]
  
              bigdl_kv_cache.append(cur_list)
  
      return bigdl_kv_cache
  
imports: import torch
  from torch import nn
  from typing import Optional, Tuple, List, Type, Dict
  from transformers import LlamaConfig
  from bigdl.llm.vllm.sequence import SequenceOutputs, SequenceGroupMetadata
  from bigdl.llm.transformers.models.utils import extend_kv_cache
  from bigdl.llm.vllm.logger import init_logger
label_desc: Use image node_id 4 for calling the BigDLModelForCausalLM obj's underlying member method code with example usage: obj.prepare_kv_cache(cur_seq_ids, seq_group_meta_data_lists, kv_cache, num_layers, kv_cache_size_1) and returns: bigdl_kv_cache