Skip to content

Add offline model support: --ssl-repo-path and --download-models#176

Merged
chanshing merged 2 commits intomainfrom
feat/offline-model-support
Feb 28, 2026
Merged

Add offline model support: --ssl-repo-path and --download-models#176
chanshing merged 2 commits intomainfrom
feat/offline-model-support

Conversation

@chanshing
Copy link
Copy Markdown
Member

Users in offline or restricted environments have no way to pre-download all model artifacts. The .joblib.lzma files are fetched lazily on first run, and the ssl-wearables torch hub repo is cloned when the SSL model loads. This PR adds --ssl-repo-path to use a local repo copy and --download-models to pre-cache everything ahead of time.

Files Changed

src/stepcount/sslmodel.py

  • Add repo_path parameter to get_sslnet(). When provided, loads via torch.hub.load() with source='local', skipping GitHub download and cache lookup
  • Document that tag is ignored when repo_path is provided

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 models serialized before this change

src/stepcount/stepcount.py

  • Add --ssl-repo-path CLI argument for specifying a local ssl-wearables repo (SSL only)
  • Wire it to model.wd.ssl_repo_path after model loading
  • Make filepath positional arg optional (nargs='?') so --download-models works without an input file
  • Add --download-models CLI flag and early-exit logic in main()
  • Add download_models() function: downloads both ssl and rf .joblib.lzma files with atomic temp-file writes, MD5 verification, 60s timeout; caches ssl-wearables repo; validates --ssl-repo-path if provided

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
  • Test --download-models appears in CLI help output
  • Test --download-models works without a filepath arg (mocked)
  • Test omitting filepath without --download-models gives an error

**`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
@chanshing chanshing force-pushed the feat/offline-model-support branch from 7bae790 to 7d78631 Compare February 28, 2026 20:46
@chanshing chanshing marked this pull request as ready for review February 28, 2026 20:54
@chanshing chanshing merged commit 7d013df into main Feb 28, 2026
9 checks passed
@chanshing chanshing deleted the feat/offline-model-support branch February 28, 2026 20:54
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.

1 participant