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

Show on the map →

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
lines 67–67const int sessions = std::max(1, cfg.max_sessions);lines 68–68const int parallel = std::max(1, cfg.n_parallel);lines 70–70PoolGeometry g;lines 71–71g.n_seq_max = std::lines 71–71max(parallel, sessions);lines 77–77g.kv_unified = (parallel > 1) && (sessions <= 1);lines 79–79g.n_ctx = cfg.context_length * sessions;lines 85–85g.temp_seq_base = std::lines 85–85max(1, sessions);lines 86–86return g;

Requirements

REQ-INFER-019

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

Show on the map →

Called by SCENARIO, validate

Calls none

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;
}
Activity · 8 steps
lines 102–102std::string reason;lines 103–103◇ if (cfg.max_sessions > 1)lines 104–104◇ if (cfg.n_parallel > 1)lines 105–109reason = "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.";lines 110–110elselines 110–110◇ if (cfg.context_length <= 0)lines 111–113reason = "max_sessions > 1 requires a positive context_length: " "the pool allocates context_length * max_sessions " "cells.";lines 116–116return reason;

Requirements

REQ-INFER-019