secondary_model_loader.cpp¶
src/inference/secondary_model_loader.cpp
@file secondary_model_loader.cpp @brief SecondaryModelLoader implementation.
Owners: @tvanfossen
clear_all_prompt_caches
void entropic::SecondaryModelLoader::clear_all_prompt_caches()
Fanout: clear prompt/KV cache on every loaded backend.
src/inference/secondary_model_loader.cpp:162
Source · 6 lines
void SecondaryModelLoader::clear_all_prompt_caches() {
std::lock_guard<std::mutex> lock(slots_mutex_);
for (auto& [role, backend] : slots_) {
backend->clear_prompt_cache();
}
}Activity · 3 steps
Requirements
ensure_loaded
bool entropic::SecondaryModelLoader::ensure_loaded(const std::string &role, const ModelConfig &config)
Lazily load and activate a model for a role.
src/inference/secondary_model_loader.cpp:41
Source · 25 lines
bool SecondaryModelLoader::ensure_loaded(
const std::string& role, const ModelConfig& config) {
std::lock_guard<std::mutex> lock(slots_mutex_);
const std::string new_path = config.path.string();
auto path_it = slot_paths_.find(role);
if (path_it != slot_paths_.end() && path_it->second == new_path) {
auto it = slots_.find(role);
if (it != slots_.end() && it->second->is_loaded()) {
return true;
}
}
auto backend = std::make_shared<LlamaCppBackend>();
if (!backend->load_and_activate(config)) {
logger->error("Failed to activate role '{}' from path: {}",
role, new_path);
return false;
}
slots_[role] = backend;
slot_paths_[role] = new_path;
logger->info("Activated secondary role '{}' from {}", role, new_path);
return true;
}Activity · 15 steps
Requirements
loaded_roles
std::vector< std::string > entropic::SecondaryModelLoader::loaded_roles() const
Names of all roles with a currently-loaded backend.
src/inference/secondary_model_loader.cpp:139
Source · 12 lines
std::vector<std::string> SecondaryModelLoader::loaded_roles() const {
std::lock_guard<std::mutex> lock(slots_mutex_);
std::vector<std::string> out;
out.reserve(slots_.size());
for (const auto& [role, backend] : slots_) {
if (backend->is_loaded()) {
out.push_back(role);
}
}
std::sort(out.begin(), out.end());
return out;
}Activity · 8 steps
Requirements
release_role
bool entropic::SecondaryModelLoader::release_role(const std::string &role)
Unload and drop a role.
src/inference/secondary_model_loader.cpp:104
Source · 14 lines
bool SecondaryModelLoader::release_role(const std::string& role) {
std::lock_guard<std::mutex> lock(slots_mutex_);
auto it = slots_.find(role);
if (it == slots_.end()) {
return false;
}
if (it->second->is_loaded()) {
it->second->unload();
}
slots_.erase(it);
slot_paths_.erase(role);
logger->info("Released secondary role '{}'", role);
return true;
}Activity · 10 steps
Requirements
shutdown
void entropic::SecondaryModelLoader::shutdown()
Unload every role.
src/inference/secondary_model_loader.cpp:179
Source · 10 lines
void SecondaryModelLoader::shutdown() {
std::lock_guard<std::mutex> lock(slots_mutex_);
for (auto& [role, backend] : slots_) {
if (backend->is_loaded()) {
backend->unload();
}
}
slots_.clear();
slot_paths_.clear();
}