| 382 | } |
| 383 | |
| 384 | std::vector<llama_token> common_sampler_sample_and_accept_n(struct common_sampler * gsmpl, struct llama_context * ctx, const std::vector<int> & idxs, const llama_tokens & draft, bool grammar_first) { |
| 385 | GGML_ASSERT(idxs.size() == draft.size() + 1 && "idxs.size() must be draft.size() + 1"); |
| 386 | |
| 387 | std::vector<llama_token> result; |
| 388 | result.reserve(idxs.size()); |
| 389 | |
| 390 | size_t i = 0; |
| 391 | for (; i < draft.size(); i++) { |
| 392 | const llama_token id = common_sampler_sample(gsmpl, ctx, idxs[i], grammar_first); |
| 393 | |
| 394 | common_sampler_accept(gsmpl, id, true); |
| 395 | |
| 396 | result.push_back(id); |
| 397 | |
| 398 | if (draft[i] != id) { |
| 399 | break; |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | if (i == draft.size()) { |
| 404 | const llama_token id = common_sampler_sample(gsmpl, ctx, idxs[i], grammar_first); |
| 405 | |
| 406 | common_sampler_accept(gsmpl, id, true); |
| 407 | |
| 408 | result.push_back(id); |
| 409 | } |
| 410 | |
| 411 | return result; |
| 412 | } |
| 413 | |
| 414 | std::vector<llama_token> common_sampler_sample_and_accept_n(struct common_sampler * gsmpl, struct llama_context * ctx, const llama_tokens & draft, bool grammar_first) { |
| 415 | std::vector<int> idxs(draft.size() + 1); |