Skip to content

Commit 2ba75cc

Browse files
committed
[None][feat] trtllm_modeling_v2 regression: leave out at the head the tests that fail at the base
A regression is a test that passed at the base and fails at the head. A test that already fails at the base can never be one, yet every head ran it again. On the Qwen3.8 FP8 run, 18 Kimi-K3 4-GPU cases timed out at 180 s on every commit, base included: 54 min a check for no signal. Once the head's environment is probed, the check leaves out the reached tests that failed at the base in that environment. The test driver takes the list (`--skip`), records nothing for them, and the comparison counts a test with no result at the head that fails at the base as one that cannot regress, not as unrun. The check's scope says how many it left out. Nothing is recorded for a left-out test, so the delivered-tests check and any later check still run it at the head. Signed-off-by: Wanli Jiang <35160485+Wanli-Jiang@users.noreply.github.com>
1 parent 3b6286c commit 2ba75cc

5 files changed

Lines changed: 106 additions & 22 deletions

File tree

‎agent-flow/agent_flow/workflows/trtllm_modeling_v2/README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ must change before that.
115115
target. Commits are audited and integrated; shared-code changes require regression coverage.
116116
A regression check runs only when no contract check runs or waits, and only on the test files
117117
the change can reach (those it changed, those importing a module it changed, the claims
118-
gates; every file when it touches code the whole package shares). A kernel task on a shared
118+
gates; every file when it touches code the whole package shares). A test that already fails
119+
at the check's base cannot regress, so the head does not run it. A kernel task on a shared
119120
catalog entry lands a local variant in the target's own `ops/`, and the target is delivered
120121
with it: the run never changes a shared entry, so other models are not disturbed mid-run.
121122
3. **Prove and deliver:** checks measure fixed-commit snapshots against framework-owned references.

‎agent-flow/agent_flow/workflows/trtllm_modeling_v2/checks/harness/test_driver.py‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
Usage, in the tree under test with that tree's python (standard library and
88
pytest only, so it runs by path in any job)::
99
10-
<python> test_driver.py run --cache DIR [--repo TREE] [--selection FILE] [ITEM ...] [-- PYTEST ARGS]
10+
<python> test_driver.py run --cache DIR [--repo TREE] [--selection FILE] [--skip FILE] [ITEM ...] [-- PYTEST ARGS]
1111
1212
``run`` takes test files and node ids (``ITEM``, or one per line in
1313
``--selection``) and runs one pytest process per test file, a ``session``
1414
each: a file that brings its process down loses only its own results, and a
15-
job cut short keeps every file it finished.
15+
job cut short keeps every file it finished. ``--skip`` lists node ids, one per
16+
line, to leave out of those files: they run nowhere and record nothing.
1617
1718
A session writes one JSON record to ``<cache>/sessions/``: the tree's commit
1819
and whether its tracked files were clean, the environment and its digest, the
@@ -170,7 +171,7 @@ def _message(report) -> str:
170171
return (lines[0] if lines else "")[:400]
171172

172173

173-
def _plugin(record: dict, repo: str, selected: set[str] | None):
174+
def _plugin(record: dict, repo: str, selected: set[str] | None, skipped: set[str]):
174175
import pytest
175176

176177
tests: dict[str, dict] = record["tests"]
@@ -194,13 +195,14 @@ def pytest_collection_modifyitems(self, session, config, items):
194195
ids[item.nodeid] = repo_id(item.path, item.nodeid)
195196
file, _, name = ids[item.nodeid].partition("::")
196197
record["collected"].setdefault(file, []).append(name)
197-
if selected is None:
198+
if selected is None and not skipped:
198199
return
199-
files = {s for s in selected if "::" not in s}
200+
files = {s for s in selected if "::" not in s} if selected is not None else set()
200201
keep, drop = [], []
201202
for item in items:
202203
rid = ids[item.nodeid]
203-
(keep if rid in selected or rid.partition("::")[0] in files else drop).append(item)
204+
chosen = selected is None or rid in selected or rid.partition("::")[0] in files
205+
(keep if chosen and rid not in skipped else drop).append(item)
204206
if drop:
205207
config.hook.pytest_deselected(items=drop)
206208
items[:] = keep
@@ -274,6 +276,7 @@ def session(args: argparse.Namespace) -> int:
274276
"collected": {},
275277
}
276278
selected = set(_read_selection(args.select, [])) if args.select else None
279+
skipped = set(_read_selection(args.skip, [])) if args.skip else set()
277280
# As `python -m pytest` from the tree: the tree first on sys.path, this
278281
# script's directory nowhere on it.
279282
here = os.path.dirname(os.path.abspath(__file__))
@@ -282,7 +285,9 @@ def session(args: argparse.Namespace) -> int:
282285
os.chdir(repo)
283286
import pytest
284287

