Repository navigation
[Engine] multi-slot Host-RAM prefix pinning and strata_pin endpoint - #343
Open
LeoXing1996 wants to merge 2 commits into
Open
LeoXing1996 wants to merge 2 commits into
LeoXing1996 wants to merge 2 commits into
Conversation
Author
|
Fixed the pre-existing Also note from the previous CI run: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem and result
Existing
warm_start/ singleSlot pinned_cannot keep multiple static Agent prefixes (such as Linger'smetaandalter_ego) hot simultaneously on Inkling 2:keep_start()interminal/serve/server.pystopped at the second<|message_system|>boundary, which on Inkling 2 (tool_declare-><SYSTEM PROMPT>->Thinking effort level) kept onlytool_declare, dropped the system prompt, and skipped saving below 2048 tokens..warm-startto disk without pinning in-process (PIN_CUR) and gave up for the rest of the process lifetime if preempted by an interactive request.Conversations::pinned_held a single global slot, andConversations::release()calledSpill::release()on pinned slots, evicting heap KV allocations to/var/tmpand dropping pages.This PR adds opt-in multi-slot Host-RAM prefix pinning (
strata_pin) and fixes Inkling 2 multi-<|message_system|>truncation someta+alter_egoprefixes stay hot in Host RAM orthogonally toparallel=1, reload automatically across server restarts via--pin-dir, and cut Inkling 2 Mini Metal TTFT from2096.2 ms(COLD_META) /1338.1 ms(COLD_ALTER) down to246.2 ms(8.5x) /253.6 ms(5.3x) onMAC-119. Requests withoutstrata_pinand default CLI flags keep identical default behavior.Related discussion
Approach
spill.hpp/spill.cpp/conversations.hpp:pin_ram(),unpin_ram(),is_pinned_ram(), andhas_heap(), guardingSpill::release()/Spill::write()soresident: "ram"pinned blobs stay hot in Host RAM.Slot pinned_with namedstd::vector<PinnedEntry> pinned_(pin_named,pin_current,unpin_named,unpin_all,pinned_count,pinned_info,CacheOptions::pin_mibLRU budget), orthogonal to active conversation slots (parallel=1).Conversations::resume()picks the longest matching prefix across all active/pinned slots and shares KV rows incrementally.main.cpp:prefill=1(max_new=0,want_logits=false) toparse_gen/Session::generate.--pin-dir,--pin-cache-mib, atomic<pin_dir>/<name>.binpersistence (PIN_CUR,PIN_LOAD,UNPIN,PINS), and automatic startup reload (pinned_slots=onINFO).terminal/serve/server.py/server_parts/openai_api.py:_system_turn_endinkeep_start()andresolve_pin_prefix()for multi-<|message_system|>templates sotool_declare+ system prompt are pinned while stopping cleanly beforeThinking effort level:and<|message_user|>./v1/chat/completionsstrata_pin(name,prefill_only,resident, optionalanchor), prioritizingstrata_pin.prefill_only: trueeven when upstream gateways (such as Bifrost) clampmax_tokensto"max_completion_tokens": 16, returning 0 completion tokens.real_requests_pending,pin_preempt,pin_idle_cond) with automatic idle retry.Validation
Passed:
conversations_test.cpp+spill.cppincludingmulti_slot_host_ram_pinsandresident_pin_skips_spill_and_respects_budget) on commitc2f313fbftree (local macOSc++ -std=c++20&MAC-119c++ -std=c++20 -O2):conversations_test: 62168 checks passed.MAC-119(/Users/aaron/ps-metal/.venv/bin/python -m pytest) after the final edit:terminal/serve/test_inkling.py:51 passed, 3 skipped, 157 subtests passed in 0.42s(the 3 skips require$STRATA_INKLING_TOKENIZER).terminal/serve/test_server.py -k StrataPinHttpAndPreemption:3 passed, 467 deselected in 2.24s.-DSTRATA_METAL_POLY=ON) and benchmark onMAC-119(Apple M5 Ultra 256 GiB, macOS 27.2.1,Inkling-2-Mini-UD-Q3_K_XL.gguf,parallel=1,--conversation-cache-mib 0,--max-context 16384):COLD_META(5,783 tok)ttft_ms: 2096.2;COLD_ALTER(3,709 tok)ttft_ms: 1338.1(cached_tokens: 0).meta(5,447 tok, omittedanchor,max_tokens: 0, prefill_only: true,meta.bin693,327,228 B) +alter_ego(3,373 tok, explicitanchor,max_tokens: 1, prefill_only: true,alter_ego.bin625,358,100 B), plus Bifrost shape (max_completion_tokens: 16, prefill_only: true->completion_tokens: 0,status: "pinned").strata_pinparam):PIN_HIT_ALTER_1ttft_ms: 253.6(5.3x,3373/3714cached),PIN_HIT_META_1ttft_ms: 246.2(8.5x,5447/5788cached); switchedreasoning_effort: "low"->314.0 ms(3373cached) /350.0 ms(5447cached).alter_ego.bin(133 ms) &meta.bin(157 ms) reloaded at startup; immediate requests516.4 ms(5447/5784cached) and249.6 ms(3373/3710cached).ttft_ms: 456.6), warmup retried cleanly when idle (preempted: 1,status: "pinned").Failed:
_system_turn_end(p + 64) andtest_server.pymock fix,python tools/check --only py-toolsonMAC-119reported2203 passed, 1 failed, 47 skipped(pre-existing M5 Ultra platform-default failure interminal.tools.test_setup_hy4.MacHy4Flash::test_mac_install_plan_defaults_to_128k_and_unified_fit).LoadSharedSettings::test_several_bad_keys_are_each_namedintest_server.pyfails on untouchedhttp_api.py(top_k: 900accepted;1 failed, 6 passed, 463 deselected).Not run:
python tools/check --only py-toolsand fullterminal/serve/test_server.pywere not re-run after the final_system_turn_end+ mock fix.main.cpp,conversations.hpp,spill.cpp) were not built or tested on hardware here (only macOS Metal + C++ unit test target).Limits
Pinslots stay pinned in Host RAM up to--pin-cache-mib(LRU eviction above budget);--pin-dirpersistence requires explicit opt-in (--pin-dir/--cache-dir).