feat: safetensors runtime loading + HF-aware resolver#28
Merged
ziv-lazarov-nagish merged 2 commits intonagishfrom Apr 26, 2026
Merged
feat: safetensors runtime loading + HF-aware resolver#28ziv-lazarov-nagish merged 2 commits intonagishfrom
ziv-lazarov-nagish merged 2 commits intonagishfrom
Conversation
- `bin.py`: new `resolve_model_path()` picks MODEL_PATH > HF_MODEL_REPO > baked-in `dist/2026/`. `load_model()` prefers `model.safetensors` + `config.json` and falls back to `.ckpt` for backward compatibility. - `load_model(..., revision="")` makes HF_MODEL_REVISION part of the lru_cache key so mid-process env changes invalidate the cached instance instead of silently returning a stale model. - `pyproject.toml`: add `[build-system]`, add `safetensors` to base deps, swap `.ckpt` for `.safetensors` in package-data, drop `slim_checkpoint` script (still runnable via `python -m`). - `.gitignore`: ignore `*.safetensors` artifacts. The `huggingface_hub` import stays behind a guarded `try/except ImportError`; no new runtime dep is advertised in this PR.
This was referenced Apr 20, 2026
Contributor
|
generally good! but, this PR, if merged to |
Contributor
Author
|
AmitMY
reviewed
Apr 23, 2026
|
|
||
| [tool.setuptools.package-data] | ||
| sign_language_segmentation = ["**/*.json", "**/*.ckpt", "**/*.yaml"] | ||
| sign_language_segmentation = ["**/*.json", "**/*.safetensors", "**/*.yaml"] |
Contributor
There was a problem hiding this comment.
convert to safetensors, otherwise, ckpt file will not be installed on pip install
AmitMY
requested changes
Apr 23, 2026
package-data now selects **/*.safetensors, so the bundled best.ckpt would not have been installed on pip install. convert it in-place (bf16 state dict + hparams json) so the baked-in default keeps working. safetensors/ckpt loads produce identical outputs (max abs diff = 0).
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.
Summary
First of a 5-PR stack (layers 1–4 split PR #22 into reviewable layers; layer 5 adds
--dry-runon top). This PR adds the runtime-only foundation:bin.pycan now load models from safetensors directories and falls back to.ckptfor backward compatibility. No HF or publish features are advertised here — thehuggingface_hubimport is behind a guardedtry/except ImportError, and the[hf]/[publish]optional-dependency groups land in the later stack layers.bin.py: newresolve_model_path()with priorityMODEL_PATHenv >HF_MODEL_REPOenv > baked-insign_language_segmentation/dist/2026/.load_model()prefersmodel.safetensors+config.jsonand falls back to.ckpt.pyproject.toml: add[build-system], addsafetensorsto base deps, swap.ckpt→.safetensorsinpackage-data, dropslim_checkpointscript (still runnable viapython -m)..gitignore: ignore*.safetensorsartifacts.Review-comment fix shipped in this layer
@lru_cache+HF_MODEL_REVISIONstaleness — addedrevision: str = ""kwarg toload_model(...)so it's part of the cache key.segment_posereadsos.environ.get("HF_MODEL_REVISION", "")and forwards it. A mid-process env change now invalidates the cache entry instead of silently returning a stale model. Non-HF paths default torevision=""and behave exactly as before.Out of scope (reverted)
datasets/dgs/dataset.pyformatting churn — not in this PRdatasets/annotation_platform/sync.py --model_pathdefault change — not in this PRStack
5-PR stack — layers 1–4 split #22, layer 5 adds
--dry-run:nagishfeat/publish-utils-and-card→ this PR (PR feat: publish utils — conversion, versioning, model card #29)feat/publish-hf-ops-and-eval→ feat: publish utils — conversion, versioning, model card #29 (PR feat: publish HF ops + evaluation helpers #31)feat/publish-cli→ feat: publish HF ops + evaluation helpers #31 (PR feat: publish CLI orchestrator #30)feat/publish-dry-run→ feat: publish CLI orchestrator #30 (PR feat: --dry-run flag on publish CLI #32)Stacks up toward replacing #22. #22 stays open until explicit close.
Test plan
uv run --extra dev pytest sign_language_segmentation/tests— 61 passedMODEL_PATHpointing at a directory withmodel.safetensors+config.jsonloads successfully (verified againstsign_language_segmentation/dist/2026/)load_model(dir, device, revision="x")vsload_model(dir, device, revision="y")returns distinct instances; same revision returns the cached instance (cache key includes revision as intended)