Module Attention.Cache
Key-value caches.
The type for key-value caches with float dtype layout 'b: the projected keys and values of the positions seen so far, each of shape [| batch; num_heads; len; head_dim |]. Slots at positions not yet seen hold zeros and are never attended to.
make ~num_heads ~head_dim ~len dtype is an empty cache of len slots: zero tensors of shape [| batch; num_heads; len; head_dim |]. batch defaults to 1. len bounds the total sequence length (prompt plus generated positions).
Raises Invalid_argument if any dimension is not positive.
map f c is c with f applied to c.keys and c.values, in that order. With map2 and iter it satisfies the Nx.Ptree.S contract at any fixed 'b, so caches can be leaves of a jitted step's parameter tree.
map2 f c c' combines c and c' leafwise with f.
iter f c applies f to c.keys and c.values, in that order.