| 107 | } |
| 108 | |
| 109 | static 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 | |
| 144 | static 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) { |
no test coverage detected