MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / init_batch

Method init_batch

subprojects/llama.cpp/src/llama-kv-cache-iswa.cpp:126–210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

124}
125
126llama_memory_context_ptr llama_kv_cache_iswa::init_batch(llama_batch_allocr & balloc, uint32_t n_ubatch, bool embd_all) {
127 GGML_UNUSED(embd_all);
128
129 // first try simple split
130 do {
131 if (!unified) {
132 // requires equal splits, so we skip the simple split
133 break;
134 }
135
136 balloc.split_reset();
137
138 std::vector<llama_ubatch> ubatches;
139 while (true) {
140 auto ubatch = balloc.split_simple(n_ubatch);
141
142 if (ubatch.n_tokens == 0) {
143 break;
144 }
145
146 ubatches.push_back(std::move(ubatch)); // NOLINT
147 }
148
149 if (balloc.get_n_used() < balloc.get_n_tokens()) {
150 // failed to find a suitable split
151 break;
152 }
153
154 auto sinfos_base = kv_base->prepare(ubatches);
155 if (sinfos_base.empty()) {
156 break;
157 }
158
159 auto sinfos_swa = kv_swa->prepare(ubatches);
160 if (sinfos_swa.empty()) {
161 break;
162 }
163
164 assert(sinfos_base.size() == sinfos_swa.size());
165
166 return std::make_unique<llama_kv_cache_iswa_context>(
167 this, std::move(sinfos_base), std::move(sinfos_swa), std::move(ubatches));
168 } while (false);
169
170 // if it fails, try equal split
171 do {
172 balloc.split_reset();
173
174 std::vector<llama_ubatch> ubatches;
175 while (true) {
176 auto ubatch = balloc.split_equal(n_ubatch, !unified);
177
178 if (ubatch.n_tokens == 0) {
179 break;
180 }
181
182 ubatches.push_back(std::move(ubatch)); // NOLINT
183 }

Callers

nothing calls this directly

Calls 9

split_resetMethod · 0.80
split_simpleMethod · 0.80
get_n_usedMethod · 0.80
get_n_tokensMethod · 0.80
split_equalMethod · 0.80
emptyMethod · 0.65
sizeMethod · 0.65
push_backMethod · 0.45
prepareMethod · 0.45

Tested by

no test coverage detected