Archived
serve: /v1/models reports max_model_len, the context the server runs with
The model list carried only the id, so a client had no way to read the context the server was started with and guessed it from the model's name. Carry the field vLLM's model card does: the server's max_ctx (--max-model-len, else the container's trained length), on both /v1/models and /v1/models/:id, and leave it out when the length is unknown.
This commit is contained in:
1 parent
7fd2cd7fa6
commit
86128c2e75
6 files changed
+33
-5
No files matched your search
+2
-1
@@ -2205,12 +2205,13 @@ std::string embeddings_body(const OaiRequest& r, const std::vector<std::vector<f
|
||||
return o.dump();
|
||||
}
|
||||
|
||||
std::string models_body(const std::string& model_id, int64_t created) {
|
||||
std::string models_body(const std::string& model_id, int64_t created, int64_t max_model_len) {
|
||||
json m;
|
||||
m["id"] = model_id;
|
||||
m["object"] = "model";
|
||||
m["created"] = created;
|
||||
m["owned_by"] = "radiance";
|
||||
if (max_model_len > 0) m["max_model_len"] = max_model_len;
|
||||
json o;
|
||||
o["object"] = "list";
|
||||
o["data"] = json::array({m});
|
||||
|
||||
+7
-1
@@ -318,7 +318,13 @@ std::string text_completion_body(const OaiRequest& r, const std::vector<ChoiceOu
|
||||
const UsageOut& u, const TimingsOut& t = TimingsOut());
|
||||
std::string embeddings_body(const OaiRequest& r, const std::vector<std::vector<float>>& vecs,
|
||||
const UsageOut& u);
|
||||
std::string models_body(const std::string& model_id, int64_t created);
|
||||
/* `max_model_len` is the context the server was started with (--max-model-len, else the
|
||||
* container's trained length), the field vLLM's model card carries. Clients size their own
|
||||
* context from it -- an agent that compresses its history at the window's edge, a UI that shows
|
||||
* how much is left -- and without it they guess from the model's name, which is wrong whenever the
|
||||
* deployment sets its own length. 0 leaves the field out rather than reporting a length the
|
||||
* server does not know. */
|
||||
std::string models_body(const std::string& model_id, int64_t created, int64_t max_model_len = 0);
|
||||
|
||||
/* The usage chunk of each endpoint's stream: an SSE event whose choices array is empty and whose
|
||||
* only payload is `usage`. Emitted when the request asked for stream_options.include_usage, ONCE
|
||||
|
||||
@@ -1154,7 +1154,7 @@ HttpResponse Server::handle_models(const HttpRequest& req) {
|
||||
return error_response(e, req.peer);
|
||||
}
|
||||
metrics_.observe_http(200);
|
||||
return HttpResponse::json_body(200, models_body(opt_.model_id, started_at_));
|
||||
return HttpResponse::json_body(200, models_body(opt_.model_id, started_at_, opt_.max_ctx));
|
||||
}
|
||||
|
||||
HttpResponse Server::handle_metrics(const HttpRequest&) {
|
||||
|
||||
+1
-1
@@ -1132,7 +1132,7 @@ for a model that takes no images or video.
|
||||
| `POST /v1/chat/completions` | chat, with tools, reasoning and streaming |
|
||||
| `POST /v1/completions` | raw text completion |
|
||||
| `POST /v1/embeddings` | needs a model with an embedding head, else 501 |
|
||||
| `GET /v1/models`, `/v1/models/:id` | what is loaded |
|
||||
| `GET /v1/models`, `/v1/models/:id` | what is loaded, with `max_model_len` (the context it serves, as vLLM reports it) |
|
||||
| `GET /health`, `/ping`, `POST /ping` | liveness |
|
||||
| `GET /load` | current load |
|
||||
| `GET /version` | server version |
|
||||
|
||||
+14
-1
@@ -343,7 +343,7 @@ struct Fixture {
|
||||
FakeGrammar gram;
|
||||
std::unique_ptr<Server> srv;
|
||||
|
||||
explicit Fixture(bool with_tools = true) {
|
||||
explicit Fixture(bool with_tools = true, int64_t max_ctx = 0) {
|
||||
Deps d;
|
||||
d.sched = &sched;
|
||||
d.tok = &tok;
|
||||
@@ -356,6 +356,7 @@ struct Fixture {
|
||||
o.model_id = "test-model";
|
||||
o.default_max_tokens = 32;
|
||||
o.max_seqs = 4;
|
||||
o.max_ctx = max_ctx;
|
||||
srv.reset(new Server(d, o));
|
||||
}
|
||||
|
||||
@@ -2521,6 +2522,18 @@ TEST(models_and_health_answer) {
|
||||
CHECK(json::parse(h.body)["status"].get<std::string>() == "ok");
|
||||
}
|
||||
|
||||
TEST(the_model_entry_carries_the_context_length_the_server_was_started_with) {
|
||||
/* Both routes a client sizes its window from: the list, and the entry it fetches by id. */
|
||||
Fixture f(true, 262144);
|
||||
for (const char* path : {"/v1/models", "/v1/models/test-model"}) {
|
||||
HttpResponse r = f.get(path);
|
||||
CHECK_EQ(r.status, 200);
|
||||
CHECK_EQ(json::parse(r.body)["data"][0].value("max_model_len", (int64_t)0), (int64_t)262144);
|
||||
}
|
||||
Fixture unknown;
|
||||
CHECK(!json::parse(unknown.get("/v1/models").body)["data"][0].contains("max_model_len"));
|
||||
}
|
||||
|
||||
TEST(embeddings_without_an_embedder_is_501_not_an_empty_200) {
|
||||
Fixture f;
|
||||
HttpResponse r = f.post("/v1/embeddings", R"({"input":"hi"})");
|
||||
|
||||
@@ -414,6 +414,14 @@ TEST(the_model_list_is_a_list_of_one_with_the_fields_clients_read) {
|
||||
CHECK_EQ(o["data"][0].value("created", (int64_t)0), (int64_t)1700000000);
|
||||
/* `owned_by` is in the schema and generated clients deserialise it. */
|
||||
CHECK(o["data"][0].contains("owned_by"));
|
||||
/* No length known, none reported: a client falls back to its own default rather than
|
||||
* trusting a made-up one. */
|
||||
CHECK(!o["data"][0].contains("max_model_len"));
|
||||
}
|
||||
|
||||
TEST(the_model_list_reports_the_context_the_server_runs_with) {
|
||||
const json o = parsed(models_body("q38-flashnext", 1700000000, 262144));
|
||||
CHECK_EQ(o["data"][0].value("max_model_len", (int64_t)0), (int64_t)262144);
|
||||
}
|
||||
|
||||
TEST(a_chat_body_carries_usage_and_one_choice_per_completion) {
|
||||
|
||||
Reference in new issue
Block a user