| 804 | } |
| 805 | |
| 806 | void solo(const GenReq& r) { |
| 807 | const Running running(in, r.seq); |
| 808 | yield_said = false; |
| 809 | int slot = best_slot(r.ids, 0); |
| 810 | if (slot < 0) { // the front end sends GEN only when no slot decodes |
| 811 | say("ERR GEN: every slot is decoding"); |
| 812 | return; |
| 813 | } |
| 814 | fnx::Session& s = lane_for(slot); |
| 815 | slots[(size_t) slot].used = ++clock; |
| 816 | // the prompt and the start of its reply, as an admission takes (idle lanes parked for them now); later pages as |
| 817 | // the reply grows, idle lanes parked for them then (on_pool_short below), so a request that sets no max_tokens |
| 818 | // (max_new: the rest of the context) does not empty every idle lane before its first token |
| 819 | const int need = pages_for((int) r.ids.size() + std::min(r.max_new, ADMIT_REPLY) + fnx::MAXT) - e.lane_pages(slots[(size_t) slot].lane); |
| 820 | if (!make_room(need, slot)) { |
| 821 | say("ERR GEN: the K/V pool is full: the request needs " + std::to_string(need) + " more pages, " + |
| 822 | std::to_string(e.free_pages()) + " are free"); |
| 823 | return; |
| 824 | } |
| 825 | fnx::GenStats st; |
| 826 | try { |
| 827 | reading = slot; |
| 828 | e.set_pass_rows(any_decoding() ? 8192 : 0); // other requests decode: they run between passes, so a pass stays at most 8192 rows (what 2 chunks of 4096 were) |
| 829 | s.read(r.ids, st, progress(-1, r.seq), r.hints); |
| 830 | reading = -1; |
| 831 | } catch (const Interrupted& it) { |
| 832 | reading = -1; |
| 833 | st.prompt_tokens = it.read; // as far as the read got (st.reused of them reused), not the whole prompt |
| 834 | // given way (not stopped): the lane with the part read goes to the slot the BYIELD named, which the front |
| 835 | // end's BGEN for the rest of this prompt will name |
| 836 | if (const int to = in.stop_now ? -1 : solo_yield_to(r.seq); to >= 0) { |
| 837 | if (to != slot) { |
| 838 | std::swap(slots[(size_t) slot].lane, slots[(size_t) to].lane); |
| 839 | std::swap(slots[(size_t) slot].sess, slots[(size_t) to].sess); |
| 840 | slot = to; |
| 841 | } |
| 842 | slots[(size_t) slot].idle_since = std::chrono::steady_clock::now(); |
| 843 | std::fprintf(stderr, "sfnx: solo read gave way after %d of %zu tokens; slot %d holds them\n", it.read, r.ids.size(), slot); |
| 844 | say("YIELDED " + std::to_string(slot) + " " + std::to_string(it.read)); |
| 845 | } |
| 846 | done_line(st, fnx::Finish::cancel); |
| 847 | return; |
| 848 | } catch (const fnx::Refused& ex) { // no room for the read: this request fails, the lane keeps what was read |
| 849 | reading = -1; |
| 850 | read_refused(slot, ex, "GEN"); |
| 851 | return; |
| 852 | } |
| 853 | say("RESUME " + std::to_string(st.reused)); |
| 854 | // the reply's pages beyond what was made room for: idle lanes parked as it needs them (nothing else decodes) |
| 855 | struct PoolShort { |
| 856 | fnx::Engine& e; |
| 857 | ~PoolShort() { e.on_pool_short = nullptr; } |
| 858 | } pool_short{e}; |
| 859 | e.on_pool_short = [this, slot](int, int pages) { make_room(e.free_pages() + pages, slot); }; |
| 860 | const fnx::Finish f = s.generate(r.max_new, r.s, [&](int t) { say("T " + std::to_string(t)); }, &in.stop_now, st); |
| 861 | done_line(st, f); |
| 862 | std::fprintf(stderr, "sfnx: slot %d: prompt %d tokens = %d reused + %d read in %.0f ms, %d generated in %.0f ms (%.1f tok/s), " |
| 863 | "drafts %ld of %ld, %d rounds (%d with lookup drafts, %.2f ms a round)\n", |
nothing calls this directly
no test coverage detected