diff --git a/tools/server/server-context.cpp b/tools/server/server-context.cpp index 6d82e0b3c..d1fc2fd93 100644 --- a/tools/server/server-context.cpp +++ b/tools/server/server-context.cpp @@ -4935,6 +4935,19 @@ private: const int32_t n_decision_first = slot.task->type == SERVER_TASK_TYPE_DECISION ? slot.task->decision.pos_first() : -1; + // [fork F14] do not break at user-message starts when the rest of the prompt + // from here fits in one ubatch: the break turns one ubatch into two, and with + // MoE experts on the host each one of >= 32 tokens uploads the experts again. + // A checkpoint at this batch start (the near-end rule below) and at the end + // minus 4 still exist, so a later prompt that diverges inside the merged range + // re-processes less than one ubatch more. LLAMA_USERSTART_MERGE=0 disables. + static const bool userstart_merge = [] { + const char * env = getenv("LLAMA_USERSTART_MERGE"); + return env == nullptr || std::string(env) != "0"; + }(); + const bool merge_user_starts = userstart_merge && !has_mtmd && + slot.task->n_tokens() - slot.prompt.n_tokens() <= n_ubatch; + // add prompt tokens for processing in the current batch while (slot.prompt.n_tokens() < slot.task->n_tokens() && batch.size() < n_batch) { // get next token to process @@ -4978,7 +4991,7 @@ private: slot.prompt.tokens.push_back(cur_tok); // break at the last user message, or at user messages at least min step past the last checkpoint - if (do_checkpoint && spans.is_user_start(slot.prompt.n_tokens())) { + if (do_checkpoint && !merge_user_starts && spans.is_user_start(slot.prompt.n_tokens())) { const auto pos = slot.prompt.n_tokens(); const auto & checkpoints = slot.prompt.checkpoints;