session_pool_util.h¶
src/inference/session_pool_util.h
@file session_pool_util.h @brief gh#144: derive a tier's KV geometry from max_sessions, purely.
Owners: @tvanfossen
derive_pool_geometry
PoolGeometry entropic::derive_pool_geometry(const ModelConfig &cfg)
Derive the context geometry a tier's config implies.
src/inference/session_pool_util.h:66
Called by SCENARIO, SCENARIO, bind_session_slot, build_cparams, prepare_batch_seqs
Calls none
Source · 22 lines
inline PoolGeometry derive_pool_geometry(const ModelConfig& cfg) {
const int sessions = std::max(1, cfg.max_sessions);
const int parallel = std::max(1, cfg.n_parallel);
PoolGeometry g;
g.n_seq_max = std::max(parallel, sessions);
// gh#98's same-prefix batch fan-out REQUIRES a unified buffer (seq_cp
// asserts on per-sequence buffers), so preserve that exactly — but a
// session pool must NOT be unified, per the header. The two are made
// mutually exclusive at configure time, so this can never be asked to
// satisfy both.
g.kv_unified = (parallel > 1) && (sessions <= 1);
// context_length is PER SESSION.
g.n_ctx = cfg.context_length * sessions;
// Sessions own seq ids [0, sessions). The batch fan-out's temp ids must
// start above them: allocate_temp_seq_id hands out 1, 2, 3... which
// would otherwise collide with session slots. The configure-time
// exclusion already makes this unreachable; raising the base is defence
// in depth against a future change that removes the exclusion silently.
g.temp_seq_base = std::max(1, sessions);
return g;
}Activity · 10 steps
Requirements
session_pool_conflict_reason
std::string entropic::session_pool_conflict_reason(const ModelConfig &cfg)
Why this tier's session-pool request cannot be honoured.
src/inference/session_pool_util.h:101
Source · 17 lines
inline std::string session_pool_conflict_reason(const ModelConfig& cfg) {
std::string reason;
if (cfg.max_sessions > 1) {
if (cfg.n_parallel > 1) {
reason = "max_sessions > 1 conflicts with n_parallel > 1: a "
"session pool needs private per-session KV streams, "
"while the same-prefix batch fan-out "
"(entropic_run_batch) needs a unified buffer. Set one "
"or the other, not both.";
} else if (cfg.context_length <= 0) {
reason = "max_sessions > 1 requires a positive context_length: "
"the pool allocates context_length * max_sessions "
"cells.";
}
}
return reason;
}