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

Method sample_prob

src/sampler.cpp:12–26  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10}
11
12float Sampler::sample_prob(int index, const InferenceState& s) {
13 const float* logits = s.logits();
14 // Find max value to moderate the logits later on for numerical stability
15 float max_val = -FLT_MAX;
16 for (int i = 0; i < vocab_size; ++i) {
17 if (logits[i] > max_val) {
18 max_val = logits[i];
19 }
20 }
21 float sum = 0;
22 for (int i = 0; i < vocab_size; ++i) {
23 sum += expf(logits[i] - max_val);
24 }
25 return expf(logits[index] - max_val) / sum;
26}
27
28int Sampler::sample_argmax(const InferenceState& s) {
29 const float* logits = s.logits();

Callers 1

run_perplexityFunction · 0.80

Calls 1

logitsMethod · 0.80

Tested by

no test coverage detected