Skip to content

Publish the int8 ONNX model on Hugging Face Hub and load it from there - #15

Merged
pavan-dangeti merged 7 commits into
mainfrom
feat/hub-model
Oct 9, 2026
Merged

pavan-dangeti merged 7 commits into
mainfrom
feat/hub-model

Conversation

@pavan-dangeti

@pavan-dangeti pavan-dangeti commented Oct 9, 2026 •

Copy link
Copy Markdown
Owner

Publishes the int8 ONNX XLM-R model and lets the app load it from Hugging Face Hub.

Model: pavan-dangeti/scamshield-xlmr-int8 at revision 34160516e72121848b4622fdb727b7f33c00101b, CC BY-NC 4.0 with the Built with Qwen notice.

What this adds

  • src/model_hub.py + configs/model_hub.json: fetch the model at the pinned revision, verifying every file's SHA-256. Interrupted downloads resume with an HTTP range request (up to 4 attempts); a corrupt or truncated file is rejected and nothing partial is left on disk.
  • The registry fetches the model on first start when SCAMSHIELD_MODEL=xlmr-aug-int8 and the files are absent, only if onnxruntime is installed, and falls back to the baseline on any failure. The live demo (baseline) is unaffected.
  • scripts/download_model.py and scripts/publish_model.py (token from HF_TOKEN only; refuses files that differ from the manifest; --new-artefact for retrained models).
  • docs/hub_model_card.md: the Hub model card (training data and licences, validation-only evaluation, limitations, Built with Qwen).
  • requirements-onnx.txt: onnxruntime was in no requirements file, so a fresh install could not run the model.
  • The Colab notebook now reproduces the published (augmented, int8) model; it previously trained only the plain encoder.

How it was checked

  • Clean folder: a fresh clone with no models/ directory and a new Python 3.11 env with only requirements-onnx.txt. Started with SCAMSHIELD_MODEL=xlmr-aug-int8, the server downloaded all four files from the Hub, /api/health reported xlmr-aug-int8, and /api/analyze served it. The files pass the Hub's SHA256SUMS (shasum -c).
  • The first clean-folder attempt dropped after 34 MB of 278 MB (IncompleteRead); that is why downloads now resume. Tested with a simulated mid-transfer drop and with repeated failures.
  • Pinned requirements-onnx.txt gives identical decisions, tactics and probabilities on 500 validation messages vs. the existing environment; the model card's code example runs as written.
  • pytest 102 passed, including with all network access blocked (no test downloads anything) · ruff · vulture · mypy clean.

onnxruntime was in no requirements file, so a fresh install could not run the
int8 model. requirements-onnx.txt pins onnxruntime and transformers (no torch);
verified on Python 3.11 with identical predictions on 500 validation messages.
requirements-ml.txt gains onnx and onnxruntime for export and quantisation.
…ecksum-verified

configs/model_hub.json pins the repository, the revision and a SHA-256 for every
file. scripts/download_model.py fetches them; the registry does the same on first
start when the model is requested but absent, only if onnxruntime is installed,
and falls back to the baseline on any failure. A corrupt or truncated download is
rejected and never left in place.
Uploads exactly the four files the app needs, the model card and SHA256SUMS,
refuses files that do not match the manifest, reads HF_TOKEN from the
environment only, and records the published revision in the manifest. The card
covers training data and licences, validation-only evaluation, limitations and
the Built with Qwen notice required by the Qwen Research License.
…otice

The Colab notebook trained only the un-augmented encoder; it now also builds the
augmented set, trains, exports and quantises the published model, and downloads
the four files.
pavan-dangeti/scamshield-xlmr-int8 at 34160516e72121848b4622fdb727b7f33c00101b.
The first clean-folder download from the Hub dropped after 34 MB of 278 MB
(IncompleteRead). Downloads now go to a .part file and resume with an HTTP range
request, up to four attempts; the checksum still covers the whole file and
nothing is left behind on failure.
pavan-dangeti/scamshield-xlmr-int8, CC BY-NC 4.0. Verified from a clean clone: the
server fetched all four files at the pinned revision on first start, they pass
the Hub's SHA256SUMS, and it served the int8 model.
@pavan-dangeti
pavan-dangeti marked this pull request as ready for review October 9, 2026 10:10
@pavan-dangeti
pavan-dangeti merged commit c0f173c into main Oct 9, 2026
3 checks passed
@pavan-dangeti
pavan-dangeti deleted the feat/hub-model branch October 9, 2026 10:13
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