返回缓存状态的序列长度 Args: layer_idx: 可选的层索引 Returns: int: 序列长度
(self, layer_idx=0)
| 81 | return self |
| 82 | |
| 83 | def get_seq_length(self, layer_idx=0) -> int: |
| 84 | """ |
| 85 | 返回缓存状态的序列长度 |
| 86 | |
| 87 | Args: |
| 88 | layer_idx: 可选的层索引 |
| 89 | |
| 90 | Returns: |
| 91 | int: 序列长度 |
| 92 | """ |
| 93 | is_empty_layer = ( |
| 94 | len(self.key_cache) == 0 # no cache in any layer |
| 95 | or len(self.key_cache) <= layer_idx # skipped `layer_idx` and hasn't run a layer with cache after it |
| 96 | or not self.key_cache[layer_idx].numel() # the layer has no cache |
| 97 | ) |
| 98 | layer_seq_length = self.key_cache[layer_idx].shape[-2] if not is_empty_layer else 0 |
| 99 | return layer_seq_length |
| 100 | |
| 101 | def copy(self): |
| 102 | """ |