Skip to content

testing: wait for cards as long as it takes, and ask only for what a command needs - #459

Merged
tzhouam merged 2 commits into
mainfrom
feat/gpu-demand-wait-and-need
Nov 26, 2026
Merged

tzhouam merged 2 commits into
mainfrom
feat/gpu-demand-wait-and-need

Conversation

@tzhouam

@tzhouam tzhouam commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

Two commits that implement the owner's rules of 2026-11-26 for demand mode (IMX_GPU_MODE=demand, #455): wait for cards for as long as it takes, never name cards, ask only for as many as a command needs, and no reserve. Nothing changes outside demand mode.

Wait (e1f5fc0). IMX_GPU_WAIT has no default any more, so gpu run is given no --wait and queues the command until it gets its cards. The runner's timers and watchdog start when the scheduler grants them (_await_grant reads the side log once a second). Timed from the spawn, a command queued for two hours was killed by its own timeout in the queue. The side log is cleared before the spawn, since a grant recorded by the previous attempt would end this one's wait before it began. The log says that a command is queued and, once granted, how long it waited. A refusal is not a wait: the process exits and the log says not run as before.

The GPU lock keeps its bounded wait on purpose. A run holding it may sit in the queue for hours; an unbounded wait behind it would stall an agent's session without a word, where a lock timeout is feedback it can act on.

Need (e1f5fc0, 2ca822e). The module wrapper and the agents' run_pytest / reproduce asked for one card, where every earlier cycle showed a module's tests four. A test that needs more failed: tests/diffusion/models/hy_nomas/test_pixelumm_parallel.py spawns 2 and 4 processes, with no cards_N marker and no guard. A command's count is now what it needs:

  • a cards_N its own -m expression selects (its largest); one the expression negates is an exclusion, not a need;
  • else the largest number the tests it names declare at its run level, through a cards_N mark or a decorator's num_cards=. Tests of other levels and of excluded counts do not count: they skip by their own guard when the cards are not there. A test that declares nothing needs one.

