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

Function process_logits

examples/perplexity/perplexity.cpp:111–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

109}
110
111static void process_logits(
112 int n_vocab, const float * logits, const int * tokens, int n_token, std::vector<std::thread> & workers,
113 double & nll, double & nll2, float * logit_history, float * prob_history
114) {
115 std::mutex mutex;
116 int counter = 0;
117 auto compute = [&mutex, &counter, &nll, &nll2, logit_history, prob_history, n_vocab, logits, tokens, n_token] () {
118 double local_nll = 0;
119 double local_nll2 = 0;
120 while (true) {
121 std::unique_lock<std::mutex> lock(mutex);
122 int i = counter++;
123 if (i >= n_token) {
124 nll += local_nll; nll2 += local_nll2;
125 break;
126 }
127 lock.unlock();
128 const results_log_softmax results = log_softmax(n_vocab, logits + i*n_vocab, tokens[i+1]);
129 const double v = -results.log_softmax;
130 local_nll += v;
131 local_nll2 += v*v;
132
133 logit_history[i] = results.logit;
134 prob_history[i] = results.prob;
135 }
136 };
137 for (auto & w : workers) {
138 w = std::thread(compute);
139 }
140 compute();
141 for (auto & w : workers) {
142 w.join();
143 }
144}
145
146static results_perplexity perplexity_v2(llama_context * ctx, const gpt_params & params) {
147 // Download: https://s3.amazonaws.com/research.metamind.io/wikitext/wikitext-2-raw-v1.zip?ref=salesforce-research

Callers 1

perplexityFunction · 0.70

Calls 3

unlockMethod · 0.80
joinMethod · 0.80
log_softmaxFunction · 0.70

Tested by

no test coverage detected