Skip to content

Commit 5526456

Browse files
ci: avoid HF 429 on PRs by caching models and downloading minimal model set (#252)
Signed-off-by: Jintao Zhang <[email protected]>
1 parent 9f90230 commit 5526456

File tree

2 files changed

+151
-120
lines changed

2 files changed

+151
-120
lines changed
Lines changed: 114 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,114 @@
1-
name: Test And Build
2-
3-
on:
4-
schedule:
5-
# Run nightly at 2:00 AM UTC
6-
- cron: '0 2 * * *'
7-
workflow_dispatch: # Allow manual triggering
8-
pull_request: # Run on all pull requests
9-
10-
jobs:
11-
test-and-build:
12-
runs-on: ubuntu-latest
13-
14-
steps:
15-
- name: Check out the repo
16-
uses: actions/checkout@v4
17-
18-
- name: Set up Rust
19-
uses: dtolnay/rust-toolchain@stable
20-
with:
21-
toolchain: 1.85
22-
23-
- name: Set up Go
24-
uses: actions/setup-go@v5
25-
with:
26-
go-version: '1.24'
27-
28-
- name: Install system dependencies
29-
run: |
30-
sudo apt-get update
31-
sudo apt-get install -y \
32-
make \
33-
build-essential \
34-
pkg-config
35-
36-
- name: Cache Rust dependencies
37-
uses: actions/cache@v4
38-
with:
39-
path: |
40-
~/.cargo/bin/
41-
~/.cargo/registry/index/
42-
~/.cargo/registry/cache/
43-
~/.cargo/git/db/
44-
candle-binding/target/
45-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml') }}
46-
restore-keys: |
47-
${{ runner.os }}-cargo-
48-
49-
- name: Cache Go dependencies
50-
uses: actions/cache@v4
51-
with:
52-
path: |
53-
~/go/pkg/mod
54-
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
55-
restore-keys: |
56-
${{ runner.os }}-go-
57-
58-
- name: Cache Models
59-
uses: actions/cache@v4
60-
with:
61-
path: |
62-
models/
63-
key: ${{ runner.os }}-models-v1-${{ hashFiles('tools/make/models.mk') }}
64-
restore-keys: |
65-
${{ runner.os }}-models-v1-
66-
67-
- name: Check go mod tidy
68-
run: make check-go-mod-tidy
69-
70-
- name: Build Rust library
71-
run: make rust
72-
73-
- name: Install HuggingFace CLI
74-
run: |
75-
pip install -U "huggingface_hub[cli]"
76-
77-
- name: Download models
78-
run: make download-models
79-
80-
- name: Run semantic router tests
81-
run: make test
82-
env:
83-
CGO_ENABLED: 1
84-
LD_LIBRARY_PATH: ${{ github.workspace }}/candle-binding/target/release
85-
86-
- name: Upload test artifacts on failure
87-
if: failure()
88-
uses: actions/upload-artifact@v4
89-
with:
90-
name: test-logs
91-
path: |
92-
**/*.log
93-
**/test-output.*
94-
retention-days: 7
95-
96-
- name: Notify on failure
97-
if: failure()
98-
run: |
99-
echo "::error::Test and build failed. Check the workflow run for details."
100-
101-
# Trigger Docker publishing on successful nightly runs
102-
publish-docker:
103-
needs: test-and-build
104-
if: success() && github.event_name == 'schedule'
105-
uses: ./.github/workflows/docker-publish.yml
106-
with:
107-
tag_suffix: nightly-$(date +'%Y%m%d')
108-
is_nightly: true
109-
secrets: inherit
1+
name: Test And Build
2+
3+
on:
4+
schedule:
5+
# Run nightly at 2:00 AM UTC
6+
- cron: "0 2 * * *"
7+
workflow_dispatch: # Allow manual triggering
8+
pull_request: # Run on all pull requests
9+
10+
jobs:
11+
test-and-build:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Check out the repo
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Rust
19+
uses: dtolnay/rust-toolchain@stable
20+
with:
21+
toolchain: 1.85
22+
23+
- name: Set up Go
24+
uses: actions/setup-go@v5
25+
with:
26+
go-version: "1.24"
27+
28+
- name: Install system dependencies
29+
run: |
30+
sudo apt-get update
31+
sudo apt-get install -y \
32+
make \
33+
build-essential \
34+
pkg-config
35+
36+
- name: Cache Rust dependencies
37+
uses: actions/cache@v4
38+
with:
39+
path: |
40+
~/.cargo/bin/
41+
~/.cargo/registry/index/
42+
~/.cargo/registry/cache/
43+
~/.cargo/git/db/
44+
candle-binding/target/
45+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml') }}
46+
restore-keys: |
47+
${{ runner.os }}-cargo-
48+
49+
- name: Cache Go dependencies
50+
uses: actions/cache@v4
51+
with:
52+
path: |
53+
~/go/pkg/mod
54+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
55+
restore-keys: |
56+
${{ runner.os }}-go-
57+
58+
- name: Cache Models
59+
uses: actions/cache@v4
60+
with:
61+
path: |
62+
models/
63+
key: ${{ runner.os }}-models-v1-${{ hashFiles('tools/make/models.mk') }}
64+
restore-keys: |
65+
${{ runner.os }}-models-v1-
66+
67+
- name: Check go mod tidy
68+
run: make check-go-mod-tidy
69+
70+
- name: Build Rust library
71+
run: make rust
72+
73+
- name: Install HuggingFace CLI
74+
run: |
75+
pip install -U "huggingface_hub[cli]"
76+
77+
78+
- name: Download models (minimal on PRs)
79+
env:
80+
CI_MINIMAL_MODELS: ${{ github.event_name == 'pull_request' }}
81+
HF_HUB_ENABLE_HF_TRANSFER: 1
82+
HF_HUB_DISABLE_TELEMETRY: 1
83+
run: make download-models
84+
85+
- name: Run semantic router tests
86+
run: make test
87+
env:
88+
CGO_ENABLED: 1
89+
LD_LIBRARY_PATH: ${{ github.workspace }}/candle-binding/target/release
90+
91+
- name: Upload test artifacts on failure
92+
if: failure()
93+
uses: actions/upload-artifact@v4
94+
with:
95+
name: test-logs
96+
path: |
97+
**/*.log
98+
**/test-output.*
99+
retention-days: 7
100+
101+
- name: Notify on failure
102+
if: failure()
103+
run: |
104+
echo "::error::Test and build failed. Check the workflow run for details."
105+
106+
# Trigger Docker publishing on successful nightly runs
107+
publish-docker:
108+
needs: test-and-build
109+
if: success() && github.event_name == 'schedule'
110+
uses: ./.github/workflows/docker-publish.yml
111+
with:
112+
tag_suffix: nightly-$(date +'%Y%m%d')
113+
is_nightly: true
114+
secrets: inherit

tools/make/models.mk

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,44 @@
22
# = Everything For models =
33
# ======== models.mk ========
44

5+
# CI_MINIMAL_MODELS=true will download only the minimal set of models required for tests.
6+
# Default behavior downloads the full set used for local development.
7+
58
download-models:
69
@$(LOG_TARGET)
10+
@mkdir -p models
11+
@if [ "$$CI_MINIMAL_MODELS" = "true" ]; then \
12+
echo "CI_MINIMAL_MODELS=true -> downloading minimal model set"; \
13+
$(MAKE) -s download-models-minimal; \
14+
else \
15+
echo "CI_MINIMAL_MODELS not set -> downloading full model set"; \
16+
$(MAKE) -s download-models-full; \
17+
fi
18+
19+
# Minimal models needed to run unit tests on CI (avoid rate limits)
20+
# - Category classifier (ModernBERT)
21+
# - PII token classifier (ModernBERT Presidio)
22+
# - Jailbreak classifier (ModernBERT)
23+
# - Optional plain PII classifier mapping (small)
24+
25+
download-models-minimal:
26+
@mkdir -p models
27+
@if [ ! -d "models/category_classifier_modernbert-base_model" ]; then \
28+
hf download LLM-Semantic-Router/category_classifier_modernbert-base_model --local-dir models/category_classifier_modernbert-base_model; \
29+
fi
30+
@if [ ! -d "models/pii_classifier_modernbert-base_presidio_token_model" ]; then \
31+
hf download LLM-Semantic-Router/pii_classifier_modernbert-base_presidio_token_model --local-dir models/pii_classifier_modernbert-base_presidio_token_model; \
32+
fi
33+
@if [ ! -d "models/jailbreak_classifier_modernbert-base_model" ]; then \
34+
hf download LLM-Semantic-Router/jailbreak_classifier_modernbert-base_model --local-dir models/jailbreak_classifier_modernbert-base_model; \
35+
fi
36+
@if [ ! -d "models/pii_classifier_modernbert-base_model" ]; then \
37+
hf download LLM-Semantic-Router/pii_classifier_modernbert-base_model --local-dir models/pii_classifier_modernbert-base_model; \
38+
fi
39+
40+
# Full model set for local development and docs
41+
42+
download-models-full:
743
@mkdir -p models
844
@if [ ! -d "models/category_classifier_modernbert-base_model" ]; then \
945
hf download LLM-Semantic-Router/category_classifier_modernbert-base_model --local-dir models/category_classifier_modernbert-base_model; \
@@ -14,43 +50,33 @@ download-models:
1450
@if [ ! -d "models/jailbreak_classifier_modernbert-base_model" ]; then \
1551
hf download LLM-Semantic-Router/jailbreak_classifier_modernbert-base_model --local-dir models/jailbreak_classifier_modernbert-base_model; \
1652
fi
17-
18-
@if [ ! -d "models/pii_classifier_modernbert_base_presidio_token_model" ]; then \
53+
@if [ ! -d "models/pii_classifier_modernbert-base_presidio_token_model" ]; then \
1954
hf download LLM-Semantic-Router/pii_classifier_modernbert-base_presidio_token_model --local-dir models/pii_classifier_modernbert-base_presidio_token_model; \
2055
fi
21-
2256
@if [ ! -d "models/lora_intent_classifier_bert-base-uncased_model" ]; then \
2357
hf download LLM-Semantic-Router/lora_intent_classifier_bert-base-uncased_model --local-dir models/lora_intent_classifier_bert-base-uncased_model; \
2458
fi
25-
2659
@if [ ! -d "models/lora_intent_classifier_roberta-base_model" ]; then \
2760
hf download LLM-Semantic-Router/lora_intent_classifier_roberta-base_model --local-dir models/lora_intent_classifier_roberta-base_model; \
2861
fi
29-
3062
@if [ ! -d "models/lora_intent_classifier_modernbert-base_model" ]; then \
3163
hf download LLM-Semantic-Router/lora_intent_classifier_modernbert-base_model --local-dir models/lora_intent_classifier_modernbert-base_model; \
3264
fi
33-
3465
@if [ ! -d "models/lora_pii_detector_bert-base-uncased_model" ]; then \
3566
hf download LLM-Semantic-Router/lora_pii_detector_bert-base-uncased_model --local-dir models/lora_pii_detector_bert-base-uncased_model; \
3667
fi
37-
3868
@if [ ! -d "models/lora_pii_detector_roberta-base_model" ]; then \
3969
hf download LLM-Semantic-Router/lora_pii_detector_roberta-base_model --local-dir models/lora_pii_detector_roberta-base_model; \
4070
fi
41-
4271
@if [ ! -d "models/lora_pii_detector_modernbert-base_model" ]; then \
4372
hf download LLM-Semantic-Router/lora_pii_detector_modernbert-base_model --local-dir models/lora_pii_detector_modernbert-base_model; \
4473
fi
45-
4674
@if [ ! -d "models/lora_jailbreak_classifier_bert-base-uncased_model" ]; then \
4775
hf download LLM-Semantic-Router/lora_jailbreak_classifier_bert-base-uncased_model --local-dir models/lora_jailbreak_classifier_bert-base-uncased_model; \
4876
fi
49-
5077
@if [ ! -d "models/lora_jailbreak_classifier_roberta-base_model" ]; then \
5178
hf download LLM-Semantic-Router/lora_jailbreak_classifier_roberta-base_model --local-dir models/lora_jailbreak_classifier_roberta-base_model; \
5279
fi
53-
5480
@if [ ! -d "models/lora_jailbreak_classifier_modernbert-base_model" ]; then \
5581
hf download LLM-Semantic-Router/lora_jailbreak_classifier_modernbert-base_model --local-dir models/lora_jailbreak_classifier_modernbert-base_model; \
5682
fi

0 commit comments

Comments
 (0)