Class MiniMaxIndexCache
java.lang.Object
smile.llm.model.minimax.MiniMaxIndexCache
- All Implemented Interfaces:
AutoCloseable
Key-only cache of MSA index keys, one
[numKeyHeads, indexDim] vector per token and
sparse layer. It is addressed by the physical slots of the main KvCachePool,
so allocation, radix prefix reuse and eviction need no separate bookkeeping.-
Constructor Summary
ConstructorsConstructorDescriptionMiniMaxIndexCache(int numSparseLayers, int numSlots, int numKeyHeads, int indexDim, Device device, ScalarType dtype) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()get(int ordinal, long[] slots) Reads index keys.get(int, long[])with the slots already on the device.layer(int ordinal) One layer of the cache[numSlots, numKeyHeads, indexDim]as a view; the caller closes it.intReturns the number of index-key heads per token.voidWrites index keys.voidput(int, long[], Tensor)with the slots already on the device.
-
Constructor Details
-
MiniMaxIndexCache
public MiniMaxIndexCache(int numSparseLayers, int numSlots, int numKeyHeads, int indexDim, Device device, ScalarType dtype) Constructor.- Parameters:
numSparseLayers- number of MSA layers.numSlots- token slots, equal to the KV pool's.numKeyHeads- index-key heads per token.indexDim- index head dimension.device- device of the KV pool.dtype- storage dtype.
-
-
Method Details
-
put
Writes index keys.- Parameters:
ordinal- sparse-layer ordinal.slots- destination slots, lengthN.keys- index keys, any shape holdingN * numKeyHeads * indexDimelements.
-
put
put(int, long[], Tensor)with the slots already on the device.- Parameters:
ordinal- sparse-layer ordinal.idx- device tensor of destination slots, lengthN.keys- index keys, any shape holdingN * numKeyHeads * indexDimelements.
-
get
get(int, long[])with the slots already on the device.- Parameters:
ordinal- sparse-layer ordinal.idx- device tensor of source slots, lengthN.- Returns:
- keys
[N, numKeyHeads, indexDim]; caller owns the tensor.
-
layer
One layer of the cache[numSlots, numKeyHeads, indexDim]as a view; the caller closes it.- Parameters:
ordinal- sparse-layer ordinal.- Returns:
- the layer view tensor.
-
numKeyHeads
public int numKeyHeads()Returns the number of index-key heads per token.- Returns:
- index-key heads per token.
-
get
Reads index keys.- Parameters:
ordinal- sparse-layer ordinal.slots- source slots, lengthN.- Returns:
- keys
[N, numKeyHeads, indexDim]; caller owns the tensor.
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-