MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / split_equal

Method split_equal

smallthinker/src/llama-batch.cpp:161–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

159}
160
161llama_ubatch llama_sbatch::split_equal(size_t n_ubatch) {
162 n_ubatch = n_tokens < n_ubatch ? n_tokens : n_ubatch;
163 llama_ubatch ubatch = reserve_ubatch(n_ubatch, /* has_embd */ batch->embd != nullptr);
164 if (!seq.empty()) {
165 size_t length = 0;
166 size_t n_tokens_in_ubatch = 0;
167 GGML_ASSERT(seq[0].n_seq_id > 0); // should not be mixed with simple splits
168 // smallest first, because it's easier to split this way;
169 // starting from the end to pop in constant time.
170 for (size_t i = seq.size(); i-- > 0;) {
171 llama_sbatch_seq & s = seq[i];
172 GGML_ASSERT(s.length > 0);
173 if (length == 0) {
174 length = s.length < n_ubatch ? s.length : n_ubatch;
175 }
176 add_seq_to_ubatch(ubatch, s, length);
177 n_tokens_in_ubatch += length;
178 // shared prompts can't be mixed with any of their sequences,
179 // so it's safer to compute them in their own ubatch
180 if (s.n_seq_id > 1) { break; }
181 // stop when there isn't enough space for another sequence
182 if (length + n_tokens_in_ubatch > n_ubatch) { break; }
183 }
184 }
185 return ubatch;
186}
187
188llama_ubatch llama_sbatch::split_seq(size_t n_ubatch) {
189 n_ubatch = n_tokens < n_ubatch ? n_tokens : n_ubatch;

Callers 1

init_batchMethod · 0.80

Calls 2

emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected