cache
OutputCache
A cache for storing tensor outputs with optional CPU offloading.
This cache stores tensors along with their original devices and can optionally move tensors to CPU to save GPU memory. When retrieving tensors, they are moved back to their original device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
maxsize
|
int
|
Maximum number of items to store in the cache |
required |
move_to_cpu
|
bool
|
If True, tensors will be moved to CPU when cached |
False
|
Source code in genlm/backend/cache.py
TokenTrie
Class used internally to cache language model results.
The TokenTrie maintains a tree of token sequences, storing logits and key-value states for each path.
Source code in genlm/backend/cache.py
DynamicTokenTrie
Bases: TokenTrie
Source code in genlm/backend/cache.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
touch()
store_kv(past_key_values)
count_kv_size()
Recompute how many nodes currently store KVs.
collect_nodes_with_kv()
Collect nodes that have stored KVs (for eviction decisions).
Source code in genlm/backend/cache.py
evict_lru_kv(max_kv)
Evict least recently used KV entries (and descendants) until under limit.