Skip to content

Force EOS at max_tokens with importance-weight correction#145

Open
ClementeP wants to merge 1 commit into
mainfrom
clemente-max-tokens-to-eos
Open

Force EOS at max_tokens with importance-weight correction#145
ClementeP wants to merge 1 commit into
mainfrom
clemente-max-tokens-to-eos

Conversation

@ClementeP
Copy link
Copy Markdown
Contributor

SequenceModel previously truncated sequences without an EOS token when hitting max_tokens, producing samples that did not target the length-conditioned distribution. At the boundary step we now swap the proposal for a point mass on EOS and apply the corresponding IS correction via a new TokenSampler.logw_eos method, so particles are properly weighted with respect to the target conditioned on |y| <= max_tokens; every returned sequence ends with EOS.

SetTokenSampler overrides logw_eos to use complete(ctx) - prefix(ctx), avoiding materializing the full logw_next vector that set samplers are designed to skip during regular sampling.

Tests updated to reflect the new boundary semantics and a focused prefix-overlap test added to cover a case the existing property test was not exercising.

SequenceModel previously truncated sequences without an EOS token when
hitting max_tokens, producing samples that did not target the
length-conditioned distribution. At the boundary step we now swap the
proposal for a point mass on EOS and apply the corresponding IS
correction via a new TokenSampler.logw_eos method, so particles are
properly weighted with respect to the target conditioned on
|y| <= max_tokens; every returned sequence ends with EOS.

SetTokenSampler overrides logw_eos to use complete(ctx) - prefix(ctx),
avoiding materializing the full logw_next vector that set samplers are
designed to skip during regular sampling.

Tests updated to reflect the new boundary semantics and a focused
prefix-overlap test added to cover a case the existing property test
was not exercising.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ClementeP ClementeP requested review from samuki and vicky-xef May 22, 2026 18:44
@codecov
Copy link
Copy Markdown

codecov Bot commented May 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

1 participant