MCPcopy Create free account
hub / github.com/Standard-Intelligence/hertz-dev / get_cache_len

Function get_cache_len

transformer.py:19–28  ·  view source on GitHub ↗

cache: (batch, seq_len, 2, kv_heads, head_dim)

(cache: Optional[Tensor])

Source from the content-addressed store, hash-verified

17CACHE_FILL_VALUE = -1
18
19def get_cache_len(cache: Optional[Tensor]) -> int:
20 """
21 cache: (batch, seq_len, 2, kv_heads, head_dim)
22 """
23 if cache is None:
24 return 0
25 nonzeros = T.any(cache.flatten(2) != CACHE_FILL_VALUE, dim=-1)
26 length = nonzeros.sum(dim=-1).int()
27 assert T.all(length == length[0])
28 return length[0]
29
30
31def rotate_half(x):

Callers 1

_attendMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected