| 26 | } |
| 27 | |
| 28 | int Sampler::sample_argmax(const InferenceState& s) { |
| 29 | const float* logits = s.logits(); |
| 30 | int argmax = 0; |
| 31 | float max_val = -FLT_MAX; |
| 32 | for (int i = 0; i < vocab_size; ++i) { |
| 33 | if (logits[i] > max_val) { |
| 34 | max_val = logits[i]; |
| 35 | argmax = i; |
| 36 | } |
| 37 | } |
| 38 | return argmax; |
| 39 | } |
| 40 | |
| 41 | int Sampler::sample(const InferenceState& s, float temperature, float top_p) { |
| 42 | if (temperature == 0.0) { |