42 const std::string& role,
const ModelConfig& config) {
43 std::lock_guard<std::mutex> lock(slots_mutex_);
45 const std::string new_path = config.
path.string();
46 auto path_it = slot_paths_.find(role);
47 if (path_it != slot_paths_.end() && path_it->second == new_path) {
48 auto it = slots_.find(role);
49 if (it != slots_.end() && it->second->is_loaded()) {
54 auto backend = std::make_shared<LlamaCppBackend>();
55 if (!backend->load_and_activate(config)) {
56 logger->error(
"Failed to activate role '{}' from path: {}",
61 slots_[role] = backend;
62 slot_paths_[role] = new_path;
63 logger->info(
"Activated secondary role '{}' from {}", role, new_path);
75 std::lock_guard<std::mutex> lock(slots_mutex_);
76 auto it = slots_.find(role);
77 return (it == slots_.end()) ? nullptr : it->second.get();
88 const std::string& role)
const {
89 std::lock_guard<std::mutex> lock(slots_mutex_);
90 auto it = slots_.find(role);
91 return (it == slots_.end()) ? std::shared_ptr<InferenceBackend>{}
105 std::lock_guard<std::mutex> lock(slots_mutex_);
106 auto it = slots_.find(role);
107 if (it == slots_.end()) {
110 if (it->second->is_loaded()) {
111 it->second->unload();
114 slot_paths_.erase(role);
115 logger->info(
"Released secondary role '{}'", role);
127 std::lock_guard<std::mutex> lock(slots_mutex_);
128 auto it = slots_.find(role);
129 return it != slots_.end() && it->second->is_loaded();
140 std::lock_guard<std::mutex> lock(slots_mutex_);
141 std::vector<std::string> out;
142 out.reserve(slots_.size());
143 for (
const auto& [role, backend] : slots_) {
144 if (backend->is_loaded()) {
148 std::sort(out.begin(), out.end());
163 std::lock_guard<std::mutex> lock(slots_mutex_);
164 for (
auto& [role, backend] : slots_) {
165 backend->clear_prompt_cache();
180 std::lock_guard<std::mutex> lock(slots_mutex_);
181 for (
auto& [role, backend] : slots_) {
182 if (backend->is_loaded()) {
Concrete base class for inference backends (80% logic).
std::shared_ptr< InferenceBackend > get_shared(const std::string &role) const
Get the backend for a role as a shared_ptr.
void clear_all_prompt_caches()
Fanout: clear prompt/KV cache on every loaded backend.
bool is_loaded(const std::string &role) const
Check whether a role is currently loaded and active.
std::vector< std::string > loaded_roles() const
Names of all roles with a currently-loaded backend.
bool release_role(const std::string &role)
Unload and drop a role.
void shutdown()
Unload every role.
InferenceBackend * get(const std::string &role) const
Get the backend for a role.
bool ensure_loaded(const std::string &role, const ModelConfig &config)
Lazily load and activate a model for a role.
LlamaCppBackend — llama.cpp C API integration.
spdlog initialization and logger access.
ENTROPIC_EXPORT std::shared_ptr< spdlog::logger > get(const std::string &name)
Get or create a named logger.
Activate model on GPU (WARM → ACTIVE).
Unified lifecycle for non-primary inference backends.
Model configuration for a single tier.
std::filesystem::path path
Resolved model file path.