MCPcopy Create free account

hub / github.com/Zefan-Cai/KVCache-Factory / functions

Functions410 in github.com/Zefan-Cai/KVCache-Factory

↓ 95 callersMethodupdate
Updates the cache with the new `key_states` and `value_states` for the layer `layer_idx`. Parameters: key_states (`torch
pyramidkv/cache_utils_think.py:34
↓ 68 callersMethodget_usable_length
Given the sequence length of the new inputs, returns the usable length of the cache.
pyramidkv/cache_utils_think.py:69
↓ 47 callersMethodupdate_kv
(self, key_states, query_states, value_states, attention_mask, num_key_value_groups)
pyramidkv/pyramidkv_utils.py:672
↓ 40 callersFunctionmaybe_repeat_kv_before_cache
Expand KV to query-head granularity before compression/caching, unless the opt-in kv_head cache layout is enabled (see docs/gqa_cache_layout.md).
pyramidkv/pyramidkv_utils.py:133
↓ 24 callersFunctionrepeat_kv_to_query_heads
Expand a kv-head-granular cache for eager/sdpa attention compute. No-op when the cache already holds query-head-granular tensors.
pyramidkv/pyramidkv_utils.py:142
↓ 23 callersMethodget_seq_length
Returns the sequence length of the cached states. A layer index can be optionally passed.
pyramidkv/cache_utils_think.py:60
↓ 17 callersFunction_flash_attention_forward
Calls the forward method of Flash Attention - if the input hidden states contain at least one padding token first unpad the input, then compu
pyramidkv/llama_model.py:34
↓ 16 callersFunctionrepeat_kv
This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch, num_key_value_heads, seqlen, he
pyramidkv/pyramidkv_utils.py:121
↓ 12 callersMethod__init__
(self)
pyramidkv/cache_utils_think.py:31
↓ 11 callersFunction_debug_print
(*args, **kwargs)
pyramidkv/pyramidkv_utils.py:22
↓ 10 callersFunction_reduce_group_scores
Reduce query-head-granularity scores to kv-head granularity. `scores` has shape (bsz, num_query_heads, ...) with heads laid out the way repea
pyramidkv/pyramidkv_utils.py:252
↓ 10 callersFunctionmake_inputs
(seed, num_q_heads, num_kv_heads, q_len, dtype=torch.float32)
tests/test_adakv_headkv_kv_head.py:86
↓ 9 callersFunction_gqa_groups
Detect the query-heads-per-kv-head group count from the tensors themselves. Returns 1 when query and key head counts match (MHA, or GQA tensors t
pyramidkv/pyramidkv_utils.py:236
↓ 9 callersFunctionadakv_kwargs
(**overrides)
tests/test_adakv_headkv_kv_head.py:102
↓ 9 callersFunctionmerge_kv
(key_states, value_states, indices, window_size, merge)
pyramidkv/pyramidkv_utils.py:151
↓ 8 callersMethod_run
(self, method, granularity, num_kv_heads=2, attn_impl="eager")
tests/test_gqa_model_integration.py:112
↓ 8 callersFunctionbuild_quantized_cache_config
Build the Hugging Face `generate(..., cache_config=...)` dictionary. KIVI quantizes keys per-channel and values per-token. With the HQQ cache
pyramidkv/quantization.py:25
↓ 7 callersFunction_align_attention_mask
(attention_mask, kv_cache_len)
pyramidkv/mistral_model.py:43
↓ 7 callersMethod_assert_identical
(self, make_old, make_new, seed_rng=False, q_lens=Q_LENS, merge=None)
tests/test_query_head_bitident.py:77
↓ 7 callersFunctionheadkv_kwargs
(head_capacity, **overrides)
tests/test_adakv_headkv_kv_head.py:110
↓ 7 callersFunctioninit_snapkv
(self)
pyramidkv/pyramidkv_utils.py:1265
↓ 7 callersFunctionis_empty_past_key_values
Return True when ``past_key_values`` holds no cached tokens yet. Handles the three shapes seen across transformers versions: ``None``, a ``Ca
pyramidkv/generation_state.py:14
↓ 7 callersMethodto_legacy_cache
Converts the `DynamicCache` instance into the its equivalent in the legacy cache format. Used for backward compatibility.
pyramidkv/cache_utils_think.py:437
↓ 6 callersMethod_check_common
(self, key_out, value_out, key_in, value_in, kept_cap, check_window=True)
tests/test_gqa_kv_head.py:79
↓ 6 callersMethod_check_flat_capacity
(self, caches, granularity, num_kv_heads=2)
tests/test_gqa_model_integration.py:123
↓ 6 callersMethod_run_twice
Run update_kv twice on cloned identical inputs; return both results.
tests/test_gqa_kv_head.py:89
↓ 6 callersMethodget_max_length
Returns the maximum sequence length of the cached states, if there is any.
pyramidkv/cache_utils_think.py:65
↓ 6 callersFunctioninit_CAM
(self)
pyramidkv/pyramidkv_utils.py:1338
↓ 6 callersFunctioninit_H2O
(self)
pyramidkv/pyramidkv_utils.py:1361
↓ 6 callersFunctioninit_StreamingLLM
(self)
pyramidkv/pyramidkv_utils.py:1385
↓ 6 callersFunctioninit_l2norm
(self)
pyramidkv/pyramidkv_utils.py:1319
↓ 6 callersFunctioninit_pyramidkv
(self, num_hidden_layers)
pyramidkv/pyramidkv_utils.py:1238
↓ 6 callersFunctionmake_head_capacity
Small synthetic per-QUERY-head capacity table, as run_longbench builds (integer, shape (num_layers, num_heads)); values stay well below q_len
tests/test_adakv_headkv_kv_head.py:94
↓ 6 callersFunctionnormalize_quant_method
(method: Optional[str])
pyramidkv/quantization.py:14
↓ 6 callersFunctionreplace_llama
(method, model_name=None)
pyramidkv/monkeypatch.py:19
↓ 5 callersFunctionreplace_mistral
(method)
pyramidkv/monkeypatch.py:92
↓ 4 callersFunction_add
(token_id)
pyramidkv/eval_utils.py:21
↓ 4 callersMethod_quantize
Quantizes a key/value using a defined quantization method.
pyramidkv/cache_utils_think.py:698
↓ 4 callersMethod_quantize
(self, tensor, axis)
pyramidkv/quantcache.py:29
↓ 4 callersFunction_select_topk_kv
Top-k select past tokens per head and keep the observation window. Works at whatever head granularity key/value/attn_cache share; in kv_head
pyramidkv/pyramidkv_utils.py:301
↓ 4 callersMethodcheck_dynamic_cache
(self, method: str)
pyramidkv/cache_utils_think.py:1379
↓ 4 callersMethodfrom_legacy_cache
Converts a cache in the legacy cache format into an equivalent `DynamicCache`. Used for backward compatibility.
pyramidkv/cache_utils_think.py:446
↓ 4 callersFunctionmake_inputs
Unrepeated GQA tensors: query at Q_HEADS, key/value at KV_HEADS.
tests/test_gqa_kv_head.py:30
↓ 4 callersMethodupdate_kv
(self, key_states, query_states, value_states)
pyramidkv/pyramidkv_utils.py:1149
↓ 3 callersMethod_assert_identical
(self, make_old, make_new)
tests/test_adakv_headkv_kv_head.py:131
↓ 3 callersMethod_run
(self, granularity, num_kv_heads=2, attn_impl="eager")
tests/test_gqa_model_integration.py:184
↓ 3 callersMethod_run
(self, cluster, seed=0, q_len=Q_LEN)
tests/test_adakv_headkv_kv_head.py:177
↓ 3 callersFunctionbuild_stop_token_ids
Collect every stop token id (e.g. Llama-3 dual terminators, issue #46).
pyramidkv/eval_utils.py:17
↓ 3 callersMethodcalcul_attn_sore
(self, key_states, query_states)
pyramidkv/pyramidkv_utils.py:971
↓ 3 callersMethodencode_text_to_tokens
(self, text)
run_needle_in_haystack.py:395
↓ 3 callersFunctionselect_quest_pages
Return top Quest page indices for the non-recent prefix. Recent tokens are protected outside the page score path and should be appended by `s
pyramidkv/quest.py:85
↓ 3 callersMethodupdate
(self, key_states, value_states, layer_idx, cache_kwargs=None)
pyramidkv/pyramidkv_utils.py:65
↓ 3 callersMethodupdate_kv
(self, key_states, query_states, value_states)
pyramidkv/pyramidkv_utils.py:1004
↓ 2 callersFunction_cache_tensors
Return the per-layer key cache tensors from a Cache or legacy tuple.
tests/test_gqa_model_integration.py:86
↓ 2 callersFunction_configure_layers
Thread the per-layer knobs onto self_attn.config the way run_longbench.py does.
tests/test_gqa_model_integration.py:54
↓ 2 callersMethod_dequantize
Dequantizes back the tensor that was quantized by `self._quantize()`
pyramidkv/cache_utils_think.py:702
↓ 2 callersMethod_dequantize
(self, qtensor, meta, outlier_indices, outlier_values)
pyramidkv/quantcache.py:43
↓ 2 callersMethod_expected_heads
(self, granularity, num_kv_heads)
tests/test_gqa_model_integration.py:120
↓ 2 callersFunction_gather_tokens
(states: torch.Tensor, indices: torch.Tensor)
pyramidkv/minicache.py:91
↓ 2 callersFunction_generate
(model)
tests/test_gqa_model_integration.py:67
↓ 2 callersFunction_grouped_window_attn_cache
SnapKV-style observation-window scores at kv-head granularity. Keys are repeated TRANSIENTLY (for the score matmul only); the returned cache
pyramidkv/pyramidkv_utils.py:273
↓ 2 callersFunction_normalise_indices
(indices: torch.Tensor | None, key_len: int, device: torch.device)
pyramidkv/nacl.py:79
↓ 2 callersFunction_reset_if_fresh
Mirror the prepare_inputs_for_generation reset guard used by the patches. Returns True when a reset happened so tests can assert the branch.
tests/test_generation_state.py:18
↓ 2 callersFunction_scatter_tokens
(states: torch.Tensor, indices: torch.Tensor | None, tokens: torch.Tensor | None)
pyramidkv/minicache.py:98
↓ 2 callersFunction_unit_and_magnitude
(states: torch.Tensor, eps: float)
pyramidkv/minicache.py:17
↓ 2 callersMethodbatch_repeat_interleave
Repeat the cache `repeats` times in the batch dimension. Used in contrastive search.
pyramidkv/cache_utils_think.py:494
↓ 2 callersMethodbatch_select_indices
Only keep the `indices` in the batch dimension of the cache. Used in contrastive search.
pyramidkv/cache_utils_think.py:500
↓ 2 callersMethodbatch_split
Split the current instance into a list of `DynamicCache` by the batch size. This will be used by `_split_model_inputs()` in `generation.utils`
pyramidkv/cache_utils_think.py:471
↓ 2 callersFunctionbuild_quest_page_metadata
Build per-page key minima and maxima. Args: key_states: Tensor with shape `[batch, heads, seq_len, head_dim]`. page_size: Number
pyramidkv/quest.py:24
↓ 2 callersMethodcalcul_attn_sore
(self, key_states, query_states)
pyramidkv/pyramidkv_utils.py:1116
↓ 2 callersMethoddecode_tokens
(self, tokens, context_length=None)
run_needle_in_haystack.py:471
↓ 2 callersMethodevict_previous_layer
Moves the previous layer cache to the CPU
pyramidkv/cache_utils_think.py:537
↓ 2 callersFunctionf1_score
(prediction, ground_truth, **kwargs)
metrics.py:118
↓ 2 callersMethodget_seq_length
Returns the sequence length of the cached states. A layer index can be optionally passed.
pyramidkv/cache_utils_think.py:426
↓ 2 callersFunctioninit_adakv
(self)
pyramidkv/pyramidkv_utils.py:1410
↓ 2 callersFunctioninit_headkv
(self)
pyramidkv/pyramidkv_utils.py:1442
↓ 2 callersFunctionlower
(text)
metrics.py:25
↓ 2 callersFunctionminicache_slerp
Merge adjacent-layer states with MiniCache SLERP direction sharing. Args: current_states: KV states from layer `l`, shape `[batch, heads,
pyramidkv/minicache.py:22
↓ 2 callersFunctionnaive_snapkv_kv_head
Independent reference for the SnapKV kv_head selection: transient repeat -> window scores with the SnapKV causal mask -> fp32 softmax -> row-sum -
tests/test_gqa_kv_head.py:39
↓ 2 callersFunctionnormalize_answer
Lower text and remove punctuation, articles and extra whitespace.
metrics.py:12
↓ 2 callersFunctionnormalize_zh_answer
Lower text and remove punctuation, extra whitespace.
metrics.py:31
↓ 2 callersFunctionpatch_quantized_cache
Install local cache overrides required by selected quantization methods.
pyramidkv/quantization.py:77
↓ 2 callersFunctionplot_heatmap
Helper function to plot a heatmap for a tensor of shape (seq_len, seq_len).
pyramidkv/viztools/utils.py:7
↓ 2 callersFunctionreduce_nacl_proxy_scores
Reduce attention scores column-wise using NACL proxy tokens. Args: attn_scores: Either `[batch, heads, query, key]` raw attention scores
pyramidkv/nacl.py:51
↓ 2 callersFunctionreduce_scissorhands_scores
Reduce recent attention history into per-token importance scores. `attn_scores` may be raw attention with shape `[batch, heads, query, key]`
pyramidkv/scissorhands.py:8
↓ 2 callersFunctionremove_punc
(text)
metrics.py:21
↓ 2 callersMethodreorder_cache
Reorders the cache for beam search, given the selected beam indices.
pyramidkv/cache_utils_think.py:80
↓ 2 callersMethodreset
(self)
pyramidkv/cache_utils_think.py:1691
↓ 2 callersFunctionrun_once
(model, tokenizer, prompt, args)
scripts/benchmark_latency_memory.py:86
↓ 2 callersFunctionscore_quest_pages
Estimate query-aware criticality for each page. The score is the upper bound of `query @ key` over the page's min/max box: positive query dim
pyramidkv/quest.py:57
↓ 2 callersFunctionscorer_e
(dataset, predictions, answers, lengths, all_classes)
eval.py:49
↓ 2 callersFunctionselect_minicache_retention_indices
Select high-angular-distance token positions to keep unmerged. `angular_distance` is expected to be normalized by pi and shaped `[batch, head
pyramidkv/minicache.py:61
↓ 2 callersFunctionselect_nacl_proxy_indices
Choose proxy token positions for NACL scoring. `suffix` matches the common long-context QA layout where the user question is placed at the en
pyramidkv/nacl.py:15
↓ 2 callersFunctionselect_nacl_tokens
Select retained KV token indices with NACL proxy/random eviction. Returned indices have shape `[batch, heads, retained]` and are sorted in as
pyramidkv/nacl.py:109
↓ 2 callersFunctionselect_quest_tokens
Return Quest-selected token indices with an exact token budget. The prefix selection is page-based, then expanded to ascending token indices.
pyramidkv/quest.py:133
↓ 2 callersFunctionselect_scissorhands_tokens
Select persistent pivotal tokens under a fixed KV budget. Returned indices have shape `[batch, heads, retained]` and are sorted in chronologi
pyramidkv/scissorhands.py:91
↓ 2 callersFunctionsynchronize
()
scripts/benchmark_latency_memory.py:80
↓ 2 callersMethodupdate
Updates the cache with the new `key_states` and `value_states` for the layer `layer_idx`. Parameters: key_states (`torch
pyramidkv/cache_utils_think.py:353
↓ 2 callersMethodupdate_kv
(self, key_states, query_states, value_states, attention_mask, num_key_value_groups)
pyramidkv/pyramidkv_utils.py:348
↓ 2 callersMethodupdate_kv
(self, key_states, query_states, value_states, attention_mask, num_key_value_groups)
pyramidkv/pyramidkv_utils.py:494
next →1–100 of 410, ranked by callers