MCPcopy Create free account
hub / github.com/Zefan-Cai/KVCache-Factory / __len__

Method __len__

pyramidkv/cache_utils_think.py:1318–1323  ·  view source on GitHub ↗

Support for backwards-compatible `past_key_value` length, e.g. `len(past_key_value)`. This value corresponds to the number of layers in the model.

(self)

Source from the content-addressed store, hash-verified

1316 raise KeyError(f"Cache only has {len(self)} layers, attempted to access layer with index {layer_idx}")
1317
1318 def __len__(self):
1319 """
1320 Support for backwards-compatible `past_key_value` length, e.g. `len(past_key_value)`. This value corresponds
1321 to the number of layers in the model.
1322 """
1323 return len(self.self_attention_cache)
1324
1325 def to_legacy_cache(self) -> Tuple[Tuple[torch.Tensor], Tuple[torch.Tensor]]:
1326 """Converts the `EncoderDecoderCache` instance into its equivalent in the legacy cache format."""

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected