Skip to content
← Implement-from-Scratch Coding / 23
hardNewOpenAITogether AIFireworks AI

Implement repetition, frequency and presence penalties and min-p for a batched sampler, in the engine's order.

Dividing every seen token's logit by the repetition penalty makes negative-logit tokens more likely, and counting repeats with one NumPy line counts each token once. The answer gets both right, fixes the order of the stage, and derives min-p without a softmax.

Updated Oct 2026 · Worked answers on inference mechanisms, with calculations, implementation details, and follow-up questions.

Dividing every seen token's logit by the repetition penalty makes negative-logit tokens more likely, and counting repeats with one NumPy line counts each token once. The answer gets both right, fixes the order of the stage, and derives min-p without a softmax.

10 answers per topic instead of 5, plus saved progress and bookmarks · costs nothingor unlock all 213 remaining answers · $25

Every worked answer and derivation in all 12 topics, every concept page, the full practice-test bank, and every code drill’s edge-case tests and reference solution.

6 months · One payment · No auto-renewal

UP NEXT ON YOUR JOURNEY
DISCUSSION · 0

Nobody has commented on this answer. Add a correction or another way to work it.