batch_kv_util.h¶
src/inference/batch_kv_util.h
@file batch_kv_util.h @brief gh#158: which sequences a same-prefix batch may touch, purely.
Owners: @tvanfossen
plan_batch_kv
BatchKvPlan entropic::plan_batch_kv(std::size_t n, int session_slots, const std::vector< int > &temp_ids)
Plan the sequence ids a same-prefix batch may use.
src/inference/batch_kv_util.h:69
Source · 17 lines
inline BatchKvPlan plan_batch_kv(std::size_t n, int session_slots,
const std::vector<int>& temp_ids) {
BatchKvPlan plan;
plan.clears_whole_cache = false;
plan.seq_ids.reserve(n);
const int floor_id = session_slots < 1 ? 1 : session_slots;
for (std::size_t i = 0; i < n && i < temp_ids.size(); ++i) {
// Defence in depth: a temp pool whose base was never raised past the
// session slots would otherwise hand back a session's sequence. The
// configure-time exclusion in session_pool_util.h makes that
// unreachable today; this makes it unreachable by construction.
plan.seq_ids.push_back(
temp_ids[i] < floor_id ? floor_id + static_cast<int>(i)
: temp_ids[i]);
}
return plan;
}Activity · 7 steps
Requirements
plan_disturbs_sessions
bool entropic::plan_disturbs_sessions(const BatchKvPlan &plan, int session_slots)
Whether a plan can disturb any session's resident KV.
src/inference/batch_kv_util.h:100
Source · 9 lines
inline bool plan_disturbs_sessions(const BatchKvPlan& plan,
int session_slots) {
if (plan.clears_whole_cache) { return true; }
bool disturbs = false;
for (int id : plan.seq_ids) {
if (id < session_slots) { disturbs = true; }
}
return disturbs;
}