Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,61 @@ permissions:
contents: read

jobs:
publish-model:
# Publishes the model.zip packaged by train's pipeline at this commit as
# api/MODEL_VERSION, unless that version is already on HuggingFace.
# `release publish` creates the HF tag last, so the tag is the "done"
# marker: a code-only release skips, a failed publish retries cleanly.
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Check whether the model version is already published
id: check
run: |
MODEL_VERSION=$(cat api/MODEL_VERSION)
if [ -z "$MODEL_VERSION" ]; then
echo "api/MODEL_VERSION is missing or empty" >&2
exit 1
fi
echo "MODEL_VERSION=$MODEL_VERSION" >> "$GITHUB_ENV"
status=$(curl -s -o /dev/null -w '%{http_code}' \
"https://huggingface.co/api/models/pyronear/temporal-model/revision/v$MODEL_VERSION")
case "$status" in
200) echo "v$MODEL_VERSION is already on HuggingFace, nothing to publish"
echo "publish=false" >> "$GITHUB_OUTPUT" ;;
404) echo "publish=true" >> "$GITHUB_OUTPUT" ;;
*) echo "Unexpected HTTP $status from HuggingFace" >&2; exit 1 ;;
esac
- name: Configure AWS credentials
if: steps.check.outputs.publish == 'true'
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-3
- name: Install uv
if: steps.check.outputs.publish == 'true'
uses: astral-sh/setup-uv@v8.1.0
with:
python-version: "3.11"
- name: Pull the packaged model.zip from DVC
if: steps.check.outputs.publish == 'true'
working-directory: train
run: uvx --from 'dvc[s3]' dvc pull data/06_models/vit_dinov2_finetune/model.zip
- name: Export ONNX and publish to HuggingFace
if: steps.check.outputs.publish == 'true'
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }} # needs write access to the model repo
run: |
MODEL=$PWD/train/data/06_models/vit_dinov2_finetune/model.zip
ONNX=$RUNNER_TEMP/model_onnx.zip
# core's dev env has the torch + onnx extras the export needs; api's does not.
uv run --project core temporal-export-onnx --model "$MODEL" --output "$ONNX"
uv run --project api --no-dev python -m temporal_model.api.release \
publish --version "$MODEL_VERSION" --file "$MODEL" --onnx-file "$ONNX"

docker:
needs: publish-model
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
Expand Down
34 changes: 16 additions & 18 deletions docs/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,17 @@ A release can move the code version while leaving the model version untouched.

## Cutting a release

### 1. (Only if the model changed) publish the new model
### 1. (Only if the model changed) bump the model version

Bump the pin, export the torch-free runtime artifact from the same `model.zip`
(the export checks torch/ONNX parity and records the source SHA-256 in its
manifest), then publish **both in one `publish` call** — the `vX.Y.Z` tag is
immutable, so a second `publish` for the same version fails and cannot add the
ONNX archive after the fact (needs a **write** HF token):
Merge a PR that sets the new version in `api/MODEL_VERSION`:

```bash
# from the repo root; MODEL=/abs/path/to/model.zip, ONNX=/abs/path/to/model_onnx.zip
echo "X.Y.Z" > api/MODEL_VERSION # the new model version
uv run --project core temporal-export-onnx --model "$MODEL" --output "$ONNX"
uv run --project api python -m temporal_model.api.release \
publish --version X.Y.Z --file "$MODEL" --onnx-file "$ONNX"
```

`publish` stamps the version into both manifests, uploads the zips + model
card, and tags `vX.Y.Z` on the HF repo (immutable — re-publishing an existing
version fails). It refuses an `--onnx-file` whose manifest was not exported
from that exact `model.zip`, then re-stamps its source hash from the uploaded
(version-stamped) copy. Commit the `api/MODEL_VERSION` change. Consumers fetch
the ONNX artifact with `release fetch --onnx` (or `make fetch-model-onnx`).
The model that gets published is the `model.zip` that `train`'s `package`
stage produced at the tagged commit (its `dvc.lock` entry), so merge the
`result_*` PR first. Publishing happens in CI at step 2.

### 2. Push the git tag

Expand All @@ -46,8 +35,14 @@ git push origin vX.Y.Z

That triggers `.github/workflows/push.yml`, which:

1. fetches the `model.zip` pinned by `api/MODEL_VERSION` from HuggingFace,
2. builds and pushes `pyronear/temporal-model-api:X.Y.Z` and `:latest`,
1. publishes the model if `v<MODEL_VERSION>` is not yet on HuggingFace: pulls
`train`'s `model.zip` from DVC, exports the torch-free `model_onnx.zip` (the
export checks torch/ONNX parity and records the source SHA-256), then runs
`release publish`, which stamps the version into both manifests, uploads the
zips + model card, and tags `v<MODEL_VERSION>` on the HF repo last. A code-only release
skips this step,
2. fetches the `model.zip` pinned by `api/MODEL_VERSION` from HuggingFace and
builds and pushes `pyronear/temporal-model-api:X.Y.Z` and `:latest`,
3. **auto-creates the GitHub Release** for `vX.Y.Z` — a header naming the image
and bundled model, followed by GitHub's auto-generated "What's Changed".

Expand All @@ -56,6 +51,9 @@ if a Release for the tag already exists, so tags are effectively immutable.

## Notes

- The CI publish needs the `HF_TOKEN` secret to have **write** access to
`pyronear/temporal-model`. Consumers fetch the ONNX artifact with
`release fetch --onnx` (or `make fetch-model-onnx`).
- The GitHub Release logic lives in `scripts/create-github-release.sh`; its
behavior is covered by `scripts/test-create-github-release.sh`.
- `pyproject.toml` versions are not the source of truth for the released version
Expand Down
14 changes: 6 additions & 8 deletions docs/runbooks/retrain-on-new-dataset.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ train/ dvc update → dvc repro (truncate → tubes → patches → train →
eval/ bump sequential_test + refresh model.zip → dvc repro (test)
new-vs-old metrics on the same test set
push dvc push (train + eval) → commit pointers + dvc.lock → PR
release bump api/MODEL_VERSION → publish model.zip to HF → git tag
release bump api/MODEL_VERSION → git tag (CI publishes model.zip to HF)
```

## 0. Snapshot the current model's metrics (before touching anything)
Expand Down Expand Up @@ -227,10 +227,8 @@ Follow **"Cutting a release" in [`docs/releasing.md`](../releasing.md)** — tha
is the canonical procedure; don't work from a copy of it here. The
retrain-specific parts:

- the `model.zip` to publish is
`train/data/06_models/vit_dinov2_finetune/model.zip` — the artifact this
loop just built, packaged, and evaluated;
- `publish` needs a **write** HF token (the read token in `api/.envrc` 403s at
upload);
- `publish` is immutable per version — a re-publish of an existing version
fails by design, so double-check the new version number before running it.
- CI publishes `train/data/06_models/vit_dinov2_finetune/model.zip` from the
tagged commit, the artifact this loop just built, packaged, and evaluated, so
tag a commit that includes the merged `result_*` PR;
- a version already on HuggingFace is never re-published, so double-check the
new version number in `api/MODEL_VERSION` before tagging.
Loading