Archived
clef: the head's rows bounded at 32768 prompt tokens, not the context
(cherry picked from commit fdc445a7cf1f6de620df6148d0482c8c795b2b27)
This commit is contained in:
1 parent
b1da6a28bd
commit
72d192dbf6
4 files changed
+24
-6
No files matched your search
+5
-1
@@ -22,7 +22,11 @@ extern "C" {
|
||||
enum {
|
||||
RAD_CLEF_MAX_QUESTIONS = 64,
|
||||
RAD_CLEF_MAX_OPTIONS = 512, /* every question's options together */
|
||||
RAD_CLEF_MAX_LEX = 8192 /* every option's tokens together */
|
||||
RAD_CLEF_MAX_LEX = 8192, /* every option's tokens together */
|
||||
/* Prompt tokens. The head gathers every row of a prompt into buffers of its own, so this,
|
||||
* not the deployment's context, sizes them: at the model's own 262144 they would take
|
||||
* 4.5 GiB of the card for prompts that never pass a fifth of it. */
|
||||
RAD_CLEF_MAX_PROMPT = 32768
|
||||
};
|
||||
|
||||
/* The header: word 0 is the engine's (RadBatch::plugin_words), the rest the counts the layout is
|
||||
|
||||
@@ -151,7 +151,10 @@ inline int ClefHead::declare(RadBuilder* b, const RadModelMeta* meta, const RadB
|
||||
if (E % 2) return RAD_E_INVAL;
|
||||
bs = rad_kv_block_size(b, kv_trunk);
|
||||
if (bs <= 0) return RAD_E_STATE;
|
||||
nblk = (g.max_ctx + bs - 1) / bs;
|
||||
/* Rows a request may hold: the context, or the head's own bound where that is less (the
|
||||
* server refuses a longer prompt before it is admitted). */
|
||||
const int64_t rows = g.max_ctx < RAD_CLEF_MAX_PROMPT ? g.max_ctx : RAD_CLEF_MAX_PROMPT;
|
||||
nblk = (rows + bs - 1) / bs;
|
||||
NM = nblk * bs;
|
||||
n_vocab = g.n_vocab;
|
||||
layer = bind_layer;
|
||||
|
||||
@@ -182,12 +182,17 @@ int parse_clef_request(const std::string& body, const OaiDeps& d, const OaiLimit
|
||||
const std::vector<int32_t> suffix =
|
||||
ids("\n<|im_end|>\n<|im_start|>assistant\n<think>\n\n</think>\n\nJOINT SCHEMA DECISIONS:");
|
||||
const int64_t n = (int64_t)(prefix.size() + state.size() + schema.size() + suffix.size());
|
||||
if (lim.max_ctx > 0 && n > lim.max_ctx) {
|
||||
ApiError e = err_bad("state", "the prompt is " + std::to_string(n) + " tokens; this "
|
||||
"deployment's context holds " + std::to_string(lim.max_ctx));
|
||||
/* The context, or the head's own bound where that is less (abi/rad_clef.h). */
|
||||
const int64_t cap = lim.max_ctx > 0 && lim.max_ctx < RAD_CLEF_MAX_PROMPT ? lim.max_ctx
|
||||
: RAD_CLEF_MAX_PROMPT;
|
||||
if (n > cap) {
|
||||
ApiError e = err_bad("state", "the prompt is " + std::to_string(n) + " tokens; " +
|
||||
(cap == lim.max_ctx ? "this deployment's context holds "
|
||||
: "clef's head takes at most ") +
|
||||
std::to_string(cap));
|
||||
e.code = "context_length_exceeded";
|
||||
e.n_prompt_tokens = n;
|
||||
e.n_ctx = lim.max_ctx;
|
||||
e.n_ctx = cap;
|
||||
*err = e;
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
|
||||
@@ -134,6 +134,12 @@ TEST(bad_requests_are_400s) {
|
||||
/* The whole prompt must fit; nothing is cut. */
|
||||
CHECK(parse(tok, kBody, &r, &e, 100) < 0);
|
||||
CHECK_EQ(e.code, "context_length_exceeded");
|
||||
/* And it fits the head's own bound, whatever the context: a byte a token here. */
|
||||
const std::string huge = R"({"state": ")" + std::string(RAD_CLEF_MAX_PROMPT, 'x') +
|
||||
R"(", "questions": {"q": {"type": "noul"}}})";
|
||||
CHECK(parse(tok, huge, &r, &e, 0) < 0);
|
||||
CHECK_EQ(e.code, "context_length_exceeded");
|
||||
CHECK_EQ(e.n_ctx, (int64_t)RAD_CLEF_MAX_PROMPT);
|
||||
}
|
||||
|
||||
TEST(answers_are_softmaxes_in_the_releases_shape) {
|
||||
|
||||
Reference in new issue
Block a user