Make ControlVector.train() deterministic (fix unseeded PCA solver)#79
Open
bamdadd wants to merge 1 commit into
Open
Make ControlVector.train() deterministic (fix unseeded PCA solver)#79bamdadd wants to merge 1 commit into
bamdadd wants to merge 1 commit into
Conversation
read_representations fits PCA(n_components=1) with the default svd_solver='auto', which selects the randomized SVD solver for hidden-state widths (>500 features). That solver is unseeded (random_state=None), so identical inputs produce different directions across runs. svd_solver='full' is exact and deterministic, and negligibly priced at n_components=1. Fixes vgel#78
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.
Fixes #78.
read_representationsfitsPCA(n_components=1)with the defaultsvd_solver="auto". For transformer hidden-state widths (n_features > 500) sklearn'sautoheuristic selects the randomized SVD solver, which is unseeded (random_state=None), soControlVector.train()returns a different vector each run for identical inputs. On weak-signal concepts the direction diverges materially (cosine 0.5–0.9 between runs on the same data); on well-separated concepts the direction is stable but still not bit-identical.svd_solver="full"is exact and deterministic, and is negligibly priced forn_components=1. One line, no API change.Repro (numpy + scikit-learn only, no model/GPU) and full analysis are in the issue. If you'd prefer to keep the randomized solver's speed for very large datasets, I'm happy to instead thread an optional
random_statethroughtrain→read_representations→PCA(...)— just say which you prefer.