Add offline model support: --ssl-repo-path and --download-models#176
Merged
Add offline model support: --ssl-repo-path and --download-models#176
Conversation
**`src/stepcount/sslmodel.py`** - Add `repo_path` parameter to `get_sslnet()`. When provided, loads the model via `torch.hub.load()` with `source='local'`, skipping GitHub download and cache lookup. **`src/stepcount/models.py`** - Add `ssl_repo_path` parameter to `WalkDetectorSSL.__init__()` - Pass it through to `get_sslnet()` in `fit()` and `load_model()` - Use `getattr` for backward compat with pre-serialized models **`src/stepcount/stepcount.py`** - Add `--ssl-repo-path` CLI argument for specifying a local copy of the ssl-wearables repo (SSL only) - Wire it to `model.wd.ssl_repo_path` after model loading **`tests/test_sslmodel.py`** - Test `repo_path` uses `source='local'` and skips cache logic - Test `repo_path=None` falls back to existing GitHub/cache logic **`tests/test_models.py`** - Test `WalkDetectorSSL` stores and defaults `ssl_repo_path` **`tests/test_stepcount.py`** - Test `--ssl-repo-path` appears in CLI help output
…e use - Make filepath positional arg optional (nargs='?') so --download-models works without an input file - Add download_models() function that downloads both ssl and rf .joblib.lzma files with atomic temp-file writes, MD5 verification, and 60s timeout - Validate --ssl-repo-path exists when used with --download-models - Add docstring note that tag is ignored when repo_path is provided - Add CLI tests for --download-models flag
7bae790 to
7d78631
Compare
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.
Users in offline or restricted environments have no way to pre-download all model artifacts. The
.joblib.lzmafiles are fetched lazily on first run, and thessl-wearablestorch hub repo is cloned when the SSL model loads. This PR adds--ssl-repo-pathto use a local repo copy and--download-modelsto pre-cache everything ahead of time.Files Changed
src/stepcount/sslmodel.pyrepo_pathparameter toget_sslnet(). When provided, loads viatorch.hub.load()withsource='local', skipping GitHub download and cache lookuptagis ignored whenrepo_pathis providedsrc/stepcount/models.pyssl_repo_pathparameter toWalkDetectorSSL.__init__()get_sslnet()infit()andload_model()getattrfor backward compat with models serialized before this changesrc/stepcount/stepcount.py--ssl-repo-pathCLI argument for specifying a local ssl-wearables repo (SSL only)model.wd.ssl_repo_pathafter model loadingfilepathpositional arg optional (nargs='?') so--download-modelsworks without an input file--download-modelsCLI flag and early-exit logic inmain()download_models()function: downloads both ssl and rf.joblib.lzmafiles with atomic temp-file writes, MD5 verification, 60s timeout; caches ssl-wearables repo; validates--ssl-repo-pathif providedtests/test_sslmodel.pyrepo_pathusessource='local'and skips cache logicrepo_path=Nonefalls back to existing GitHub/cache logictests/test_models.pyWalkDetectorSSLstores and defaultsssl_repo_pathtests/test_stepcount.py--ssl-repo-pathappears in CLI help output--download-modelsappears in CLI help output--download-modelsworks without a filepath arg (mocked)--download-modelsgives an error