stateBlocks method

List<Float32List> stateBlocks(
  1. int position
)

Views of everything the first position tokens left behind: the conv histories, then each attention layer's keys and values rows before position. Writing them out and reading them back into another model on the same backend restores that position (see Lfm3Model.saveState).

Implementation

List<Float32List> stateBlocks(int position) => [
  for (final conv in _conv)
    if (conv != null) conv.history,
  for (final att in _attention)
    if (att != null) ...[
      Float32List.sublistView(
        att.keys,
        0,
        position * (att.kv1 - att.kv0) * config.headDim,
      ),
      Float32List.sublistView(
        att.values,
        0,
        position * (att.kv1 - att.kv0) * config.headDim,
      ),
    ],
];