Fix ESMC 300M/600M local loading: torch.load the .pth (repos ship no safetensors)#332
Open
sakzgupzzz wants to merge 1 commit into
Open
Fix ESMC 300M/600M local loading: torch.load the .pth (repos ship no safetensors)#332sakzgupzzz wants to merge 1 commit into
sakzgupzzz wants to merge 1 commit into
Conversation
The 300M and 600M HF repos (biohub/esmc-300m-2024-12, biohub/esmc-600m-2024-12)
ship a single legacy checkpoint at data/weights/esmc_*_2024_12_v0.pth and no
safetensors. ESMC_300M_202412 / ESMC_600M_202412 loaded them via
load_torch_model(model, dir), which defaults to safe=True and looks for a
safetensors checkpoint in the directory, so loading fails with:
ValueError: Directory '.../snapshots/...' does not contain a valid
checkpoint. Expected either a sharded checkpoint with an index file,
or a single model file.
Load the .pth explicitly with torch.load + load_state_dict(assign=True), exactly
as the ESM3 loaders in this file already do. The 6B loader is unchanged because
its repo ships sharded safetensors, for which load_torch_model works.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
ESMC.from_pretrained("esmc_300m") and ("esmc_600m") currently fail with:
Cause
ESMC_300M_202412/ESMC_600M_202412inesm/pretrained.pyload weights viaload_torch_model(model, data_root("esmc-300"|"esmc-600")).huggingface_hub.load_torch_modeldefaults to
safe=True, so given a directory it looks for a safetensors checkpoint.But the
biohub/esmc-300m-2024-12andbiohub/esmc-600m-2024-12repos ship a singlelegacy checkpoint at
data/weights/esmc_*_2024_12_v0.pthand no safetensors — so thelookup fails.
The 6B repo (
biohub/esmc-6b-2024-12) ships sharded safetensors + an index, so itsloader works; this PR leaves it unchanged.
Fix
Load the
.pthexplicitly withtorch.load+load_state_dict(assign=True), exactlyas the
ESM3_*loaders in the same file already do.Testing
Verified
esmc_600mloads and runs end-to-end on a GPU (downloads the.pth, buildsthe model with
d_model=1152, n_heads=18, n_layers=36, embeds 65 protein sequences vialogits(..., return_embeddings=True)). Theesmc_300mchange is the identical patternagainst the verified
data/weights/esmc_300m_2024_12_v0.pthfilename.