Repository navigation
[Feat] sampling: Count penalty history right after sampling in a per-request pool - #52035
Conversation
… sampling Penalty history (per-token output counts and the output length) moves from per-batch penalizer tables, which the scheduler filled from host output_ids in prepare_for_decode and filtered and merged on the schedule stream, into one PenaltyStore per scheduler: an int32 count table plus lengths, one row per request that uses a penalty, found through a request-slot -> row table. - The scheduler only admits and frees rows and builds each step's params (StepPenalties); every device write (reset and replay at admission, growth, counting) runs on the sampling stream, so no cross-stream fence is needed. - A row is reset and replayed from output_ids at every extend admission (chunks, retraction, PD decode) and freed at request exit in RequestRetirer; the tables are dropped when no row is live. - Tokens are counted right after sampling: ModelRunner.sample, the EAGLE-family and NGRAM verify, and the DFlash and DSpark block verify. - DLLM, Unlimited-OCR document reuse, and DFlash with a bound runtime reject sampling penalties at request entry; UNO still rejects them. - The host bookkeeping (Req.penalty_cumulated_len, cumulate_penalty_output_tokens) and the penalizer orchestrator are removed. Behavior: under overlap, the token sampled in the previous step now counts (non-spec, and spec block-start penalties); frequency penalty is f * count; additive penalties apply before repetition scaling.
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.
Tip: disable this comment in your organization's Code Review settings.
|
/rerun-test registered/sampling/test_penalty.py registered/openai_server/basic/test_openai_server.py registered/spec/eagle/test_spec_eagle.py registered/spec/eagle/test_spec_eagle_topk.py registered/spec/dflash/test_dflash.py registered/spec/test_spec_ngram.py registered/scheduler/test_retract_decode.py registered/dllm/test_dllm_batching_fdfo.py |
|
🚀 🚀 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
… rename penalty_row to penalty_index
This comment has been minimized.
This comment has been minimized.
…ex; fix the freed-index error text
|
🚀 🚀 |
…eps only step_penalties
|
🚀 🚀 |
Resolve conflicts with the per-request penalty pool (sgl-project#52035), DFLASH request penalties (sgl-project#47020) and the megakernel runtime binding (sgl-project#51676): the shared logit-adjustment check reads step_penalties, so penalized batches keep the dense verify and get upstream's penalties; the sparse accept syncs its decision across TP ranks like the dense selector accept. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Motivation
Sampling penalties need each request's output history. On main that history lives in per-batch penalizer tables: the scheduler fills them from the host
output_idsinprepare_for_decode, which lags one step under overlap, and filters and merges them on the schedule stream while a forward may still read them. Exact speculative penalties (the next PR) need the history current at verify and owned by the device.This PR counts each committed token right after sampling, on the sampling stream, into a per-request pool; the scheduler only hands out and frees penalty indices and builds each step's params.
Modifications
sampling/penalties.py:PenaltyStatusPool, one per scheduler. It holds an int32 per-token count table plus output lengths, with one row per request that uses a penalty; the request holds its row's penalty index (Req.penalty_index), and a step carries the penalty indices it was built with.StepPenaltiesholds a step's params and builds the[bs, vocab]additive and scaling tables from the pool. The penalizer orchestrator and its four penalizers are removed.Rows:
alloc), and the row is reset and replayed fromoutput_idsat every extend admission (reset_history) (prefill, every chunk, retraction readmission, PD decode prebuilt). This also wipes a discarded chunk sample.RequestRetirer; a retraction keeps its row.Streams: host calls only queue device writes. Growth, reset, replay, and counting run on the sampling stream, so the scheduler never writes penalty state and no cross-stream fence is needed.
Counting: tokens are counted right after sampling, in
ModelRunner.sample(which also covers delayed sampling and watermark sampling), the EAGLE-family and NGRAM verify, and the DFlash and DSpark block verify. Ids outside the vocab, from NaN logits or masked draft slots, count nothing.Tables:
SamplingBatchInfo.step_penaltiesreplacespenalizer_orchestrator.StepPenaltiesbuilds and caches the step's tables (built atcopy_for_forwardon the forward stream);acc_additive_penaltiesandacc_scaling_penaltiesare read-only views of them.New request-entry rejections for sampling penalties:
UNO still rejects them.
Removed: the host bookkeeping
Req.penalty_cumulated_lenandScheduleBatch.cumulate_penalty_output_tokens.Behavior changes
min_new_tokens(which no longer blocks EOS one extra step), and the block-start penalties of speculative verify. Verify rows still share the block-start penalties; per-row exactness is the next PR.f * count, not a running sum off, so results can differ in the last float bits.sglang.srt.sampling.penaltiesno longer exports the orchestrator classes.Accuracy Tests
test_penalty_status_pool.py,spec/test_verify_penalty_commit.py,test_request_retirer.py, andtest_sampling_batch_info.pypass. Every other failure in the sampling, managers, spec, speculative, disaggregation, and session unit directories also fails on main.Checklist
CI States
Latest PR Test (Base): 🚫 Run #44882128219
Latest PR Test (Extra): ⊘ Skipped -- add the
run-ci-nv-extralabel to opt in.Latest PR Test (AMD ROCm 10): 🚫 Run #44882128222
Tip
Base CI only covers the core cases, and its workload may not exercise your change. Use
/rerun-testto run the tests your change touches, or copy this prompt for an agent: