Updates the cache with the new `key_states` and `value_states` for the layer `layer_idx`. Parameters: key_states (`torch.Tensor`): The new key states to cache. value_states (`torch.Tensor`): The new value states to cache.
(
self,
key_states: torch.Tensor,
value_states: torch.Tensor,
layer_idx: int,
cache_kwargs: Optional[Dict[str, Any]] = None,
)
| 32 | super().__init__() |
| 33 | |
| 34 | def update( |
| 35 | self, |
| 36 | key_states: torch.Tensor, |
| 37 | value_states: torch.Tensor, |
| 38 | layer_idx: int, |
| 39 | cache_kwargs: Optional[Dict[str, Any]] = None, |
| 40 | ) -> Tuple[torch.Tensor, torch.Tensor]: |
| 41 | """ |
| 42 | Updates the cache with the new `key_states` and `value_states` for the layer `layer_idx`. |
| 43 | |
| 44 | Parameters: |
| 45 | key_states (`torch.Tensor`): |
| 46 | The new key states to cache. |
| 47 | value_states (`torch.Tensor`): |
| 48 | The new value states to cache. |
| 49 | layer_idx (`int`): |
| 50 | The index of the layer to cache the states for. |
| 51 | cache_kwargs (`Dict[str, Any]`, `optional`): |
| 52 | Additional arguments for the cache subclass. These are specific to each subclass and allow new types of |
| 53 | cache to be created. |
| 54 | |
| 55 | Return: |
| 56 | A tuple containing the updated key and value states. |
| 57 | """ |
| 58 | raise NotImplementedError("Make sure to implement `update` in a subclass.") |
| 59 | |
| 60 | def get_seq_length(self, layer_idx: Optional[int] = 0) -> int: |
| 61 | """Returns the sequence length of the cached states. A layer index can be optionally passed.""" |
no outgoing calls