Skip to content

fix: don't re-download encoder weights when loading a pretrained model#1360

Open
cycsmail wants to merge 1 commit into
qubvel-org:mainfrom
cycsmail:fix/957-skip-encoder-download-on-load
Open

fix: don't re-download encoder weights when loading a pretrained model#1360
cycsmail wants to merge 1 commit into
qubvel-org:mainfrom
cycsmail:fix/957-skip-encoder-download-on-load

Conversation

@cycsmail

Copy link
Copy Markdown

Fixes #957.

When you reload a model with from_pretrained, the encoder weights are already stored in the checkpoint, but the saved config still has encoder_weights set (e.g. "imagenet"), so smp went and re-downloaded the encoder's pretrained weights anyway. That makes loading fail offline / from a purely local path.

This skips the download when the config records encoder_weights, falling back to None so the checkpoint weights are used as-is. An explicit encoder_weights=... passed to from_pretrained still takes precedence via setdefault.

Added a test that asserts no encoder download happens on reload and that the restored weights match the saved model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Is there any way of loading the encoder from local path instead of downloading it?

1 participant