Bug/issue 5 rotary emb mismatch#6
Merged
Merged
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.
Fix: load DISCO checkpoint against newer/downgraded transformers ESM
Fixes #5.
Summary
The bundled DISCO checkpoint (
DISCO-Design/DISCOon HF Hub) was saved against an oldtransformersrelease whoseEsmEmbeddingsonly createdposition_embeddingson the absolute-position branch and stored a per-layer rotaryinv_freqbuffer on every attention layer. Both of those have since changed in the upstream ESM rewrite, soInferenceRunner.load_checkpointthrows aRuntimeErrorfromload_state_dict(strict=True). The first is on extra per-layer rotaryinv_freqkeys, while the second is on a missing sharedrotary_embeddings.inv_freq/ missingposition_embeddings.weight.This PR adds two small, narrowly-scoped state-dict remaps that run before
load_state_dict, so the existing checkpoint loads cleanly on current ESM/DPLM module layouts without weakeningstrict=True.Changes
All changes are in
runner/inference.py:_remap_esm_rotary_inv_freq— when the current model exposes a single shared…rotary_embeddings.inv_freqbuffer but the checkpoint carries the old per-layer copies, verify all per-layer tensors are identical (they always are by construction) and promote the first one to the shared key, dropping the per-layer entries. No-op on older transformers where the per-layer layout still exists._fill_unused_esm_position_embeddings— when the currentEsmEmbeddingsinstantiates an unusedposition_embeddings.weight(e.g., on transformers 4.50.0) and the checkpoint does not carry that key, fill it from the freshly-initialized current model state. Safe becauseposition_embedding_type="rotary"means the weight is never read during the forward pass. No-op on checkpoints that legitimately carry an absolute-position embedding.load_checkpointimmediately after the existingmodule.-prefix stripping and before the shape-mismatch filter, so the rest of the loading path is unchanged.Test plan
python runner/inference.py experiment=designable input_json_path=input_jsons/unconditional_config.json seeds=[0,1]end-to-end against the HF-hostedDISCO-Design/DISCOcheckpoint and confirm it loads and produces outputs.