Skip to content

Commit 4f7524b

Browse files
tadani3Tommaso Adanijustinchuby
authored
Fix --models flag being silently ignored by e2e golden tests (#217)
### Problem The `--models` flag passed from CI workflows (`gpu_l4_golden_parity.yml`, `gpu_l5_generation_e2e.yml`) was silently ignored by the e2e golden tests. All ~214 golden tests ran every time, regardless of which models were actually affected. **Root cause:** The `pytest_collection_modifyitems` hook in `tests/conftest.py` filters tests by checking for a `model_type` parameter in `item.callspec.params`. But golden tests are parametrized with a `case` object (`GoldenTestCase`), not `model_type`. The hook hit `continue` and skipped filtering entirely. ### Fix Added an explicit `model_type` field to the golden test YAML schema and wired it through to the filtering hook. **Changes:** | File | Change | |------|--------| | `testdata/cases/schema.json` | Added `model_type` to `required` and `properties` | | `src/mobius/_testing/golden.py` | Added `model_type: str` field to `GoldenTestCase`, extracted in `load_test_case()` | | `tests/conftest.py` | Extended `--models` hook to check `case.model_type` for golden test items | | `testdata/cases/**/*.yaml` (214 files) | Added `model_type` line to each YAML case file | ### Why this approach - **Declarative, not runtime:** `model_type` is a static YAML field — no reverse-map lookups, no registry imports in test infra, no network calls at collection time. - **Fails closed:** Missing `model_type` causes a schema validation error (`yaml_schema_test.py`) and a `load_test_case()` `ValueError`. New YAML cases can't silently bypass the filter. - **Consistent:** Same pattern as `model_id`, `task_type`, `dtype` — already-required fields in the schema. ### Verification | Test | Result | |------|--------| | `pytest tests/yaml_schema_test.py` | 218 passed — all YAMLs valid | | `--models qwen2` | 343 skipped, only qwen2 tests ran | | `--models nonexistent` | 345 skipped — all golden tests filtered out | | `--models llama` on `build_graph_test.py` | Existing filtering unchanged | --------- Co-authored-by: Tommaso Adani <[email protected]> Co-authored-by: Justin Chu <[email protected]>
1 parent 41d2641 commit 4f7524b

223 files changed

Lines changed: 269 additions & 17 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.agents/skills/writing-tests/references/test-examples.md‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,11 @@ Guidelines for choosing models:
111111
Categories match task types: `causal-lm`, `encoder`, `seq2seq`, `audio`,
112112
`vision`, `vision-language`, `diffusion`.
113113

114-
**Required fields:**
114+
**Required fields** (enforced by `testdata/cases/schema.json`; `tests/yaml_schema_test.py` validates every YAML on every PR):
115115

116116
```yaml
117117
model_id: "Qwen/Qwen2.5-1.5B-Instruct" # HuggingFace model ID
118+
model_type: "qwen2" # HF config.model_type — must match a key in mobius._registry
118119
revision: "main" # Git revision / commit SHA
119120
task_type: "text-generation" # Task type string
120121
dtype: "float32" # "float32", "float16", or "bfloat16"
@@ -125,6 +126,8 @@ inputs:
125126
- "Here is my poem:" # Text prompt(s); use this default
126127
```
127128
129+
`model_type` is the value the registry lookup uses (see `_create_default_registry()` in `src/mobius/_registry.py`). It is **also** what `tests/model_coverage_test.py` keys on — every registered `model_type` must either appear in some YAML's `model_type` field or be added to `_COVERAGE_SKIP` with a reason. Omit it and the schema test fails; provide a value the registry doesn't know and the coverage test still flags it.
130+
128131
For image models, use `images:` instead of (or alongside) `prompts:`:
129132

130133
```yaml
@@ -209,8 +212,11 @@ Golden files must be committed alongside new test case YAML files.
209212

210213
**L2 — Config compatible:**
211214
1. Create `testdata/cases/<category>/my-model.yaml`.
212-
2. Set `test_model_id: "org/my-model-id"`.
215+
2. Fill in all required fields, including `model_type` (must match the
216+
key registered in `src/mobius/_registry.py`) and `test_model_id`.
213217
3. Run schema validation: `python -m pytest tests/yaml_schema_test.py`.
218+
4. Run coverage check: `python -m pytest tests/model_coverage_test.py` —
219+
fails if any registered `model_type` lacks a YAML or `_COVERAGE_SKIP` entry.
214220

215221
**L3 — Synthetic parity:**
216222
1. Add `pytest.param("org/my-model", False, id="my-model")` to the

‎.github/workflows/main.yml‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ on:
1010
- v*
1111
pull_request:
1212

13-
# Allows you to run this workflow manually from the Actions tab
14-
workflow_dispatch:
15-
1613
concurrency:
17-
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name == 'workflow_dispatch' }}
14+
group: ${{ github.workflow }}-${{ github.ref }}
1815
cancel-in-progress: true
1916

2017
jobs:
@@ -33,7 +30,8 @@ jobs:
3330
detect-affected:
3431
name: Detect affected models
3532
runs-on: ubuntu-latest
36-
if: github.event_name == 'pull_request'
33+
# Run on PRs and pushes to main. Skip on tag pushes — those go through release.
34+
if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/main')
3735
outputs:
3836
affected: ${{ steps.detect.outputs.affected }}
3937
run_all: ${{ steps.detect.outputs.run_all }}
@@ -46,8 +44,20 @@ jobs:
4644
id: changed
4745
env:
4846
BASE_REF: ${{ github.base_ref }}
47+
BEFORE_SHA: ${{ github.event.before }}
48+
AFTER_SHA: ${{ github.sha }}
4949
run: |
50-
git diff --name-only origin/"$BASE_REF"...HEAD > changed_files.txt
50+
if [ "${{ github.event_name }}" = "pull_request" ]; then
51+
git diff --name-only origin/"$BASE_REF"...HEAD > changed_files.txt
52+
else
53+
# push to main: diff the pushed range. Fall back to HEAD~1 when
54+
# `before` is the zero SHA (e.g. first push of a new branch).
55+
if [ -z "$BEFORE_SHA" ] || [ "$BEFORE_SHA" = "0000000000000000000000000000000000000000" ]; then
56+
git diff --name-only HEAD~1...HEAD > changed_files.txt
57+
else
58+
git diff --name-only "$BEFORE_SHA"..."$AFTER_SHA" > changed_files.txt
59+
fi
60+
fi
5161
echo "Changed files:"
5262
cat changed_files.txt
5363
- name: Detect affected models
@@ -110,7 +120,7 @@ jobs:
110120
always() && !cancelled() &&
111121
(needs.detect-affected.result == 'failure' ||
112122
needs.detect-affected.outputs.has_affected == 'true' ||
113-
github.event_name != 'pull_request')
123+
needs.detect-affected.result == 'skipped')
114124
steps:
115125
- uses: actions/checkout@v6
116126
- name: Setup Python
@@ -141,7 +151,7 @@ jobs:
141151
fi
142152
if [ "${{ needs.detect-affected.result }}" = "failure" ] || \
143153
[ "${{ needs.detect-affected.outputs.run_all }}" = "true" ] || \
144-
[ "${{ github.event_name }}" != "pull_request" ]; then
154+
[ "${{ needs.detect-affected.result }}" = "skipped" ]; then
145155
echo "Running all synthetic parity tests"
146156
pytest tests/synthetic_parity_test.py -v --tb=short -n auto \
147157
--cov=src --cov-report=xml --cov-branch --junitxml junit.xml
@@ -178,7 +188,7 @@ jobs:
178188
always() && !cancelled() &&
179189
(needs.detect-affected.result == 'failure' ||
180190
needs.detect-affected.outputs.has_affected == 'true' ||
181-
github.event_name != 'pull_request')
191+
needs.detect-affected.result == 'skipped')
182192
uses: ./.github/workflows/gpu_l4_golden_parity.yml
183193
with:
184194
affected_models: ${{ needs.detect-affected.outputs.affected }}
@@ -193,7 +203,7 @@ jobs:
193203
always() && !cancelled() &&
194204
(needs.detect-affected.result == 'failure' ||
195205
needs.detect-affected.outputs.has_affected == 'true' ||
196-
github.event_name != 'pull_request')
206+
needs.detect-affected.result == 'skipped')
197207
uses: ./.github/workflows/gpu_l5_generation_e2e.yml
198208
with:
199209
affected_models: ${{ needs.detect-affected.outputs.affected }}

‎src/mobius/_testing/golden.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ class GoldenTestCase:
7070
model_id: str
7171
"""HuggingFace model ID (e.g. ``Qwen/Qwen2.5-0.5B``)."""
7272

73+
model_type: str
74+
"""Registry model_type key (e.g. ``qwen2``, ``llama``)."""
75+
7376
revision: str
7477
"""HF model revision / commit SHA."""
7578

@@ -204,7 +207,7 @@ def load_test_case(yaml_path: Path) -> GoldenTestCase:
204207
raise TypeError(f"Expected a YAML mapping in {yaml_path}, got {type(data)}")
205208

206209
# Validate required top-level fields
207-
_required = ("model_id", "revision", "task_type", "dtype", "level")
210+
_required = ("model_id", "model_type", "revision", "task_type", "dtype", "level")
208211
missing = [k for k in _required if k not in data]
209212
if missing:
210213
raise ValueError(f"Missing required fields in {yaml_path}: {missing}")
@@ -220,6 +223,7 @@ def load_test_case(yaml_path: Path) -> GoldenTestCase:
220223
case_id=case_id,
221224
task_type=data["task_type"],
222225
model_id=data["model_id"],
226+
model_type=data["model_type"],
223227
revision=data["revision"],
224228
dtype=data["dtype"],
225229
level=data["level"],

‎src/mobius/_testing/golden_test.py‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
MINIMAL_YAML = """\
3131
model_id: "test-org/test-model"
32+
model_type: "test_model"
3233
revision: "abc123"
3334
task_type: "text-generation"
3435
dtype: "float32"
@@ -40,6 +41,7 @@
4041

4142
VL_YAML = """\
4243
model_id: "test-org/test-vl"
44+
model_type: "test_vl"
4345
revision: "def456"
4446
task_type: "qwen-vl"
4547
dtype: "float32"
@@ -57,6 +59,7 @@
5759

5860
SKIP_YAML = """\
5961
model_id: "test-org/skip-model"
62+
model_type: "test_skip"
6063
revision: "aaa111"
6164
task_type: "text-generation"
6265
dtype: "float32"
@@ -293,19 +296,19 @@ def _setup_cases(self, tmp_path: Path) -> Path:
293296
_write_yaml(
294297
causal,
295298
"model-a.yaml",
296-
'model_id: "a"\nrevision: "1"\ntask_type: "text-generation"'
299+
'model_id: "a"\nmodel_type: "a"\nrevision: "1"\ntask_type: "text-generation"'
297300
'\ndtype: "float32"\nlevel: "L4+L5"\n',
298301
)
299302
_write_yaml(
300303
causal,
301304
"model-b.yaml",
302-
'model_id: "b"\nrevision: "2"\ntask_type: "text-generation"'
305+
'model_id: "b"\nmodel_type: "b"\nrevision: "2"\ntask_type: "text-generation"'
303306
'\ndtype: "float32"\nlevel: "L4"\n',
304307
)
305308
_write_yaml(
306309
encoder,
307310
"model-c.yaml",
308-
'model_id: "c"\nrevision: "3"\n'
311+
'model_id: "c"\nmodel_type: "c"\nrevision: "3"\n'
309312
'task_type: "feature-extraction"'
310313
'\ndtype: "float32"\nlevel: "L4"\n',
311314
)
@@ -362,7 +365,7 @@ def test_malformed_yaml_skipped(self, tmp_path: Path):
362365
_write_yaml(
363366
root,
364367
"good.yaml",
365-
'model_id: "ok"\nrevision: "1"\n'
368+
'model_id: "ok"\nmodel_type: "ok"\nrevision: "1"\n'
366369
'task_type: "text-generation"'
367370
'\ndtype: "float32"\nlevel: "L4"\n',
368371
)

‎testdata/cases/audio/data2vec-audio-base.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
model_id: "facebook/data2vec-audio-base-960h"
2+
model_type: "data2vec-audio"
23
revision: "main"
34
task_type: "audio-feature-extraction"
45
dtype: "float32"

‎testdata/cases/audio/hubert-base.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
model_id: "facebook/hubert-base-ls960"
2+
model_type: "hubert"
23
revision: "main"
34
task_type: "audio-feature-extraction"
45
dtype: "float32"

‎testdata/cases/audio/musicgen-small.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
model_id: "facebook/musicgen-small"
2+
model_type: "musicgen"
23
revision: "main"
34
task_type: "audio-to-audio"
45
dtype: "float32"

‎testdata/cases/audio/seamless-m4t-medium.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
model_id: "facebook/hf-seamless-m4t-medium"
2+
model_type: "seamless_m4t"
23
revision: "main"
34
task_type: "speech-to-text"
45
dtype: "float32"

‎testdata/cases/audio/seamless-m4t-v2-large.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
model_id: "facebook/seamless-m4t-v2-large"
2+
model_type: "seamless_m4t_v2"
23
revision: "main"
34
task_type: "speech-to-text"
45
dtype: "float32"

‎testdata/cases/audio/sew-d-tiny.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
model_id: "asapp/sew-d-tiny-100k"
2+
model_type: "sew-d"
23
revision: "main"
34
task_type: "audio-feature-extraction"
45
dtype: "float32"

0 commit comments

Comments
 (0)