285-
code = int(pytest.main(list(args.pytest_args), plugins=[_plugin(record, repo, selected)]))
288+
code = int(
289+
pytest.main(list(args.pytest_args), plugins=[_plugin(record, repo, selected, skipped)])
290+
)
286291
record["exit_code"] = code
287292
record["ended"] = _now()
288293
path = _write(args.cache, record)
@@ -318,6 +323,8 @@ def run(args: argparse.Namespace) -> int:
318323
with open(select, "w", encoding="utf-8") as handle:
319324
handle.write("\n".join(items) + "\n")
320325
command += ["--select", select]
326+
if args.skip:
327+
command += ["--skip", os.path.abspath(args.skip)]
321328
command += ["--", *args.pytest_args, file]
322329
print(
323330
f"testcache: {file}: {'whole file' if whole else f'{len(items)} test(s)'}", flush=True
@@ -353,6 +360,7 @@ def _parse(argv: list[str]) -> argparse.Namespace:
353360
p.add_argument("items", nargs="*", help="Test files and node ids.")
354361
else:
355362
p.add_argument("--select", default="", help="Keep only these node ids.")
363+
p.add_argument("--skip", default="", help="A file of node ids to leave out.")
356364
if "--" in argv:
357365
at = argv.index("--")
358366
args = parser.parse_args(argv[:at])

‎agent-flow/agent_flow/workflows/trtllm_modeling_v2/checks/test_results.py‎

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import shlex
1515
from dataclasses import dataclass, field
1616
from pathlib import Path
17-
from typing import Iterable, Sequence
17+
from typing import Collection, Iterable, Sequence
1818

1919
import yaml
2020

@@ -100,12 +100,16 @@ def result(self, nodeid: str) -> Result | None:
100100
return None
101101
return Result(nodeid, str(entry.get("outcome") or "error"), str(entry.get("message") or ""))
102102

103-
def unrun(self, files: Iterable[str]) -> list[str]:
104-
"""The ``files`` holding a test with no result here: what is still to run."""
103+
def unrun(self, files: Iterable[str], settled: Collection[str] = ()) -> list[str]:
104+
"""The ``files`` holding a test with no result here: what is still to run.
105+
106+
A test in ``settled`` is not waited for: it is left out on purpose.
107+
"""
105108
return [
106109
file
107110
for file in files
108-
if (ids := self.test_ids(file)) is None or any(i not in self.tests for i in ids)
111+
if (ids := self.test_ids(file)) is None
112+
or any(i not in self.tests and i not in settled for i in ids)
109113
]
110114

111115

@@ -149,6 +153,8 @@ class CompareReport:
149153
base_unknown: list[Comparison] = field(default_factory=list)
150154
#: Test ids with no result at the head; a file no session collected, whole.
151155
not_run: list[str] = field(default_factory=list)
156+
#: Test ids with no result at the head that fail at the base: no change can regress them.
157+
failing_at_base: list[str] = field(default_factory=list)
152158
passed: int = 0
153159

154160
@property
@@ -170,6 +176,8 @@ def compare(
170176
the base does not hold it (its file is not among ``base_files``, or the
171177
base's collection of that file has no such test); pre-existing when it
172178
failed there too; and of unknown standing when the base has no result for it.
179+
A test with no result at the head is not run there, unless it fails at the
180+
base: a test that already fails cannot regress.
173181
"""
174182
at_base = set(base_files)
175183
report = CompareReport()
@@ -182,7 +190,11 @@ def compare(
182190
for nodeid in ids:
183191
now = head.result(nodeid)
184192
if now is None:
185-
report.not_run.append(nodeid)
193+
then = base.result(nodeid)
194+
if then is not None and then.outcome in FAILING:
195+
report.failing_at_base.append(nodeid)
196+
else:
197+
report.not_run.append(nodeid)
186198
continue
187199
if now.outcome not in FAILING:
188200
report.passed += 1
@@ -306,10 +318,21 @@ def write_selection(path: Path, lines: Sequence[str]) -> Path:
306318
return path
307319

308320

309-
def driver_command(python: str, cache: str | Path, tree: str | Path, selection: str | Path) -> str:
310-
"""The driver's command line over the tests ``selection`` lists, run in ``tree``."""
321+
def driver_command(
322+
python: str,
323+
cache: str | Path,
324+
tree: str | Path,
325+
selection: str | Path,
326+
skip: str | Path | None = None,
327+
) -> str:
328+
"""The driver's command line over the tests ``selection`` lists, run in ``tree``.
329+
330+
``skip`` lists node ids to leave out of the files the selection names.
331+
"""
311332
words = [str(DRIVER), "run", "--cache", str(cache), "--repo", str(tree)]
312333
words += ["--selection", str(selection)]
334+
if skip is not None:
335+
words += ["--skip", str(skip)]
313336
return (
314337
f"{python} {' '.join(shlex.quote(w) for w in words)} "
315338
"-- -p no:cacheprovider -rA --timeout=180"

‎agent-flow/agent_flow/workflows/trtllm_modeling_v2/run/validation/regression.py‎

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
results (``checks/test_results.py``), which hold at the exact commit they ran at:
88
99
1. at the commit the checkout is at (the head), every test file with no result
10-
there yet, in a read-only snapshot of the head (:func:`record_at`);
10+
there yet, in a read-only snapshot of the head (:func:`record_at`), less the
11+
tests that already fail at the base: none of those can regress;
1112
2. at the commit the last check cleared, else the run's starting commit (the
1213
base), the tests that fail at the head and have no result there;
1314
3. the results at the head against those at the base.
@@ -42,7 +43,7 @@
4243
import shlex
4344
from dataclasses import dataclass, field
4445
from pathlib import Path
45-
from typing import Any, Callable, ContextManager, Sequence
46+
from typing import Any, Callable, Collection, ContextManager, Sequence
4647

4748
from ...checks import test_results
4849
from ...infra.compute.commands import CommandSpec
@@ -219,11 +220,13 @@ def record_at(
219220
tree_at: TreeAt,
220221
run_job: RunJob,
221222
python: str,
223+
leave_out: Callable[[str], Collection[str]] | None = None,
222224
) -> tuple[test_results.Results, int, int, str]:
223225
"""Probe the current environment, then run missing ``files`` at ``commit``.
224226
225227
The probe is one short job (:data:`PROBE_TIMEOUT_S`); the test jobs, as many as
226228
:data:`TEST_BUDGET_S` holds at the runner's job size (:func:`_run_unrun`).
229+
``leave_out`` names, given the probed environment's digest, the node ids not to run.
227230
Returns results, test jobs run, and the last job's exit code and output tail.
228231
A failed probe returns empty results, never historical results.
229232
"""
@@ -242,6 +245,7 @@ def record_at(
242245
tree_at=tree_at,
243246
run_job=run_job,
244247
python=python,
248+
skip=leave_out(match.group(1)) if leave_out is not None else (),
245249
)
246250

247251

@@ -255,23 +259,31 @@ def _run_unrun(
255259
tree_at: TreeAt,
256260
run_job: RunJob,
257261
python: str,
262+
skip: Collection[str] = (),
258263
) -> tuple[test_results.Results, int, int, str]:
259264
"""Run the ``items`` (test files, node ids) with no result at ``commit`` in ``env_digest``.
260265
261266
A job at a time, each resuming from what the last recorded, while one makes progress and
262-
:func:`max_jobs` of the runner's job size are not spent. Returns what :func:`record_at` does.
267+
:func:`max_jobs` of the runner's job size are not spent. The node ids in ``skip`` are left
268+
out and not waited for. Returns what :func:`record_at` does.
263269
"""
264270
allowed = max_jobs(getattr(run_job, "timeout_s", JOB_TIMEOUT_S))
265271
results = test_results.recorded(cache_dir, commit, env_digest)
266-
unrun = results.unrun(items)
272+
unrun = results.unrun(items, skip)
273+
skipped = (
274+
test_results.write_selection(out / f"{commit[:12]}.skip.txt", sorted(skip))
275+
if skip
276+
else None
277+
)
267278
jobs, code, tail = 0, 0, ""
268279
while unrun and jobs < allowed:
269280
listed = test_results.write_selection(out / f"{commit[:12]}.txt", unrun)
270281
with tree_at(commit) as tree:
271-
code, tail = run_job(test_results.driver_command(python, cache_dir, tree, listed), tree)
282+
command = test_results.driver_command(python, cache_dir, tree, listed, skipped)
283+
code, tail = run_job(command, tree)
272284
jobs += 1
273285
results = test_results.recorded(cache_dir, commit, env_digest)
274-
left = results.unrun(items)
286+
left = results.unrun(items, skip)
275287
if len(left) >= len(unrun):
276288
break
277289
unrun = left
@@ -541,7 +553,21 @@ def run_regression_check(
541553
roots=(MODELING_V2_PACKAGE, *paths),
542554
)
543555
selected = set(files)
544-
results, ran, code, tail = record_at(head, files, **job)
556+
557+
def failing_at_base(env_digest: str) -> set[str]:
558+
"""The tests of ``files`` that failed at the base in ``env_digest``: none can regress."""
559+
if base is None:
560+
return set()
561+
at_base = test_results.recorded(cache_dir, base, env_digest)
562+
return {
563+
nodeid
564+
for nodeid, entry in at_base.tests.items()
565+
if "::" in nodeid
566+
and nodeid.partition("::")[0] in selected
567+
and entry.get("outcome") in test_results.FAILING
568+
}
569+
570+
results, ran, code, tail = record_at(head, files, leave_out=failing_at_base, **job)
545571
if files and not results.env_digest:
546572
# No session at the head: nothing the jobs ran can be read.
547573
failure = f"the test job recorded nothing (exit {code}): {tail[-500:]}"
@@ -570,6 +596,9 @@ def against_base() -> test_results.CompareReport:
570596
failures += [
571597
f"{c.head.nodeid} (fails at the head; no result at the base)" for c in report.base_unknown
572598
]
599+
if report.failing_at_base:
600+
left_out = f"{len(report.failing_at_base)} test(s) failing at the base not run"
601+
scope = f"{scope}; {left_out}" if scope else left_out
573602
return RegressionResult(head, base, report.verdict, _named(failures), report.passed, ran, scope)
574603

575604

‎agent-flow/tests/workflows/trtllm_modeling_v2/test_gates.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,6 +1664,29 @@ def test_environment_change_cannot_reuse_a_pass_and_probe_failure_is_incomplete(
16641664
assert jobs == 0 and code == 1 and "environment probe failed" in tail
16651665

16661666

1667+
@_requires_git
1668+
def test_a_test_that_fails_at_the_base_is_not_run_at_a_later_head(tmp_path):
1669+
"""Kimi-K3's 4-GPU cases time out at the base too: each head paid 54 min for no signal."""
1670+
repo, workspace, base = _regression_repo(tmp_path)
1671+
cache = workspace / tc.CACHE_DIRNAME
1672+
_run(f"{sys.executable} {drv.__file__} run --cache {cache} --repo {repo} tests/test_broken.py "
1673+
"-- -q -p no:cacheprovider") # fmt: skip
1674+
(repo / "pkg" / "mod.py").write_text(
1675+
"def f():\n return 1 # same answer\n", encoding="utf-8"
1676+
)
1677+
_git(repo, "commit", "-qam", "shared change")
1678+
head = _git(repo, "rev-parse", "HEAD")
1679+
1680+
result, ran = _check(repo, workspace, head, tmp_path)
1681+
1682+
assert result.verdict == "CLEAN", result.failures
1683+
assert "1 test(s) failing at the base not run" in result.scope
1684+
at_head = tc.recorded(cache, head)
1685+
assert at_head.result("tests/test_a.py::test_f").outcome == "passed"
1686+
assert at_head.result("tests/test_broken.py::test_broken") is None
1687+
assert len(ran) == 2, "the probe and one test job at the head; nothing at the base"
1688+
1689+
16671690
@_requires_git
16681691
def test_a_change_reaches_the_tests_that_import_it_through_other_files(tmp_path):
16691692
"""``catalog/_op.py`` reaches a test through the entry that imports it, or the helper that does."""

0 commit comments

Comments
 (0)