| 869 | } |
| 870 | |
| 871 | void admit(const GenReq& r) { |
| 872 | if (r.slot < 0 || r.slot >= (int) slots.size() || !slots[(size_t) r.slot].free()) { |
| 873 | say("ERR BGEN: no such free slot " + std::to_string(r.slot) + " (--batch " + std::to_string(slots.size()) + ")"); |
| 874 | return; |
| 875 | } |
| 876 | const Running running(in, r.seq); |
| 877 | const int i = r.slot; |
| 878 | // the slot takes the idle lane that holds most of the prompt (the front end picks slots by what it believes they |
| 879 | // hold; the lanes are sFNX's to deal) |
| 880 | const int k = best_slot(r.ids, i); |
| 881 | if (k >= 0 && k != i && slots[(size_t) k].lane >= 0) { |
| 882 | std::swap(slots[(size_t) i].lane, slots[(size_t) k].lane); |
| 883 | std::swap(slots[(size_t) i].sess, slots[(size_t) k].sess); |
| 884 | } |
| 885 | fnx::Session& s = lane_for(i); |
| 886 | Slot& sl = slots[(size_t) i]; |
| 887 | sl.used = ++clock; |
| 888 | sl.seq = r.seq; |
| 889 | // the prompt's pages and the first ADMIT_REPLY tokens of its reply (the lane's own count: it may restart), and |
| 890 | // room for the decoding slots to grow while it reads; short of that, the decoding slots go on until enough of |
| 891 | // them end |
| 892 | for (;;) { |
| 893 | int growing = 0; |
| 894 | for (const Slot& o : slots) growing += o.decoding; |
| 895 | const int need = pages_for((int) r.ids.size() + std::min(r.max_new, ADMIT_REPLY) + fnx::MAXT) + 2 * growing - |
| 896 | e.lane_pages(sl.lane); |
| 897 | if (make_room(need, i)) break; |
| 898 | if (!any_decoding()) { |
| 899 | say("ERR BGEN: the K/V pool is full: the prompt needs " + std::to_string(need) + " more pages, " + |
| 900 | std::to_string(e.free_pages()) + " are free"); |
| 901 | return; |
| 902 | } |
| 903 | if (in.yielded(i, r.seq) || in.bstopped(i, r.seq) || in.stop_now) { |
| 904 | if (in.yielded(i, r.seq)) say("YIELDED " + std::to_string(i) + " 0"); |
| 905 | fnx::GenStats st; // nothing read: prompt_tokens 0 |
| 906 | done_line(st, fnx::Finish::cancel); |
| 907 | say("BADM " + std::to_string(i) + " 0"); |
| 908 | return; |
| 909 | } |
| 910 | decode_step(); |
| 911 | } |
| 912 | fnx::GenStats st; |
| 913 | try { |
| 914 | reading = i; |
| 915 | e.set_pass_rows(any_decoding() ? 8192 : 0); |
| 916 | s.read(r.ids, st, progress(i, r.seq), r.hints); |
| 917 | reading = -1; |
| 918 | } catch (const Interrupted& it) { |
| 919 | reading = -1; |
| 920 | if (in.yielded(i, r.seq)) say("YIELDED " + std::to_string(i) + " " + std::to_string(it.read)); |
| 921 | st.prompt_tokens = it.read; |
| 922 | done_line(st, fnx::Finish::cancel); |
| 923 | say("BADM " + std::to_string(i) + " 0"); |
| 924 | return; |
| 925 | } catch (const fnx::Refused& ex) { |
| 926 | reading = -1; |
| 927 | read_refused(i, ex, "BGEN"); |
| 928 | return; |
nothing calls this directly
no test coverage detected