Skip to content

Add challenge 121: Fused Logit Penalties (Medium) - #334

Open
claude[bot] wants to merge 1 commit into
mainfrom
add-challenge-121-fused-logit-penalties
Open

claude[bot] wants to merge 1 commit into
mainfrom
add-challenge-121-fused-logit-penalties

Conversation

@claude

@claude claude Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds challenge 121: Fused Logit Penalties (Medium) — the logit-processor stage that vLLM, SGLang and HF TGI run on every decode step, right before sampling.

Given a batch of B in-flight requests, each with a V-wide logit row, its prompt/generated token histories (-1-padded), and its own penalty coefficients, the solver produces the penalized logits:

  1. Repetition (multiplicative, keyed on prompt ∪ generated tokens): z /= r if z > 0, else z *= r
  2. Frequency (keyed on generated counts): z -= frequency_penalty * count
  3. Presence (flat, keyed on generated presence): z -= presence_penalty if count > 0

Why this is a worthwhile GPU problem

V (up to 131,072) dwarfs the token histories, so the obvious "scan the history for each vocabulary entry" approach is hopelessly slow. A good solution builds the per-request occurrence table with a scatter (atomics or privatized counters), then streams the logits in a single bandwidth-bound pass. Padding slots and the asymmetry between the three penalties (two different "seen" predicates) add real bookkeeping. It is not an element-wise map.

No overlap with existing sampling challenges (29 top-k, 60 top-p, 104 min-p) — those select/renormalize, this one is a gather/scatter histogram problem — and no overlap with any open PR topic or number.

Contents

  • challenge.py — reference impl (standard PyTorch scatter_add_ / where, CUDA + XLA safe), 10 functional tests (edge sizes 1–4, powers of 2, 100/255 non-powers of 2, zeros, negatives, all-padding rows, penalty no-ops, realistic 32k-vocab decode), performance test at B=256, V=128,256, P=1,024, G=512 (~264 MB of tensors)
  • challenge.html — description, SVG walk-through of the scatter → count table → apply pipeline, worked example, constraints
  • Starters for all 6 frameworks (empty solve, medium convention)

Validation

  • python scripts/validate_challenges.py → 0 errors
  • pre-commit run --all-files → all hooks pass
  • A CUDA solution was validated against the live platform on a Tesla T4: --action run ✓ and --action submit ✓ ("All tests passed"). The solution file is not committed.

🤖 Generated with Claude Code

Implements the logit penalty stage that LLM serving stacks (vLLM, SGLang,
TGI) run before sampling: per-request repetition, frequency and presence
penalties applied to a B x V logit batch given each request's prompt and
generated token histories.

The interesting part is work distribution — V is far larger than the token
histories, so solvers must build per-request occurrence counts with a
scatter instead of rescanning the histories per vocabulary entry.

Co-Authored-By: Claude Opus 5 <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