Entropic 2.9.4
Local-first agentic inference engine
Loading...
Searching...
No Matches
batch_util.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
13#ifndef ENTROPIC_INFERENCE_BATCH_UTIL_H
14#define ENTROPIC_INFERENCE_BATCH_UTIL_H
15
16#include <algorithm>
17#include <cstddef>
18#include <vector>
19
20#include "warm_keep_util.h" // common_prefix_len
21
22namespace entropic {
23
42template <typename Tok>
43inline std::size_t batch_shared_prefix_len(
44 const std::vector<std::vector<Tok>>& seqs) {
45 if (seqs.size() < 2) { return 0; }
46 std::size_t shortest = seqs[0].size();
47 std::size_t shared = seqs[0].size();
48 for (std::size_t i = 1; i < seqs.size(); ++i) {
49 shortest = std::min(shortest, seqs[i].size());
50 shared = std::min(shared, common_prefix_len(seqs[0], seqs[i]));
51 }
52 if (shortest == 0) { return 0; }
53 return std::min(shared, shortest - 1);
54}
55
80inline bool batch_is_viable(std::size_t n, int n_parallel, std::size_t shared,
81 bool hybrid, std::size_t total_suffix,
82 int n_batch) {
83 return n >= 2
84 && !hybrid
85 && n_parallel >= 1
86 && n <= static_cast<std::size_t>(n_parallel)
87 && shared > 0
88 && total_suffix <= static_cast<std::size_t>(n_batch);
89}
90
91} // namespace entropic
92
93#endif // ENTROPIC_INFERENCE_BATCH_UTIL_H
Activate model on GPU (WARM → ACTIVE).
bool batch_is_viable(std::size_t n, int n_parallel, std::size_t shared, bool hybrid, std::size_t total_suffix, int n_batch)
Decide whether the same-prefix batch fast-path is safe + worthwhile.
Definition batch_util.h:80
std::size_t common_prefix_len(const std::vector< Tok > &a, const std::vector< Tok > &b)
Length of the longest common token prefix of two sequences.
std::size_t batch_shared_prefix_len(const std::vector< std::vector< Tok > > &seqs)
Longest shared token prefix across N request sequences (gh#98).
Definition batch_util.h:43
gh#96 (v2.7.5) warm-keep / incremental-prefill decision logic.