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

Function log_softmax

examples/perplexity/perplexity.cpp:99–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

97}
98
99static results_log_softmax log_softmax(int n_vocab, const float * logits, int tok) {
100 float max_logit = logits[0];
101 for (int i = 1; i < n_vocab; ++i) {
102 max_logit = std::max(max_logit, logits[i]);
103 }
104 double sum_exp = 0.0;
105 for (int i = 0; i < n_vocab; ++i) {
106 sum_exp += expf(logits[i] - max_logit);
107 }
108 return {logits[tok] - max_logit - log(sum_exp), logits[tok], expf(logits[tok] - max_logit) / (float) sum_exp};
109}
110
111static void process_logits(
112 int n_vocab, const float * logits, const int * tokens, int n_token, std::vector<std::thread> & workers,

Callers 1

process_logitsFunction · 0.70

Calls 2

maxFunction · 0.85
logFunction · 0.85

Tested by

no test coverage detected