MCPcopy Create free account
hub / github.com/FastFlowLM/FastFlowLM / ensure_model_loaded

Method ensure_model_loaded

src/server/rest_handler.cpp:380–413  ·  view source on GitHub ↗

@brief Ensure the model is loaded @param model_tag the model tag

Source from the content-addressed store, hash-verified

378///@brief Ensure the model is loaded
379///@param model_tag the model tag
380bool RestHandler::ensure_model_loaded(const std::string& model_tag) {
381 std::string ensure_tag = model_tag;
382 if (current_model_tag != ensure_tag) {
383 std::this_thread::sleep_for(std::chrono::milliseconds(500));
384 if (auto_chat_engine != nullptr) {
385 auto_chat_engine.reset();
386 }
387 std::pair<std::string, std::unique_ptr<AutoModel>> auto_model = get_auto_model(ensure_tag, this->supported_models, &this->npu_device_inst);
388 auto_chat_engine = std::move(auto_model.second);
389 ensure_tag = auto_model.first;
390 if (!downloader.is_model_downloaded(ensure_tag)) {
391 downloader.pull_model(ensure_tag);
392 }
393 auto [new_ensure_tag, model_info] = supported_models.get_model_info(ensure_tag);
394 auto_chat_engine->configure_parameter("img_pre_resize", this->img_pre_resize);
395 try {
396 auto_chat_engine->load_model(supported_models.get_model_path(new_ensure_tag), model_info, ctx_length, preemption);
397 }
398 catch (const std::exception& e) {
399 header_print("ERROR", "Failed to load model: " + std::string(e.what()));
400 this->auto_chat_engine.reset();
401 this->npu_device_inst.reset();
402 this->npu_device_inst = xrt::device(0);
403 this->current_model_tag = "model-faker";
404 return false;
405 }
406
407 if (this->prefill_chunk_len == -1) {
408 this->prefill_chunk_len = model_info["max_prefill_len"].get<int>();;
409 }
410 current_model_tag = ensure_tag;
411 }
412 return true;
413}
414
415///@brief Ensure the asr model is loaded
416///@param model_tag the model tag

Callers

nothing calls this directly

Calls 8

get_auto_modelFunction · 0.85
is_model_downloadedMethod · 0.80
pull_modelMethod · 0.80
get_model_infoMethod · 0.80
get_model_pathMethod · 0.80
resetMethod · 0.45
configure_parameterMethod · 0.45
load_modelMethod · 0.45

Tested by

no test coverage detected