| 974 | } |
| 975 | |
| 976 | void run() { |
| 977 | std::string line; |
| 978 | long seq = 0; |
| 979 | for (;;) { |
| 980 | // requests first; the decoding slots' window when none is waiting |
| 981 | upkeep(); |
| 982 | if (!in.next(line, seq, !any_decoding(), std::chrono::duration_cast<std::chrono::milliseconds>(UPKEEP))) { |
| 983 | if (in.closed()) return; |
| 984 | decode_step(); |
| 985 | continue; |
| 986 | } |
| 987 | if (line.empty()) continue; |
| 988 | const std::string cmd = line.substr(0, line.find(' ')); |
| 989 | if (cmd == "QUIT") return; |
| 990 | if (cmd != "GEN" && cmd != "BGEN" && cmd != "GENI" && cmd != "BGENI") { |
| 991 | say("ERR " + cmd + ": not supported by sfnx"); |
| 992 | continue; |
| 993 | } |
| 994 | const bool batch = cmd[0] == 'B', images = cmd.back() == 'I'; |
| 995 | if (batch && a.batch < 2) { |
| 996 | say("ERR " + cmd + ": sfnx runs without --batch"); |
| 997 | continue; |
| 998 | } |
| 999 | if (images && !a.vision) { |
| 1000 | say("ERR this engine was started without --vision"); |
| 1001 | continue; |
| 1002 | } |
| 1003 | GenReq r; |
| 1004 | try { |
| 1005 | r = parse_gen(line, m.vocab, (int) m.ple_image, batch, images); |
| 1006 | if ((long) r.ids.size() + r.max_new + 8 > a.max_ctx) throw std::runtime_error(cmd + ": prompt + max_new exceed the context"); |
| 1007 | r.seq = seq; |
| 1008 | } catch (const std::exception& ex) { |
| 1009 | say(std::string("ERR ") + ex.what()); |
| 1010 | continue; |
| 1011 | } |
| 1012 | if (batch) admit(r); |
| 1013 | else solo(r); |
| 1014 | // FNX_ADMIT_INTERLEAVE=1 (default off): a request read takes the engine for 0.2-0.5 s even for a few tokens; the slots already decoding run one window between two |
| 1015 | // admissions instead of waiting for all of them (8 users that start together: the first ones decode while the last are read) |
| 1016 | if (batch && interleave_ && any_decoding()) decode_step(); |
| 1017 | } |
| 1018 | } |
| 1019 | const bool interleave_ = fnx::env_int("FNX_ADMIT_INTERLEAVE", 0) != 0; // off: measured no gain on 4 x R9700 (RESULTS-HIP.md section 8) |
| 1020 | }; |
| 1021 | |