The declaration is read with the ast module, because names inside strings are not needs (the target repository's own tests quote CI commands that say cards_8), and only test directories inside the repository root are walked. The result is kept for five minutes, since agents edit tests as they work.

Cap (e1f5fc0). IMX_GPU_MAX caps what one command asks for. It is not set by this repository: the campaign's launcher sets it to four.

Evidence

  • On the night of 2026-11-25/26 the machine was fully booked. Two of the input_output module's verification runs were skipped after their 30-minute queue wait, and its first session ended on that.
  • Declared needs at core_model, read from the target repository's tests: one card for the worker_runner, input_output, online_serving and model_config suites; four for the full runs of model_executor, scheduler and platform (196 files declare one card, 14 two, 6 four).
  • tests/e2e --run-level advanced_model declares eight cards: the whole machine. With an unbounded wait such a command might never be served, hence the cap.
  • A negated marker was counted as a need until 2ca822e. Seen in the running campaign: tests/distributed/ -m 'core_model and cuda and L4 and not cards_2' asked for two cards, and the repository's CPU job (core_model and cpu and not (cards_2 or ... or cards_8)) would have asked for eight.

Validation

Offline, on head 2ca822ef:

  • The 17 test files that import the changed modules pass. test_gpu_demand.py (82) uses a stand-in gpu executable and covers: the unbounded wait with the test timed from the grant (4 s in the queue, a test allowed 2 s, runs to its end), the bounded wait and its skip, a refusal, the lock keeping its default wait, the need read from decorators, module and class marks, a per-platform num_cards, strings ignored, other run levels ignored, exclusions, the cap, and the cache.
  • A test whose repository root was / and whose command said cd /tmp hung: the first version walked every directory a command named. It now walks only test directories inside the root, at most 4000 files.
  • tools/check_doc_links.py, tools/check_doc_citations.py, tools/check_spec_freshness.py --strict, both knowledge linters: clean.

Real execution: none of this has run against the real scheduler yet. The campaign it was written for runs the same code since 10:13 on 2026-11-26, but every test request it made since was for one card, and its engine process still carries the old 30-minute bound until its next restart.

Notes for review

  • A full-suite run of model_executor, scheduler or platform now holds four cards for as long as it runs, because those suites contain tests that declare four. Under the campaign-wide reservation every run held four for days.
  • A multi-GPU test that declares nothing (no cards_N, no num_cards=, no skip guard) still fails with one card; test_pixelumm_parallel.py is the one known. A marker in that repository's tests is the fix, not a change here.
  • A test an agent starts synchronously in run_shell still waits at most half of that tool call's timeout, which the harness sets.
  • SPEC pages updated with dated sections: testing.md, engine/steps/rebase_v3.md, rebase_engine.md.

…many as a command needs

The owner's rules of 2026-11-26: never give up on cards; never name cards,
ask for the number a command needs; no reserve. This implements the first
two in demand mode.

Wait. IMX_GPU_WAIT no longer has a default, so `gpu run` is given no
`--wait` and queues the command until it gets its cards. The runner's
timers and watchdog now start when the scheduler grants them
(`_await_grant` reads the side log once a second): timed from the spawn, a
command queued for two hours was killed by its own timeout in the queue.
The side log is cleared before the spawn, since a grant recorded by the
previous attempt would end this one's wait before it began. The log says
that a command is queued and, once granted, how long it waited. A refusal
is not a wait: the process exits and the log says `not run` as before.
The GPU lock keeps its bounded wait on purpose: a run holding it may sit
in the queue for hours, and an unbounded wait behind it would stall an
agent's session without a word.

Need. The module wrapper and the agents' run_pytest/reproduce asked for one
card, where every earlier cycle showed a module's tests four. A test that
needs more failed: tests/diffusion/models/hy_nomas/test_pixelumm_parallel.py
spawns 2 and 4 processes, with no cards_N marker and no guard. A command's
count is now what it needs: a cards_N in its own -m expression, else the
largest number declared by the tests it names at its run level, through a
cards_N mark or a decorator's num_cards=. Tests of another level do not
count; they skip by their own guard when the cards are not there. The
declaration is read with the ast module, because names inside strings are
not needs (the target repository's own tests quote CI commands that say
cards_8), and only test directories inside the repository root are walked:
a test whose root was `/` said `cd /tmp`, and the whole of /tmp was read.
The result is kept for five minutes, since agents edit tests as they work.

Cap. `tests/e2e --run-level advanced_model` declares eight cards: with an
unbounded wait such a command might never be served. IMX_GPU_MAX caps what
one command asks for; a test that declares more skips by its own guard, as
it did whenever four cards were visible. The launcher sets it to four.

Still bounded: a test an agent starts synchronously in run_shell waits at
most half of that tool call's timeout, which the harness sets.
command_gpus took the largest `cards_N` it could find in the whole command,
so `not cards_2` read as two cards. Seen in the running campaign: the
scheduler module's agent ran `tests/distributed/ -m 'core_model and cuda
and L4 and not cards_2'` and asked for two; the repository's own CPU job,
`core_model and cpu and not (cards_2 or ... or cards_8)`, would have asked
for eight.

The -m expression is now parsed: `not` applies to the term that follows it
or to a bracketed group. Counts it selects are the need; counts it negates
are left out of what the selected tests declare.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T03:00:50.071584Z 2ca822e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2ca822efcf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +721 to +723
# the queue lines are the runner's, not this attempt's evidence
try:
attempt_offset = log_file.stat().st_size

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve test output produced before the grant poll completes

In unbounded demand mode, the test starts running as soon as the scheduler grants its cards, but _await_grant can take another second to observe that grant. Resetting attempt_offset to the current log size therefore excludes actual test output, not just the runner's queue messages. A command that immediately prints CUDA out of memory and exits zero now returns rc=0, leaves watchdog_triggered=False, and creates a pass marker; I reproduced this with the scheduler stub. Keep the original attempt boundary or otherwise exclude only runner-generated messages so early fatal output remains visible to the watchdog.

Useful? React with 👍 / 👎.

Comment on lines 451 to +453
rc, wd_hit, timed_out = self._spawn(
self._command(job, job.command, side_log), job, run_env,
log_file, append=True)
log_file, append=True, queue=queue)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Apply grant-aware timing to the coverage fallback too

When pytest rejects --cov, the fallback calls _spawn without queue, even though _command wraps that retry in another unbounded scheduler request. Consequently, the retry's timeout starts while it is still waiting for cards, undoing the new behavior for installations without pytest-cov. With the scheduler stub, a two-second job whose fallback queues for four seconds returns timeout status 124 without executing the fallback test. Pass the queue information through the fallback path as well, including clearing the previous attempt's grant record.

Useful? React with 👍 / 👎.

command and its tests say, never the caller's `minimum`.
"""
command = command or ""
selected, excluded = _expression_cards(_option(_words(command), "-m") or "")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Parse pytest markers after the interpreter's module option

For python -m pytest ... -m 'core_model and cards_4', _option(..., '-m') returns pytest, so the explicit card selection and exclusions are ignored. These options have different meanings: python --help describes -m mod as “run library module as a script,” whereas pytest --help defines -m MARKEXPR as the test marker filter. This affects the module wrapper directly because module_pytest.main normally constructs commands beginning with python -m pytest; it can request cards for excluded tests or infer only one card when a different run level is selected through the marker expression. Parse the pytest argument segment rather than taking the first -m in the whole shell command, and use the same parsing in _run_level.

Useful? React with 👍 / 👎.

@tzhouam
tzhouam merged commit 7df7ca7 into main Nov 26, 2026
4 checks passed
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