Skip to content

Instantly share code, notes, and snippets.

View patrickvonplaten's full-sized avatar

Patrick von Platen patrickvonplaten

View GitHub Profile
@patrickvonplaten
patrickvonplaten / cache.py
Created October 3, 2023 16:25
Transformers new cache design
class DynamicCache: # <- this is what we currently have
def __init__(self):
self.cache = {}
def update(self, key_states, value_states, layer_idx):
kv_states = torch.cat([key_states[None, :], value_states[None, :], dim=0)
if layer_idx not in self.cache:
self.cache[layer_idx] = kv_states
else: