class_docstr: Transformers handler class for sequence, token classification and question answering.
class_docstr_tok: ["Transformers","handler","class","for","sequence",",","token","classification","and","question","answering","."]
code: def _swap_kv_cache(self, i: int, j: int) -> None:
      rearrangement_indices = torch.tensor(
          range(self.max_bsz), dtype=torch.long, device=self.device
      )
      rearrangement_indices[i], rearrangement_indices[j] = (
          rearrangement_indices[j],
          rearrangement_indices[i],
      )
  
      for l in self.model.layers:
          l.attention.cache_k = l.attention.cache_k[
              rearrangement_indices, ...
          ]
          l.attention.cache_v = l.attention.cache_v[
              rearrangement_indices, ...
          ]
  
imports: import json
  import logging
  import os
  import sys
  import time
  from abc import ABC
  from typing import List
  import packaging.version
  import requests
  import torch
  import transformers
  from ts.torch_handler.base_handler import BaseHandler
  from generate import sample_top_p
  from llama2 import Llama
label_desc: Use image node_id 15 for calling the LlamaHandler obj's underlying member method code with example usage: obj._swap_kv_cache(i, j) without return types