FIX AdaMSS save/load reproduction by making slice_pca SVD deterministic#3310
Open
AshNicolus wants to merge 1 commit into
Open
FIX AdaMSS save/load reproduction by making slice_pca SVD deterministic#3310AshNicolus wants to merge 1 commit into
AshNicolus wants to merge 1 commit into
Conversation
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.
What does this PR do?
Saving an AdaMSS adapter with
save_pretrainedand reloading it withfrom_pretraineddoes not reproduce the model's outputs once the adapter hasbeen trained.
Root cause
When an AdaMSS adapter is loaded, the layer is rebuilt from the base weights
(
update_layer→slice_pca→clustering_Z). This recomputesscatter_index,the mapping that places each subspace's contribution into the correct output
dimensions.
slice_pcausestorch.svd_lowrank, which draws a random projectionfrom the global RNG, so the SVD result — and therefore the clustering and
scatter_index— depends on the RNG state at construction time. Because thatstate differs between saving and loading, the reloaded adapter rebuilds a
different
scatter_index. The trainedadamss_A/adamss_Bweights are restoredcorrectly, but are then scattered to the wrong output dimensions, so the output
changes.
This stayed hidden because AdaMSS initializes
B = 0: an untrained adapter is ano-op and reloads trivially regardless of
scatter_index. The discrepancy onlyappears once the adapter is trained.
clustering_Zalready pinsKMeans(random_state=...), so deterministicinitialization is clearly intended; the only remaining source of randomness was
svd_lowrank.Fix
Seed a forked RNG around the
svd_lowrankcalls inslice_pcaso thedecomposition is deterministic and the reconstructed
scatter_indexmatches theone used at save time.
torch.random.fork_rngleaves the global RNG streamuntouched.
Tests
Added
TestAdamssSaveLoad::test_save_load_reproduces_outputintests/test_adamss_asa.py: it trains an AdaMSS adapter, saves it, perturbs theglobal RNG state, reloads into a fresh base model, and asserts the outputs match.
The test fails on
mainand passes with this change; the existing AdaMSS testsstill pass.