Repository navigation
fix: make the first-use weight download resolve every id and fail loudly - #75
Merged
Merged
Conversation
Three defects in the automatic download: * The `*_semantic` ids are registered as available models -- they even show up in the "Available semantic models: [...]" error message -- but had no `download_names` entry, so `--model-semantic t2w_semantic` on a machine without the weights died with `KeyError: 't2w_semantic'`. `ct_semantic` additionally missed the CT version override and resolved to the v1.0.9 folder name while downloading the v2.0.0 archive. A single `canonical_model_key()` now maps the alias onto the id the weights are registered under. * `download_weights` caught every exception, logged "Download attempt failed" and returned normally, so `download_if_missing` handed back a path that does not exist and the real failure surfaced later as a config-not-found from the model loader. It now raises a RuntimeError naming the URL, the cause, and the manual-download fallback. * The archive was extracted straight into the final model folder, whose existence is the only "is this model installed?" check there is. An extraction interrupted halfway (Ctrl-C, full disk) left a partial folder that was never retried and never worked, and a truncated download left a stray .zip plus a raw BadZipFile. Download and extraction now happen in a unique staging folder that is moved into place only after the contents are verified to hold an inference_config.json, and is removed on any failure. The unique staging name also stops concurrent SPINEPS processes (e.g. a job array) from overwriting each other's partial download. Co-Authored-By: Claude Opus 5 <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.
Model weights download automatically on first use, so this code path is the very first thing a new user
hits. It had three defects.
1. Four advertised model ids crashed
auto_downloadregisters each semantic model twice,t2wandt2w_semantic, butdownload_namesonlyhas the canonical key:
These ids are listed to the user in the "Model 'x' does not exist. Available semantic models: [...]"
error message, so the obvious next step -- copy one of the listed names -- died with
RuntimeError: Failed to download model 't2w_semantic' ...: KeyError: 't2w_semantic'.ct_semantichad a second problem:phase_to_versionis keyedSEMANTIC_ct, so the alias missed the CToverride and resolved to a
CT_semantic_v1.0.9folder while downloading the v2.0.0 archive.One
canonical_model_key()maps*_semanticonto the id the weights are registered under, anddownload_if_missingraises a readableKeyErrorfor a genuinely unknown id instead of a bare lookupfailure.
2. A failed download reported success
The caller then handed that non-existent folder to the model loader, and the user got a config-not-found
error with no mention of the network. It now raises a
RuntimeErrornaming the URL, the underlying causeand the manual-download fallback from the README.
3. An interrupted download poisoned the cache permanently
out_pathexisting is the "model is installed" check, and the archive was extracted straight into it:A truncated download left a stray
T2w_semantic_v1.0.9.zipin the models directory and a rawBadZipFile. Download and extraction now happen in a unique staging folder, which is moved into placeonly after its contents are verified to contain an
inference_config.json, and is removed on anyfailure. The unique staging name also means concurrent SPINEPS processes (a job array all starting at
once) no longer overwrite each other's partial download.
Tests
unit_tests/test_auto_download.py: every registry id resolves to a download name; alias and canonical idgive the same folder at the right release version; unknown id raises a readable error; unreachable URL,
truncated archive and config-less archive each raise and leave the models directory empty; flat and
nested archives both install correctly; an existing folder is never re-downloaded.
Full suite: 233 passed, ruff clean.
🤖 Generated with Claude Code