Skip to content

[MiniMax-M3.1] Step watchdog and GPU guard for Mono decode stalls - #3724

Draft
ganyi1996ppo wants to merge 1 commit into
ROCm:mainfrom
ganyi1996ppo:ganyi/step-watchdog-gpu-guard
Draft

ganyi1996ppo wants to merge 1 commit into
ROCm:mainfrom
ganyi1996ppo:ganyi/step-watchdog-gpu-guard

Conversation

@ganyi1996ppo

Copy link
Copy Markdown
Contributor

Motivation

Mono decode kernels are persistent: one CTA per CU, each holding the CU's whole LDS, spinning on each other and on the TP peers' mailbox pushes. Any other kernel that needs LDS on one CU of one TP GPU can keep a Mono CTA from launching, and then every rank spins until that kernel leaves. See #3369 (mailbox polling stalls next to concurrent copy kernels; the backoff in #3350 is a mitigation, the root cause is open).

One source of such kernels is another process on the same TP GPUs (e.g. a second server on double-leased GPUs). In a c8 benchmark run the engine thread sat blocked in one forward for ~212 s with no log line. This PR is a robustness and diagnostics change, not a speedup.

Change

  • atom/utils/gpu_guard.py (new): GpuGuard polls /sys/class/kfd/kfd/proc/*/vram_<gpu_id> (readable inside a container) for processes on the server's GPUs that were not there at engine start. While one is present, and for 5 s after the last one leaves (so a periodic neighbour does not flip steps between Mono and eager), EngineCore marks the batch mono_blocked (decided once on the engine, so all TP ranks agree) and decode stays off Mono; the runner runs such a step eagerly when a Mono-captured graph could replay it. The watched GPUs follow ROCR_VISIBLE_DEVICES / HIP_VISIBLE_DEVICES (else CUDA_VISIBLE_DEVICES); entries that are not indices, an empty list, or an unset variable (every GPU of the host is watched) are logged. On a host without KFD sysfs the guard sees nothing and says so.
  • EngineCore._timed_forward: every model forward (main loop, PP stages, decode-side engine) goes through it. It sets mono_blocked and publishes the step to a watchdog thread. A forward running past 5 s is logged with its kind (prefill / mixed / decode, "Mono off" when the guard blocked it) and the processes on the GPUs that are not the server's own; when it ends, the log reports how long it ran and counts long forwards per kind. Mono kernels only run in decode-only steps, so a long prefill or mixed forward is not read as a Mono stall.
  • MonoDecode: set_blocked() and the set of token counts captured with Mono, which the runner uses to decide when a blocked step must run eagerly.

No new environment variables. The thresholds (5 s watchdog, 5 s hold-off, 0.2 s guard poll) are constants in gpu_guard.py.

Evidence

  • A c8 run (900 s, MI355X TP4) with the guard and watchdog in: 12843 tok/s/GPU, request coverage 0.999, 0% errors, no engine gap over 5 s and no watchdog report. The same node and settings without the change: 12776 tok/s/GPU. The +0.5% is within run-to-run noise; the claim is only that nothing regresses when nothing stalls. (That run also carried an async-copy fence, which this PR no longer includes; the numbers are therefore indicative, not a measurement of this exact diff.) The p90 inter-token latency of that run was 286.7 vs 282.7 baseline, i.e. not better.
  • The Mono-off / eager fallback with a foreign process present was NOT run on a GPU. It is covered by the CPU unit tests below (guard on a fake KFD tree; the runner's eager decision on a stand-in model).
  • Step-kind naming came from a log scan: the stalls of >5 s seen in later runs (8K-32K token prefill forwards) were prefill-only steps with no Mono kernel in them, a different class (device memory running out in large prefill steps) that this PR does not claim to fix.
  • Unit tests (run on MI355X, no GPU kernel involved): 7 passed. The other tests that build an EngineCore / PPEngineCoreProc / MonoDecode stand-in (59 files) give the same results as main. Tests: tests/test_gpu_guard.py (fake KFD tree: GPU mapping, ROCR/UUID handling, newcomer reported then cleared, hold-off, other servers' GPUs not watched) and tests/test_step_watchdog_kind.py (step naming, _mono_blocked_step; skipped without torch).

Reproduce: python -m pytest tests/test_gpu_guard.py tests/test_step_watchdog_kind.py.

Numerics

Bit-identical when no foreign process is present: no kernel or tensor-value code is touched. While the guard blocks Mono, a step runs the model's existing non-Mono path, which is not bit-identical to the Mono kernels (fp32-order class, not verified on GPU); which steps those are depends on foreign-process timing. No GSM8K gate is claimed.

Notes for review

  • With none of ROCR_/HIP_/CUDA_VISIBLE_DEVICES set the guard watches every GPU of the host and says so; a sibling engine process that opens a GPU after this one started counts as foreign and keeps Mono off. Set the variable (as the launchers do) for a multi-server host.

  • The guard thread and the watchdog start in every EngineCore (all models); the guard only changes routing for a model with Mono hooks. A guard poll that raises is logged and retried.

  • The watchdog logs at ERROR for any forward over 5 s, including long prefills.

  • Applies to every model: the guard and watchdog live in EngineCore. For a model without Mono the guard has no effect on routing (the runner only acts on a model exposing the Mono hooks); the watchdog only logs.

  • Own processes are those on the GPUs when the engine finished starting; a process of this server that opens a watched GPU later (e.g. a profiler) counts as foreign. Host PIDs from KFD cannot be matched to the container's process tree, so descendants are not tracked.

  • Out of scope: a decision made mid-forward (a process arriving during a step affects the next step), and DP idle-rank dummy forwards that bypass _timed_forward.

🤖 Generated with Claude Code

A Mono decode kernel holds every CU of its GPU and its CTAs spin on the TP
peers, so any other kernel that needs a CU on one TP GPU can stall the whole
step until the GPU's queues are remapped.

- atom/utils/gpu_guard.py: poll KFD sysfs for processes on the server's GPUs
  that were not there at start; while one is present (and for a short hold-off
  after it leaves) the engine keeps decode off Mono, and runs a step eagerly
  when a Mono-captured graph could replay it.
- EngineCore: every model forward goes through _timed_forward, which hands the
  guard's verdict to the batch and lets a step watchdog report a forward
  running past 5 s with its kind (prefill / mixed / decode), the processes
  on the GPUs that are not the server's own, and a count of long forwards.
- MonoDecode: set_blocked() and the set of token counts captured with Mono.

Liveness only; numerics unchanged.
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every eligible PR before approval:

  • ✅ Pre Checkin: Black, Ruff, catalog schema validation, non-GPU unit tests

Heavy model tests:

  • ✅ Gate checks are published on every PR so required checks do not stay missing
  • ✅ Expensive jobs run only after the PR is approved, or when a matching ci:* label is present
  • ✅ Pre Checkin must pass before approved heavy jobs continue
  • ✅ Without a matching label, expensive jobs also require a relevant path
  • ✅ A matching ci:* label is an explicit request and can open the gate even when paths would otherwise skip it

Path scope:

  • Native ATOM, vLLM, and SGLang use ignore lists: docs/markdown and unrelated plugin or Mesh paths are skipped
  • ATOMesh uses an include list: Mesh code, ATOMesh scripts/workflows/catalogs, OpenAI entrypoints, and Slurm helpers
  • Relevant path alone does not start expensive jobs; approval still opens the automatic path-scoped gate
Label Tests
ci:full Run all heavy PR model tests: native ATOM, vLLM, SGLang, and ATOMesh
ci:atom Run native ATOM model accuracy tests
ci:vllm Run ATOM vLLM OOT model accuracy tests
ci:sglang Run ATOM SGLang model accuracy tests
ci:mesh Run ATOMesh accuracy/benchmark gates for Mesh-related changes

Without a matching ci:* label, heavy jobs are skipped when the path is not relevant or the PR is not approved.
Add labels via the sidebar or gh pr edit 3724 --add-label <label>

This branch has not been deployed

No deployments
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