Repository navigation
Fix .safetensors detection for local ResNet50 checkpoints (str weights_path) - #238
Merged
guillaumejaume merged 1 commit intoSep 15, 2026
Conversation
_get_weights_path() returns a str, so weights_path.suffix raised
AttributeError inside the bare except and surfaced the misleading
"download pytorch_model.bin" error for valid .safetensors files.
Use str(weights_path).endswith(".safetensors") and add a fast-tier
regression test that loads .safetensors and .bin state dicts from a
string path.
Fixes mahmoodlab#172
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 #172.
Problem.
ResNet50InferenceEncoder._buildchecksweights_path.suffix == ".safetensors", but_get_weights_path()returns astr(fromlocal_ckpts.jsonor theweights_pathkwarg), so any local ResNet50 checkpoint raisesAttributeError: 'str' object has no attribute 'suffix'inside the bareexcept. The user then sees the misleading "Failed to create ResNet50 model from local checkpoint … downloadpytorch_model.bin" error even though the checkpoint is valid. Reported and diagnosed by @haydenych and @PingjunChen in #172.Fix. One line:
str(weights_path).endswith(".safetensors"). Works forstrandpathlib.Pathinputs and leaves thetorch.loadbranch unchanged. Also removes a stray leading space in the adjacent error message (` model.safetensors`).Test.
tests/test_resnet50_local_checkpoint.py(fast tier: CPU only, no network, ~2 s). It builds an untrained timm resnet50 with the same kwargs as_build, stampsconv1.weightwith a probe value, saves the state dict asmodel.safetensorsand aspytorch_model.bin, loads each throughencoder_factory("resnet50", weights_path=<str>), and asserts the probe tensor is present in the encoder, so the test proves the file was actually loaded rather than silently skipped bystrict=False.Without the fix both cases error with the
AttributeErrorabove; with the fix both pass.Verification. Windows 11, Python 3.12, torch 2.14 (CPU), timm 1.0.29, safetensors 0.8.0:
The single failure (
test_wsi_states_v2.TestWSIStatesV2.test_output_stats_added_for_paths) reproduces identically on a cleanmaincheckout on Windows and is unrelated to this change.Out of scope on purpose (happy to follow up separately): the bare
except:clauses inload.py, and the other encoders that calltorch.loaddirectly.