MCPcopy Create free account
hub / github.com/pytorch/executorch / reset_cache

Function reset_cache

examples/mediatek/model_export_scripts/phi.py:183–198  ·  view source on GitHub ↗
(
    num_chunks, num_key_value_heads, num_blocks_per_chunk, head_dim, max_cache_size
)

Source from the content-addressed store, hash-verified

181
182
183def 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
201def forward_and_save(

Callers 1

prepare_model_inputsFunction · 0.70

Calls 2

zerosMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected