Skip to content

fix: apply temperature scaling to logits before softmax in sampler#161

Open
zhuxiaoxuhit wants to merge 1 commit intoMoonshotAI:masterfrom
zhuxiaoxuhit:fix/temperature-scaling-in-sampler
Open

fix: apply temperature scaling to logits before softmax in sampler#161
zhuxiaoxuhit wants to merge 1 commit intoMoonshotAI:masterfrom
zhuxiaoxuhit:fix/temperature-scaling-in-sampler

Conversation

@zhuxiaoxuhit
Copy link
Copy Markdown

Temperature sampling requires dividing raw logits by T before softmax, i.e. softmax(logits / T). The previous code applied temperature after log_softmax (logprobs / T), which computes softmax(logits)^(1/T) — a mathematically different distribution whose denominator is (Σ exp(logit_j))^(1/T) instead of Σ exp(logit_j / T). This produces incorrect sampling distributions whenever temperature > 0 is used.

Fix applied to both sample_audio_logits and sample_text_logits.

Temperature sampling requires dividing raw logits by T before softmax,
i.e. softmax(logits / T). The previous code applied temperature after
log_softmax (logprobs / T), which computes softmax(logits)^(1/T) — a
mathematically different distribution whose denominator is
(Σ exp(logit_j))^(1/T) instead of Σ exp(logit_j / T). This produces
incorrect sampling distributions whenever temperature > 0 is used.

Fix applied to both sample_audio_logits and sample_text_logits.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant