Converts a cache in the legacy cache format into an equivalent `Cache`.
(
cls,
past_key_values: Optional[Tuple[torch.Tensor]] = None,
seen_tokens: int = 0
)
| 126 | |
| 127 | @classmethod |
| 128 | def from_legacy_cache( |
| 129 | cls, |
| 130 | past_key_values: Optional[Tuple[torch.Tensor]] = None, |
| 131 | seen_tokens: int = 0 |
| 132 | ) -> Cache: |
| 133 | """Converts a cache in the legacy cache format into an equivalent `Cache`.""" |
| 134 | |
| 135 | cache = cls(seen_tokens) |
| 136 | if past_key_values is not None: |
| 137 | for layer_idx in range(len(past_key_values)): |
| 138 | cache.states.append(past_key_values[layer_idx]) |
| 139 | return cache |
no outgoing calls
no test coverage detected