feat: sampling mask pass-through - #2460
Merged
Merged
Conversation
vLLM 0.28 returns kept-set sampling masks natively (sampling_mask, one list of surviving vocab ids per completion token) instead of the custom base64 kept_tokens payload. Convert to the flat int32 ids/counts arrays on the train client; graph attribution validates alignment and attaches the arrays as-is.
mikasenghaas
added a commit
to PrimeIntellect-ai/prime-rl
that referenced
this pull request
Aug 29, 2026
Truncated train sampling (top_p < 1, top_k) renormalizes the rollout distribution over the surviving kept set; rollout logprobs reflect that (processed_logprobs) while the trainer normalizes over the full vocab, biasing every importance ratio. Record the kept set at sampling time and renormalize trainer logprobs over the same set (DeepSeek V3.2's Keep Sampling Mask, arXiv:2512.02556 3.1). Same user API as #3235: [orchestrator.train.sampling] top_p/top_k, no replay flags. Truncating policy sampling auto-enables inference.enable_return_sampling_mask, bounds top_k to 512 (trainer mask tensors pad to the largest kept set), and rejects opd/opsd and temperature 0. Unlike #3235 the capture is vLLM's native --return-sampling-mask (>= 0.28, V2 model runner) instead of custom engine patches: the /generate response carries sampling_mask natively, renderers parse it (PrimeIntellect-ai/renderers#144) and verifiers carry it as KeptTokens arrays (PrimeIntellect-ai/verifiers#2460). Capture is engine-wide: vLLM rejects requests with temperature <= 0 or top_k <= 0 while it is on, and it is incompatible with router replay (V1-only).
mikasenghaas
marked this pull request as ready for review
September 1, 2026 21:39
hallerite
reviewed
Sep 1, 2026
hallerite
reviewed
Sep 1, 2026
hallerite
reviewed
Sep 1, 2026
hallerite
reviewed
Sep 1, 2026
Contributor
ApprovabilityVerdict: Not approved Macroscope's review found this PR not approvable — This is a cross-project training-trace integration that adopts a new renderer payload and replaces the public and wire contract from KeptTokens/kept_tokens to SamplingMask/sampling_mask. Although ordinary generation is largely unchanged without a mask, the breaking API/schema migration and prerelease dependency require human review. You can add or adjust custom eligibility rules. Learn more. |
hallerite
approved these changes
Sep 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SamplingMaskfrom asampling_maskpayload.renderers==0.1.12.dev2feature floor.idsand per-tokencountsarrays.sampling_maskacross response tokens, message nodes, branch views, wire serialization, and public exports.Branch.sampling_maskaligned to the branch token ids for prime-rl.Pairs with PrimeIntellect-ai/renderers#144 and prime-rl's native sampling-replay PR.
Breaking
vf.KeptTokenstovf.SamplingMask.TurnTokens.kept_tokens,MessageNode.kept_tokens, andBranch.kept_tokenstosampling_mask.sampling_maskfield.Verification
mainwithout conflicts.uv sync --upgrade-package renderers: lockfile regenerated withrenderers==0.1.12.dev2.uv run pytest tests/v1/test_graph.py tests/v1/test_trace.py -q: 21 passed.🤖 Generated with Claude Code
Note
Replace
KeptTokenswithSamplingMaskacross v1 verifier pipelineSamplingMaskdataclass in types.py withidsandcountsfields plusfrom_sampling_mask, and swapskept_tokensforsampling_maskonTurnTokensandMessageNodesampling_maskfrom the generate result and builds it viaSamplingMask.from_sampling_mask;response_from_generatepopulatesTurnTokens.sampling_mask_attribute_kept_tokensto_attribute_sampling_mask, which validatescounts/idslengths and assigns theSamplingMaskdirectly (no base64 decode or buffer copy)sampling_maskfrom disk serialization and exposesBranch.sampling_mask, which scatters per-nodecountsonto sampled positions and concatenatesidsrenderers[multimodal]dependency from>=0.1.11to>=0.1.12.dev2in pyproject.tomlKeptTokensis removed from theverifiers.v1public API (__all__) andSamplingMaskreplaces it; any downstream code importingKeptTokensor readingkept_tokensonTurnTokens,MessageNode, orBranchmust switch tosampling_mask._attribute_sampling_maskno longer base64-decodes or copies buffers — callers must provide a validSamplingMaskpayload directlyChanges since #2460 opened
Macroscope summarized 67af753.
Note
Medium Risk
Breaking rename across the v1 training/trace wire contract; incorrect mask alignment would silently drop masks at attribution, and consumers must upgrade renderers in lockstep.
Overview
Replaces the
KeptTokens/kept_tokenssurface withSamplingMask/sampling_maskso training traces align with the newrenderersgenerate payload (sampling_maskas nested token-id rows). Public exports,TurnTokens,MessageNode, wire serialization, andBranch.sampling_maskall use the new names; disk dumps still exclude the tensor field viaEXCLUDE_FIELDS.SamplingMaskholds flat int32idsand per-completion-tokencounts, withfrom_sampling_maskto build from the engine’slist[list[int]]. The train client mapsresult["sampling_mask"]intoTurnTokens; graph attribution validates row counts against sampled positions and stores the mask on the assistant node (no base64 decode/copy path like the old kept-set flow).Dependency:
renderers[multimodal]is pinned to>=0.1.12.dev2(lockfile updated). Downstream code that importedKeptTokensor readkept_tokenson traces must switch tosampling_mask.Reviewed by Cursor Bugbot for commit 3ff2553. Bugbot is set up for automated code reviews on this repo. Configure here.