MCPcopy Create free account
hub / github.com/antirez/llama.cpp-deepseek-v4-flash / load

Method load

tools/server/server-models.cpp:531–706  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

529}
530
531void server_models::load(const std::string & name) {
532 if (!has_model(name)) {
533 throw std::runtime_error("model name=" + name + " is not found");
534 }
535 unload_lru();
536
537 std::lock_guard<std::mutex> lk(mutex);
538
539 auto meta = mapping[name].meta;
540 if (meta.status != SERVER_MODEL_STATUS_UNLOADED) {
541 SRV_INF("model %s is not ready\n", name.c_str());
542 return;
543 }
544
545 // Re-check capacity under the lock to prevent concurrent loads from
546 // exceeding models_max. Without this, the window between unload_lru()
547 // releasing its lock and this lock_guard acquiring allows multiple
548 // threads to each observe capacity and all proceed to load.
549 if (base_params.models_max > 0) {
550 size_t count_active = 0;
551 for (const auto & m : mapping) {
552 if (m.second.meta.is_running()) {
553 count_active++;
554 }
555 }
556 if (count_active >= (size_t)base_params.models_max) {
557 throw std::runtime_error("model limit reached, try again later");
558 }
559 }
560
561 // prepare new instance info
562 instance_t inst;
563 inst.meta = meta;
564 inst.meta.port = get_free_port();
565 inst.meta.status = SERVER_MODEL_STATUS_LOADING;
566 inst.meta.last_used = ggml_time_ms();
567
568 if (inst.meta.port <= 0) {
569 throw std::runtime_error("failed to get a port number");
570 }
571
572 inst.subproc = std::make_shared<subprocess_s>();
573 {
574 SRV_INF("spawning server instance with name=%s on port %d\n", inst.meta.name.c_str(), inst.meta.port);
575
576 inst.meta.update_args(ctx_preset, bin_path); // render args
577
578 std::vector<std::string> child_args = inst.meta.args; // copy
579 std::vector<std::string> child_env = base_env; // copy
580 child_env.push_back("LLAMA_SERVER_ROUTER_PORT=" + std::to_string(base_params.port));
581
582 SRV_INF("%s", "spawning server instance with args:\n");
583 for (const auto & arg : child_args) {
584 SRV_INF(" %s\n", arg.c_str());
585 }
586 inst.meta.args = child_args; // save for debugging
587
588 std::vector<char *> argv = to_char_ptr_array(child_args);

Callers 3

init_routesMethod · 0.45
readMethod · 0.45
writeMethod · 0.45

Calls 13

update_statusMethod · 0.95
get_free_portFunction · 0.85
ggml_time_msFunction · 0.85
to_char_ptr_arrayFunction · 0.85
is_runningMethod · 0.80
update_argsMethod · 0.80
findMethod · 0.80
endMethod · 0.80
to_stringFunction · 0.50
string_starts_withFunction · 0.50
push_backMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected