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
+15
-13
@@ -31,6 +31,7 @@
|
||||
#include "text/tokenizer.h"
|
||||
#include "format/radfile.h"
|
||||
#include "format/table_copy.h"
|
||||
#include "lora/slots.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
@@ -141,24 +142,25 @@ private:
|
||||
int lora_start();
|
||||
public:
|
||||
int lora_load(const std::string& name, const std::string& dir, std::string* err);
|
||||
/* Unpublish an adapter. Refused (RAD_E_STATE) while a request holds it; its slot is reused
|
||||
* only once the step loop has gone round three times since, so no step still on the card can
|
||||
* read bytes a later load is writing (the next step is issued before the last is read back). */
|
||||
int lora_unload(const std::string& name, std::string* err);
|
||||
/* RAD_OK with the slot, the uid of its load and a HOLD -- the adapter cannot be unloaded while
|
||||
* the hold lives (the server keeps it in the request's Generation, which outlives the request
|
||||
* in the scheduler). RAD_E_NOTFOUND for a name no slot holds. */
|
||||
/* Unpublish an adapter (lora::SlotTable::unload). Idle, its slot is freed at once; in use, it
|
||||
* DRAINS: *in_flight says how many requests still hold it, no new request may name it, and
|
||||
* the last of them frees the slot. A freed slot is reused only once the step loop has gone
|
||||
* round three times since, so no step still on the card can read bytes a later load is
|
||||
* writing (the next step is issued before the last is read back). */
|
||||
int lora_unload(const std::string& name, std::string* err, int* in_flight);
|
||||
/* RAD_OK with the slot, the uid of its load and a HOLD -- the adapter is not freed while the
|
||||
* hold lives (the server keeps it in the request's Generation, which outlives the request in
|
||||
* the scheduler). RAD_E_NOTFOUND for a name no slot holds, or one that is draining. */
|
||||
int lora_acquire(const std::string& name, int32_t* slot, uint64_t* uid,
|
||||
std::shared_ptr<void>* hold);
|
||||
std::vector<std::string> lora_names() const;
|
||||
private:
|
||||
struct LoraSlotState { std::string name, dir; uint64_t uid = 0; bool used = false; uint64_t freed_at = 0; };
|
||||
std::vector<LoraSlotState> lora_slots_;
|
||||
uint64_t lora_next_uid_ = 1;
|
||||
std::map<uint64_t, int> lora_refs_;
|
||||
mutable std::mutex lora_mu_;
|
||||
std::set<std::string> lora_targets_;
|
||||
std::atomic<uint64_t> lora_epoch_{0}; /* step-loop iterations, for slot reuse */
|
||||
lora::SlotTable lora_table_; /* reads lora_epoch_, so declared after it */
|
||||
/* Serialises loads: a slot is reserved, filled on every rank and published by one load at a
|
||||
* time. Requests and unloads go to the table alone and never wait for a load's copy. */
|
||||
std::mutex lora_mu_;
|
||||
std::set<std::string> lora_targets_;
|
||||
/* Resolves --embedding-placement, --vision-tower-placement and --ngram-placement into Config
|
||||
* before the card is split (engine_bringup.cpp describes how auto chooses). `wfs` is every
|
||||
* rank's footprint, read for its towers. `host_late` is the pinned host memory startup
|
||||
|
||||
Reference in new issue
Block a user