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

Function softmax

tools/perplexity/perplexity.cpp:40–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38};
39
40static std::vector<float> softmax(const std::vector<float>& logits) {
41 std::vector<float> probs(logits.size());
42 float max_logit = logits[0];
43 for (float v : logits) {
44 max_logit = std::max(max_logit, v);
45 }
46 double sum_exp = 0.0;
47 for (size_t i = 0; i < logits.size(); i++) {
48 // Subtract the maximum logit value from the current logit value for numerical stability
49 const float logit = logits[i] - max_logit;
50 const float exp_logit = expf(logit);
51 sum_exp += exp_logit;
52 probs[i] = exp_logit;
53 }
54 for (size_t i = 0; i < probs.size(); i++) {
55 probs[i] /= sum_exp;
56 }
57 return probs;
58}
59
60static results_log_softmax log_softmax(int n_vocab, const float * logits, int tok) {
61 float max_logit = logits[0];

Callers 3

perplexity_v2Function · 0.70
hellaswag_scoreFunction · 0.70
multiple_choice_scoreFunction · 0.70

Calls 2

maxFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected