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

Function decode_helper

smallthinker/tools/perplexity/perplexity.cpp:661–693  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

659}
660
661static bool decode_helper(llama_context * ctx, llama_batch & batch, std::vector<float> & batch_logits, int n_batch, int n_vocab) {
662 int prev_outputs = 0;
663 for (int i = 0; i < (int) batch.n_tokens; i += n_batch) {
664 const int n_tokens = std::min<int>(n_batch, batch.n_tokens - i);
665
666 llama_batch batch_view = {
667 n_tokens,
668 batch.token + i,
669 nullptr,
670 batch.pos + i,
671 batch.n_seq_id + i,
672 batch.seq_id + i,
673 batch.logits + i,
674 };
675
676 const int ret = llama_decode(ctx, batch_view);
677 if (ret != 0) {
678 LOG_ERR("failed to decode the batch, n_batch = %d, ret = %d\n", n_batch, ret);
679 return false;
680 }
681
682 int n_outputs = 0;
683 for (int i = 0; i < n_tokens; ++i) {
684 n_outputs += batch_view.logits[i] != 0;
685 }
686
687 memcpy(batch_logits.data() + size_t(prev_outputs)*n_vocab, llama_get_logits(ctx), size_t(n_outputs)*n_vocab*sizeof(float));
688
689 prev_outputs += n_outputs;
690 }
691
692 return true;
693}
694
695#define K_TOKEN_CHUNK 4
696

Callers 5

mainFunction · 0.85
hellaswag_scoreFunction · 0.85
winogrande_scoreFunction · 0.85
multiple_choice_scoreFunction · 0.85
mainFunction · 0.85

Calls 3

llama_decodeFunction · 0.50
llama_get_logitsFunction · 0.50
dataMethod · 0.45

Tested by

no test coverage detected