| 124 | } |
| 125 | |
| 126 | llama_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 | } |
nothing calls this directly
no test coverage detected