MCPcopy Create free account
hub / github.com/antirez/llama.cpp-deepseek-v4-flash / process_logits

Function process_logits

tools/perplexity/perplexity.cpp:109–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

107}
108
109static void process_logits(
110 int n_vocab, const float * logits, const int * tokens, int n_token, std::vector<std::thread> & workers,
111 double & nll, double & nll2, float * logit_history, float * prob_history
112) {
113 std::mutex mutex;
114 int counter = 0;
115 auto compute = [&mutex, &counter, &nll, &nll2, logit_history, prob_history, n_vocab, logits, tokens, n_token] () {
116 double local_nll = 0;
117 double local_nll2 = 0;
118 while (true) {
119 std::unique_lock<std::mutex> lock(mutex);
120 int i = counter++;
121 if (i >= n_token) {
122 nll += local_nll; nll2 += local_nll2;
123 break;
124 }
125 lock.unlock();
126 const results_log_softmax results = log_softmax(n_vocab, logits + size_t(i)*n_vocab, tokens[i+1]);
127 const double v = -results.log_softmax;
128 local_nll += v;
129 local_nll2 += v*v;
130
131 logit_history[i] = results.logit;
132 prob_history[i] = results.prob;
133 }
134 };
135 for (auto & w : workers) {
136 w = std::thread(compute);
137 }
138 compute();
139 for (auto & w : workers) {
140 w.join();
141 }
142}
143
144static void process_logits(std::ostream& out, int n_vocab, const float * logits, const int * tokens, int n_token,
145 std::vector<std::thread> & workers, std::vector<uint16_t> & log_probs, double & nll, double & nll2) {

Callers 2

perplexityFunction · 0.70
kl_divergenceFunction · 0.70

Calls 4

maxFunction · 0.85
log_softmaxFunction · 0.70
dataMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected