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

Function common_sampler_sample_and_accept_n

smallthinker/common/sampling.cpp:384–412  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

382}
383
384std::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
414std::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);

Callers 2

update_slotsMethod · 0.85
mainFunction · 0.85

Calls 5

common_sampler_sampleFunction · 0.85
common_sampler_acceptFunction · 0.85
reserveMethod · 0.80
sizeMethod · 0.45
push_backMethod · 0.45

Tested by 1

mainFunction · 0.68