MCPcopy Create free account
hub / github.com/andrewkchan/deepseek.cpp / softmax

Function softmax

src/infer.cpp:472–487  ·  view source on GitHub ↗

Compute the softmax of an input vector `x` of length `size` and store it in `o`.

Source from the content-addressed store, hash-verified

470
471// Compute the softmax of an input vector `x` of length `size` and store it in `o`.
472static void softmax(float* o, float* x, int size) {
473 float score_max = -FLT_MAX;
474 for (int i = 0; i < size; ++i) {
475 if (x[i] > score_max) {
476 score_max = x[i];
477 }
478 }
479 float score_sum = 0.0f;
480 for (int i = 0; i < size; ++i) {
481 o[i] = expf(x[i] - score_max);
482 score_sum += o[i];
483 }
484 for (int i = 0; i < size; ++i) {
485 o[i] /= score_sum;
486 }
487}
488
489inline float sigmoid(float x) {
490 return 1.0f / (1.0f + expf(-x));

Callers 3

moe_gateFunction · 0.85
attnFunction · 0.85
attn_mlaFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected