MCPcopy Create free account
hub / github.com/microsoft/BitNet / cache_prefix

Function cache_prefix

gpu/model.py:346–366  ·  view source on GitHub ↗

Take a prefix view of a larger cache. The original cache object remains of identical size and valid after the shrinked alias has been used. This function is useful when a cache was allocated for a larger batch size than what is necessary. Args: cache: the

(cache: list[LayerCache], length: int)

Source from the content-addressed store, hash-verified

344
345
346def cache_prefix(cache: list[LayerCache], length: int) -> list[LayerCache]:
347 """
348 Take a prefix view of a larger cache.
349
350 The original cache object remains of identical size and valid
351 after the shrinked alias has been used. This function is useful
352 when a cache was allocated for a larger batch size than what is
353 necessary.
354
355 Args:
356 cache: the cache to take a view in.
357 length (int): the desired length
358
359 Returns:
360 A view in the input cache object.
361 """
362
363 if len(cache) > 0:
364 assert cache[0][0].shape[1] >= length
365
366 return [(ck[:, :length], cv[:, :length]) for ck, cv in cache]

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected