Skip to content

Add challenge 103: Repetition Penalty Logit Processor (Medium)#275

Open
claude[bot] wants to merge 1 commit into
mainfrom
add-challenge-103-repetition-penalty
Open

Add challenge 103: Repetition Penalty Logit Processor (Medium)#275
claude[bot] wants to merge 1 commit into
mainfrom
add-challenge-103-repetition-penalty

Conversation

@claude
Copy link
Copy Markdown
Contributor

@claude claude Bot commented May 29, 2026

Summary

  • Adds a new medium challenge: Repetition Penalty Logit Processor, the in-place sampler step used by LLM inference engines (HuggingFace Transformers, vLLM, TGI) to discourage repeating tokens already seen in the prompt or prior generation.
  • Per-batch, scales logits[b, v] by 1/penalty (positive logits) or penalty (negative logits) for every unique token id v present in input_ids[b]. Duplicate ids count only once.
  • Tests the solver's ability to avoid the naive O(B·V·T) per-thread scan by building a per-batch presence bitmap (O(B·(V+T))).

Test plan

  • Reference impl verified to match the HuggingFace RepetitionPenaltyLogitsProcessor semantics on hand-checked example.
  • 10 functional cases cover edge sizes (B=1, V=4–5, T=1), zero logits, mixed signs, multi-batch, non-powers-of-two, and realistic vocabulary sizes (V=32k).
  • Performance test uses B=64, V=131,072, T=4,096 (≈33MB logits + 1MB ids) — Llama-class vocab, fits 5× in 16GB Tesla T4 VRAM.
  • pre-commit run --all-files passes.
  • CUDA solution validated against the live T4 runner via scripts/run_challenge.py --action submitall tests passed.

🤖 Generated with Claude Code

Implements the repetition penalty sampler used by LLM inference engines
(HuggingFace Transformers, vLLM, TGI) to discourage repeating tokens that
already appeared in the prompt or prior generation. Applies the penalty
once per unique token id, dividing positive logits and multiplying
negative logits.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.

0 participants