include/entropic/inference/adapter_manager.h

← API

include/entropic/inference/adapter_manager.h

entropic::AdapterManager

LoRA adapter lifecycle manager.

bool entropic::AdapterManager::load(const std::string &name, const std::filesystem::path &adapter_path, llama_model *model, float scale=1.0f)

Load a LoRA adapter into RAM (COLD -> WARM).

Calls llama_adapter_lora_init() to load the adapter against the base model. The adapter stays in RAM until explicitly unloaded or the base model is unloaded.

Parameters
  • name — Unique identifier for this adapter.
  • adapter_path — Path to the LoRA .gguf file.
  • model — llama_model the adapter targets.
  • scale — LoRA scaling factor (default 1.0).
  • name — Unique identifier.
  • adapter_path — Path to .gguf adapter file.
  • model — Base llama_model pointer.
  • scale — LoRA scaling factor.
Returns
  • true on success.
  • true on success; false on a duplicate name, a null base model, or a load failure — each fails cleanly without corrupting state.

void entropic::AdapterManager::unload(const std::string &name, llama_context *ctx)

Unload adapter (any state -> COLD).

If HOT, clears from context first. Frees via llama_adapter_lora_free(). No-op if not found.

Parameters
  • name — Adapter identifier.
  • ctx — Context to deactivate from (if HOT). May be nullptr.
  • ctx — Context to clear from (if HOT). May be nullptr.

bool entropic::AdapterManager::activate(const std::string &name, llama_context *ctx)

Activate adapter on context (WARM -> HOT).

If another adapter is HOT, deactivates it first. Uses llama_set_adapters_lora() to apply the single adapter.

Parameters
  • name — Adapter identifier.
  • ctx — llama_context to activate on.
Returns
  • true on success.
  • true on success; false for an unknown adapter. At most one adapter is HOT per context, so any incumbent is deactivated first.

void entropic::AdapterManager::deactivate(llama_context *ctx)

Deactivate current HOT adapter (HOT -> WARM).

Clears all adapters from the context. No-op if none active.

Parameters
  • ctx — llama_context to clear adapter from.
  • ctx — llama_context to clear from.

bool entropic::AdapterManager::swap(const std::string &name, llama_context *ctx)

Swap to a different adapter atomically.

Deactivates current HOT adapter and activates the target. Fires ON_ADAPTER_SWAP hook which can cancel the operation.

Parameters
  • name — Target adapter (must be WARM).
  • ctx — llama_context to swap on.
Returns
  • true on success.
  • true on success; false when the target is COLD/unknown or the ON_ADAPTER_SWAP pre-hook vetoes. Swapping to the already-active adapter is a successful no-op.

void entropic::AdapterManager::unload_all_for_model(llama_model *model, llama_context *ctx)

Unload all adapters for a given base model.

Unload all adapters targeting a specific base model. Called when base model transitions out of ACTIVE/WARM. Prevents dangling adapter handles.

Parameters
  • model — The base model being unloaded.
  • ctx — Context to deactivate from. May be nullptr.
  • ctx — Context to clear from. May be nullptr.

void entropic::AdapterManager::release_handles_for_model(llama_model *model, llama_context *ctx)

Free a base model's adapter handles, KEEPING the registrations (gh#164).

Free a model's adapter handles, keeping the registrations (gh#164). The difference from unload_all_for_model is the whole point: that one ERASES the entries, which is right for a tier being replaced by another and wrong for one the consumer intends to bring back. entropic_release_model unloads a model expecting it to reload, so the name → (path, scale) registration must survive; only the llama_adapter_lora* cannot, because it belongs to the model being freed. Entries are left COLD with a null handle. load() re-initialises such an entry in place rather than refusing it as a duplicate, which is how preload_adapters_for_model re-binds them at the next activation. See the header for why this is a separate operation from unload_all_for_model rather than a flag on it. Entries are left COLD with a null handle; load() re-initialises such an entry in place.

Parameters
  • model — The base model being released.
  • ctx — Context to clear a HOT adapter from. May be nullptr.

void entropic::AdapterManager::unload_all()

Free every loaded adapter handle (gh#58 close-out, v2.3.0).

Called by ~ModelOrchestrator after backends are torn down, so by the time this runs the llama_contexts that referenced these adapters are already destroyed and there is no HOT-attachment to clear. Safe to call repeatedly. Without this, the bare AdapterManager destructor (defaulted) dropped raw llama_adapter_lora* handles on engine destroy, leaking each loaded LoRA's VRAM until process exit — the same pattern that caused gh#58's two-handle GPU regression for LlamaCppBackend in v2.2.8.

AdapterState entropic::AdapterManager::state(const std::string &name) const

Get adapter state.

Parameters
  • name — Adapter identifier.
Returns
AdapterState. COLD if not found.

AdapterInfo entropic::AdapterManager::info(const std::string &name) const

Get metadata for an adapter.

Parameters
  • name — Adapter identifier.
Returns
  • AdapterInfo. COLD state if not found.
  • AdapterInfo. COLD with empty name if not found.

std::vector< AdapterInfo > entropic::AdapterManager::list_adapters() const

List all known adapters.

Returns
  • Vector of AdapterInfo.
  • Vector of AdapterInfo snapshots.

std::string entropic::AdapterManager::active_adapter() const

Get the currently HOT adapter name.

Get currently HOT adapter name.

Returns
  • Adapter name, empty if none active.
  • Adapter name, empty if none. Safe under concurrent access with an in-flight swap.

void entropic::AdapterManager::set_hook_interface(const HookInterface &hooks)

Set hook interface for ON_ADAPTER_SWAP dispatch.

Set hook dispatch interface.

Parameters
  • hooks — Hook dispatch interface.
  • hooks — Hook interface from facade.

entropic::AdapterManager::AdapterEntry

std::string entropic::AdapterManager::AdapterEntry::name

Adapter identifier.

std::filesystem::path entropic::AdapterManager::AdapterEntry::path

.gguf file path

llama_adapter_lora* entropic::AdapterManager::AdapterEntry::handle

llama.cpp adapter handle

llama_model* entropic::AdapterManager::AdapterEntry::model

Base model this targets.

float entropic::AdapterManager::AdapterEntry::scale

LoRA scale factor.

AdapterState entropic::AdapterManager::AdapterEntry::state

Lifecycle state (mutex-protected)

size_t entropic::AdapterManager::AdapterEntry::ram_bytes

RAM consumed.

std::string entropic::AdapterManager::AdapterEntry::tier_name

Assigned tier.

std::unordered_map<std::string, std::string> entropic::AdapterManager::AdapterEntry::metadata

Routing metadata.