Archived
lora: an unload of an adapter in use drains it instead of answering 409
POST /v1/unload_lora_adapter for an adapter requests still hold marks it draining and answers
202 {"action": "draining", "lora_name", "in_flight": N}: from then on a request naming it gets the
404 an unknown model gets and /v1/models leaves it out, the N requests finish normally, and the
last hold to go frees the slot, which then cools for three step-loop rounds like any freed slot.
An idle adapter still unloads at once with 200; a second unload while it drains answers 202 with
the count as it is then, and 404 once it is gone; a load of the same name while it drains answers
409 (is being unloaded).
The slots' bookkeeping moves out of Engine into lora::SlotTable (core/lora/slots.h): reserve,
publish, acquire with its hold, unload, names. It has its own lock, so a request's hold and an
unload no longer wait behind a load's device copy; Engine::lora_mu_ now only serialises loads,
which is what keeps a reserved slot from being handed out twice. lora_test drives the table
through both paths, and server_test drives the routes over a real table with a streamed request
held open: 200 idle, 202 draining twice, 404 for a new request and on /v1/models/:id, 409 for a
load while draining, the slot freed when the stream ends, 503 while it cools, 200 after.
This commit is contained in:
1 parent
582cda0a53
commit
91127395ee
10 files changed
+495
-93
No files matched your search
+12
-1
@@ -1832,17 +1832,28 @@ HttpResponse Server::handle_lora_admin(const HttpRequest& req, bool load) {
|
||||
return fail(400, "invalid_request_error", "lora_name must be non-empty and not the served model's name");
|
||||
std::string err;
|
||||
int s;
|
||||
int in_flight = 0;
|
||||
if (load) {
|
||||
if (!j.contains("lora_path") || !j["lora_path"].is_string())
|
||||
return fail(400, "invalid_request_error", "load_lora_adapter needs lora_path");
|
||||
s = opt_.lora_load(name, j["lora_path"].get<std::string>(), &err);
|
||||
} else {
|
||||
s = opt_.lora_unload(name, &err);
|
||||
s = opt_.lora_unload(name, &err, &in_flight);
|
||||
}
|
||||
/* 409 for a load of a name that is still draining: the old adapter's requests are running. */
|
||||
if (s == RAD_E_NOTFOUND) return fail(404, "not_found_error", err);
|
||||
if (s == RAD_E_STATE) return fail(409, "conflict_error", err);
|
||||
if (s == RAD_E_FULL) return fail(503, "service_unavailable", err);
|
||||
if (s < 0) return fail(400, "invalid_request_error", err.empty() ? std::string(rad_strerror(s)) : err);
|
||||
/* AN UNLOAD OF AN ADAPTER IN USE DRAINS IT (lora/slots.h): accepted, not done. New requests
|
||||
* naming it are already refused as an unknown model and it is off /v1/models; the requests
|
||||
* counted here finish normally, and the last of them frees the slot. Asking again answers
|
||||
* the same with the count as it is then, and a 404 once it is gone. */
|
||||
if (!load && in_flight > 0) {
|
||||
metrics_.observe_http(202);
|
||||
return HttpResponse::json_body(202, json{ { "action", "draining" }, { "lora_name", name },
|
||||
{ "in_flight", in_flight } }.dump());
|
||||
}
|
||||
metrics_.observe_http(200);
|
||||
return HttpResponse::json_body(200, json{ { "status", "ok" }, { "lora_name", name },
|
||||
{ "action", load ? "loaded" : "unloaded" } }.dump());
|
||||
|
||||
Reference in new issue
Block a user