(
num_chunks, num_key_value_heads, num_blocks_per_chunk, head_dim, max_cache_size
)
| 181 | |
| 182 | |
| 183 | def reset_cache( |
| 184 | num_chunks, num_key_value_heads, num_blocks_per_chunk, head_dim, max_cache_size |
| 185 | ): |
| 186 | cache = [] |
| 187 | for i in range(num_chunks): |
| 188 | curr_chunk_cache = torch.zeros( |
| 189 | ( |
| 190 | 2 * num_blocks_per_chunk[i], |
| 191 | num_key_value_heads, |
| 192 | max_cache_size, # generate fixed cache as torch dynamic shape cannot handle 2 dynamic dim |
| 193 | head_dim, |
| 194 | ), |
| 195 | dtype=torch.float32, |
| 196 | ) |
| 197 | cache.append(curr_chunk_cache) |
| 198 | return cache |
| 199 | |
| 200 | |
| 201 | def forward_and_save( |
no test coverage detected