fix: _validate_seqpos rejects valid step_size of 1 in seqpos_slice#681
Open
robbiebusinessacc wants to merge 1 commit into
Open
Conversation
The step-size check used `if step_size <= 1`, which rejected the valid step of 1 even though the comment and error message both state the step must be at least 1. This made any 3-tuple seqpos_slice with an explicit or defaulted step of 1 (e.g. (0, 5, 1), (1, None, 1), (None, None, 1)) crash at config construction with a self-contradictory error. Change the check to `< 1` so step 1 is accepted while 0 and negative steps still raise. Add tests covering valid 3-tuple slices that were previously untested.
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.
_validate_seqposinsae_lens/config.pyvalidates the step component of a3-tuple
seqpos_slice. The intent (per the comment "Ensure that the step-sizeis larger or equal to 1" and the error message "is at least 1") is to reject
steps below 1. But the guard was written as
step_size <= 1, which alsorejects a step of exactly
1— the most common case.Because the step defaults to
1when omitted (step_size = seqpos[2] or 1),this made every natural 3-tuple usage crash at config-construction time:
seqpos_slice=(0, 5, 1)— explicit step of 1seqpos_slice=(None, 5, None)— step omitted, defaults to 1seqpos_slice=(1, None, 1)— e.g. drop the BOS position, keep the restAll raised
ValueError: Ensure the step_size=1 for sequence slicing is at least 1.— a self-contradictory message, since 1 is at least 1.Fix
Relax the guard so that a step of
1is accepted — an omitted orNonestepdefaults to 1 as well — while
0and negative values are still rejected asbefore. It is a one-character change in
sae_lens/config.py, replacing thecomparison
step_size <= 1withstep_size < 1.Testing
The existing parametrized tests only covered error cases (steps of 0, -1, and
empty/reversed ranges); the valid
step == 1path was untested. This PR addsparametrized tests for both
LanguageModelSAERunnerConfigandCacheActivationsRunnerConfigasserting that valid slices such as(0, 5, 1),(None, 5, None),(None, None, 1), and(1, None, 1)are accepted andround-trip correctly.
Reverting only the one-character fix makes 8 of the new tests fail; restoring
it makes all pass.
ruff check,ruff format --check, andpyrightare allclean.