sample: make mutations in transforms explicit (#9743)

* updated minP to use early exit making use of sorted tokens
This commit is contained in:
Parth Sareen
2025-03-17 11:24:18 -07:00
committed by GitHub
parent 50b5962042
commit 108fe02165
3 changed files with 110 additions and 72 deletions

View File

@@ -87,8 +87,9 @@ func (s *Sampler) sample(tokens []token) (token, error) {
// topK also sorts the tokens in descending order of logits
tokens = topK(tokens, s.topK)
tokens = temperature(tokens, s.temperature)
tokens = softmax(tokens)
// scale and normalize the tokens in place
temperature(tokens, s.temperature)
softmax(tokens)
tokens = topP(tokens, s.topP)
tokens = minP(tokens, s.minP)