40#include <unordered_map>
41#include <unordered_set>
163 const std::vector<Message>& messages,
165 const std::string& tier_name =
"");
177 const std::vector<Message>& messages,
179 std::atomic<bool>& cancel,
180 const std::string& tier_name =
"");
200 const std::vector<std::vector<Message>>& messages_list,
201 const std::vector<GenerationParams>& params_list,
202 const std::vector<std::string>& tiers,
203 std::atomic<bool>& cancel);
210 const std::vector<Message>& messages,
212 std::function<
void(std::string_view)> on_token,
213 std::atomic<bool>& cancel,
214 const std::string& tier_name =
"");
224 std::string
route(
const std::vector<Message>& messages);
256 bool can_handoff(
const std::string& from,
const std::string& to)
const;
414 const std::string& tier_name,
415 const std::string& model_path,
524 const std::string& tier_name) {
525 apply_tier_sampler_defaults(params, tier_name);
530 std::unordered_map<std::string, std::shared_ptr<InferenceBackend>> model_pool_;
533 std::unordered_map<std::string, std::shared_ptr<InferenceBackend>> tiers_;
536 std::unordered_map<std::string, std::unique_ptr<ChatAdapter>> adapters_;
552 std::unordered_map<std::string, std::string> tier_map_;
553 std::unordered_map<std::string, std::unordered_set<std::string>> handoff_rules_;
554 std::string default_tier_;
555 std::string loaded_main_tier_;
557 std::vector<std::string> tier_history_;
559 mutable std::mutex swap_mutex_;
574 mutable std::unordered_map<std::string, size_t> tier_footprint_bytes_;
582 std::unordered_map<std::string, long long> tier_last_activation_ms_;
588 std::chrono::steady_clock::time_point start_time_{std::chrono::steady_clock::now()};
599 size_t vram_budget_bytes_{0};
626 size_t estimate_footprint_bytes(
const std::string& tier_name)
const;
638 static size_t resolve_vram_budget_bytes();
650 void fire_residency_observer(
652 const std::string& tier_name,
653 const std::string& model_path,
657 AdapterManager lora_manager_;
660 GrammarRegistry grammar_registry_;
663 ProfileRegistry profile_registry_;
666 ThroughputTracker throughput_tracker_;
674 InferenceBackend* get_model(
const std::string& tier_name);
683 void record_activation_reuse(
const std::string& tier_name);
692 bool residency_admits(
const std::string& tier_name);
700 InferenceBackend* activate_and_track(
701 const std::string& tier_name,
702 const std::shared_ptr<InferenceBackend>& backend);
711 GenerationResult build_no_model_error(
const std::string& tier_name);
717 void deactivate_current_if_needed(InferenceBackend* incoming);
731 void ensure_tier_lora(
const std::string& tier_name,
732 InferenceBackend* result);
744 void unload_or_warm_current(InferenceBackend* current);
750 std::pair<std::string, std::string> classify_task(
751 const std::vector<Message>& messages);
759 bool deactivate_if_active(llama_context* ctx);
772 double ensure_adapter_for_tier(
773 const std::string& tier_name, llama_context* ctx);
779 void preload_adapters();
788 bool create_tier_backends(
const ParsedConfig& config);
796 void build_routing_tables(
const ParsedConfig& config);
805 bool activate_default_tier(
const ParsedConfig& config);
813 void activate_router(
const ParsedConfig& config);
830 void activate_draft(
const ParsedConfig& config);
836 void load_bundled_grammars();
844 void resolve_grammar_key(GenerationParams& params,
845 const std::string& tier_name);
859 void apply_tier_sampler_defaults(GenerationParams& params,
860 const std::string& tier_name);
877 GenerationParams resolve_and_stage(InferenceBackend* model,
878 const GenerationParams& params,
879 const std::string& tier_name);
891 std::string resolve_speculative_pair(
892 llama_model*& target_out, llama_model*& draft_out)
const;
903 bool try_speculative_route(
904 InferenceBackend* model,
905 const std::vector<Message>& messages,
906 const GenerationParams& params,
907 const std::string& tier_name,
908 GenerationResult& result);
920 GenerationResult run_generate_dispatch(
921 InferenceBackend* model,
922 const std::vector<Message>& messages,
923 const GenerationParams& params,
924 const std::string& tier_name);
935 bool try_speculative_route_streaming(
936 InferenceBackend* model,
937 const std::vector<Message>& messages,
938 const GenerationParams& params,
939 const std::string& tier_name,
940 std::function<
void(std::string_view)> on_token,
941 std::atomic<bool>& cancel,
942 GenerationResult& result);
955 InferenceBackend* model,
956 const std::vector<Message>& messages,
957 const GenerationParams& params,
958 std::function<
void(std::string_view)> on_token,
959 std::atomic<bool>& cancel,
960 GenerationResult& result);
971 bool resolve_mtp_effective(
const std::string& tier_name)
const;
ChatAdapter concrete base class.
AdapterManager — LoRA adapter lifecycle and hot-swap.
LoRA adapter lifecycle manager.
Concrete base class for chat format adapters (80% logic).
Centralized grammar registry for named GBNF grammars.
Concrete base class for inference backends (80% logic).
Multi-model lifecycle and routing orchestrator.
size_t vram_budget_bytes() const
Engine-tracked VRAM budget in bytes (0 = unknown).
SpeculativeCompatInfo check_speculative_compat() const
Check whether the currently-configured target/draft pair is compatible for speculative decoding.
std::vector< std::string > available_models() const
All configured tier names.
size_t load_grammars_from(const std::filesystem::path &grammar_dir)
Load grammars from an explicit directory path.
GrammarRegistry & grammar_registry()
Access the grammar registry.
GenerationResult generate_streaming(const std::vector< Message > &messages, const GenerationParams ¶ms, std::function< void(std::string_view)> on_token, std::atomic< bool > &cancel, const std::string &tier_name="")
Streaming generation.
void apply_tier_sampler_defaults_for_test(GenerationParams ¶ms, const std::string &tier_name)
Test-only forwarder to the private per-tier sampler default application (gh#94, audit task #71).
std::vector< std::string > loaded_models() const
Currently loaded model tier names.
bool initialize(const ParsedConfig &config)
Initialize from parsed config.
bool has_vision_capable_tier() const
Return true if any configured tier declares the "vision" capability (gh#41, v2.1.8).
size_t tier_footprint_bytes(const std::string &tier_name) const
Estimated VRAM footprint for a given tier in bytes.
AdapterManager & adapter_manager()
Access the LoRA adapter manager.
void shutdown()
Shutdown — unload all models.
RoutingResult last_routing_result() const
Last routing result.
std::function< void(ResidencyEvent event, const std::string &tier_name, const std::string &model_path, size_t footprint)> ResidencyObserverFn
Residency observer callback type (internal C++ form).
GenerationResult generate(const std::vector< Message > &messages, const GenerationParams ¶ms, const std::string &tier_name="")
Generate using routed or explicit tier.
void clear_last_residency_error()
Clear last_residency_error().
void clear_all_prompt_caches()
Invalidate prompt/KV caches across every pooled backend.
entropic_error_t last_residency_error() const
Last residency-related error code, or ENTROPIC_OK if none.
std::string route(const std::vector< Message > &messages)
Route to tier using router model.
ChatAdapter * get_adapter(const std::string &tier_name) const
Get adapter for a tier.
void set_residency_observer(ResidencyObserverFn cb)
Register a residency observer.
std::string last_used_tier() const
Last used tier name.
~ModelOrchestrator()
Destructor — invokes shutdown() and AdapterManager::unload_all().
std::vector< GenerationResult > generate_batch(const std::vector< std::vector< Message > > &messages_list, const std::vector< GenerationParams > ¶ms_list, const std::vector< std::string > &tiers, std::atomic< bool > &cancel)
Same-prefix batch generation on a shared resident model (gh#98).
std::string select_vision_tier() const
Pick the canonical vision-capable tier name (gh#41).
ProfileRegistry & profile_registry()
Access the GPU resource profile registry.
ThroughputTracker & throughput_tracker()
Access the throughput tracker.
void set_speculative_enabled(bool enabled)
Runtime toggle for the speculative-decoding path.
bool can_handoff(const std::string &from, const std::string &to) const
Check if handoff is permitted.
std::string residency_snapshot_json() const
Serialize the current residency set as a JSON string.
ResidencyEvent
Residency observer event codes — mirror the C ABI enum entropic_residency_event_t exactly (LOADED=0,...
InferenceBackend * get_backend(const std::string &tier_name) const
Get the inference backend for a tier (for evaluation APIs).
Centralized registry for named GPU resource profiles.
Role-keyed lifecycle manager for non-primary models.
EWMA-based throughput tracker for generation budgeting.
Configuration structs with defaults.
Error types for cross-.so error reporting.
entropic_error_t
Error codes returned by all C API functions.
GrammarRegistry — named grammar management and validation.
InferenceBackend concrete base class.
Activate model on GPU (WARM → ACTIVE).
ENTROPIC_EXPORT void apply_tier_sampler_overrides(GenerationParams ¶ms, const TierSamplerOverrides &ov)
Apply per-tier sampler overrides to params.
ProfileRegistry – named GPU resource profile management.
Unified lifecycle for non-primary inference backends.
Generation parameters for a single inference call.
Result of a single generation call.
SpeculativeConfig speculative
Speculative decoding (gh#36)
Result of a speculative-decoding compatibility check.
bool compatible
true when speculative may proceed
std::string diagnostic
Reason on failure (empty on ok)
Full parsed configuration.
InferenceConfig inference
Inference-side knobs (currently speculative decoding only).
Result metadata from a routing decision.
std::string adapter_name
Active adapter (empty = base model) (v1.9.2)
double routing_ms
Total routing time.
std::string model_raw
Raw model output (e.g. "2")
std::string tier_name
Selected tier.
std::string swap_action
"none", "reused", "loaded"
std::string previous_tier
Previous tier (empty if first)
double adapter_swap_ms
Adapter swap latency (v1.9.2)
bool enabled
Master switch (off by default)
Per-tier sampler overrides parsed from identity frontmatter.
std::optional< float > top_p
gh#85
std::optional< float > temperature
gh#82
std::optional< float > min_p
gh#85
std::optional< float > presence_penalty
gh#85
std::optional< std::string > tool_call_mode
gh#103
std::optional< float > frequency_penalty
gh#85
std::optional< int > top_k
gh#85
std::optional< bool > enable_thinking
gh#86
std::optional< float > repeat_penalty
gh#86
std::optional< int > max_output_tokens
gh#82
ThroughputTracker – real-time throughput measurement and prediction.