mstar.engine.resources.kv.keys#
Page keys for cross-request prefix reuse.
A key commits to the whole prefix below it: the previous key, this page’s token ids, and for each input on the page that is not a token, its digest and where it sits. One match confirms every page under it, and a new root leaves every old key unreachable.
The encoding is canonical because one process builds these keys and another matches them: fixed-width little-endian ints, and a length prefix on every variable-length field so that no two different spans encode alike.
Functions
|
Key every page of one stream, folding each key into the next. |
|
Key a page's first |
|
SHA-256 over |
|
Each page's items, given every span's length and digest (None for ids). |
|
Hash a page's parent key, its token ids and its items into the page's key. |
Classes
|
An input that is not a token, as it sits on one page. |
- class mstar.engine.resources.kv.keys.PageItem(start, offset, length, digest)[source]#
Bases:
NamedTupleAn input that is not a token, as it sits on one page.
startis its first slot on this page,offsetcounts its slots on earlier pages, andlengthcounts all of its slots.
- mstar.engine.resources.kv.keys.chain(pages_of_tokens, items_by_page=None, root=b'')[source]#
Key every page of one stream, folding each key into the next.
- mstar.engine.resources.kv.keys.end_key(prev, tokens, items, end)[source]#
Key a page’s first
endslots, where an item on it ends.
- mstar.engine.resources.kv.keys.fingerprint(*fields)[source]#
SHA-256 over
fields, in the encoding page keys use.Used for process constants, so changing one makes every older key unreachable.
- mstar.engine.resources.kv.keys.page_items(spans, page_size)[source]#
Each page’s items, given every span’s length and digest (None for ids).
The preprocess worker keys a prompt’s pages with this, and the engine keys the page that generation fills after the prompt. If the two worked out the items differently, that page’s key would never match.
- mstar.engine.resources.kv.keys.page_key(prev, tokens, items=())[source]#
Hash a page’s parent key, its token ids and its items into the page’s key.
The ids fill the slots the items leave, in order, so an item’s
startis what tells[t1 t2 IMG]from[t1 IMG t2]. Every page an item touches carries the item’s wholelengthanddigest, because attention inside an item is not causal and a page’s KV depends on the item’s later slots too.