Skip to content

fix: exit promptly on fatal GPU inference errors - #1685

Open
NorthCedar wants to merge 6 commits into
ModelTC:mainfrom
NorthCedar:fix/fatal-device-exit
Open

NorthCedar wants to merge 6 commits into
ModelTC:mainfrom
NorthCedar:fix/fatal-device-exit

Conversation

@NorthCedar

@NorthCedar NorthCedar commented Nov 10, 2026 •

Copy link
Copy Markdown

Fixes #1686 (fatal-error handling; the underlying GPU fault and supervisor restart/retry policy are separate).

Problem

Some CUDA/MUSA runtime errors leave the device context unusable and explicitly require terminating and relaunching the process. Treating these as ordinary request failures can reuse the failed context or block shutdown before a supervisor can recover the worker.

Checking only the outer inference worker is too late: runner exception branches may offload or fall back, profiler exits may synchronize or query device memory, and graph/stream/RNG contexts may run device cleanup while unwinding. An exception from a background copy or VAE thread may remain in a Future until another thread polls it. These paths can perform more device work before the original fatal error reaches the worker.

Change

Add a shared fatal-device-error classifier and termination helper in lightx2v/utils/inference_errors.py:

  • Match documented, restart-required CUDA/MUSA messages on the first line of a RuntimeError, including chained causes/contexts. OOM, generic ECC/unknown errors, broad NCCL wrappers, and near-matching text do not trigger termination unless an underlying exception matches.
  • Check at worker, runner, and profiling boundaries before cleanup, fallback, synchronization, or device context exit. Use direct exception checks for simple handlers and a shared guard where it simplifies nested contexts or suppression. Background workers check inside their own threads, before Future polling.
  • Exit the affected process with status 1. Emit bounded, best-effort error/frame diagnostics through an independently reopened nonblocking stderr descriptor, without changing sibling ranks' shared descriptor flags or waiting for logging to flush.
  • Preserve ordinary exception handling, return values, and cleanup. Adapt the checks to the upstream autoregressive runner lifecycle and decoder structure.

This applies to the touched inference/runner paths for both CUDA and MUSA. The message matching is deliberately conservative and text-based; an unrecognized error keeps its existing behavior. MUSA 5.2.0 runtime strings and explicit restart contracts were checked against the installed runtime/header, and torch_musa 2.9.1.post1+musa5.2.0 native and CUDA-compatible formatting was inspected: all 30 documented fatal MUSA codes match both prefixes, including AXI errors 796–798. OOM and ECC error 214 remain excluded.

A supervisor must restart the runtime after termination. No watchdog, inference timeout, or cancellation deadline is added. Calls that never raise remain outside this fix, and hardware faults may still require device/host recovery.

Testing

62 targeted CPU unittest tests passed, together with Ruff lint/format checks, Python compilation, and git diff --check.

  • Subprocess regressions cover 86 runner boundaries, context/stream/capture exit ordering, fallback and cleanup paths, background-thread failures, and ordinary exception types, return values, and actual cleanup side effects.
  • Mutation checks detect delayed exit, cleanup/fallback before exit (including inside an exception branch), and disabled background guards. An unrelated subprocess crash is not accepted as successful regression detection.
  • Five diagnostic regressions cover frame/cause reporting, shared stderr flags, a full pipe, regular-file append, and diagnostic failures.
  • An AST comparison against the upstream base passed for 28 modified production files after normalizing fatal checks/guards, unused exception bindings, and the shared sync/async profiler implementation.

A targeted integration overlaid only the shared helper and worker boundary on an existing four-rank MUSA runtime:

injected request failure observed result
Rank-1 RuntimeError("MUSA error: device-side assert triggered") Fatal handler exited that rank; torchrun signaled peers after ~0.39 s; the task supervisor marked the bound task failed after ~3 s
Runtime recovery after that fatal error Container restarted after ~58 s, with liveness-probe intervention; peer shutdown was not immediate
Ordinary ValueError through the same request path Request failed normally; runtime did not restart

No real GPU hardware fault was injected, and the complete upstream patch was not deployed in that integration. It does not validate upstream-specific runner paths or end-to-end Job Manager retries. The CPU tests validate control flow and process termination, not recovery from a physical device fault.

@ReadyDog ReadyDog 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.

Reviewed fatal exit ordering and reran all 52 targeted tests successfully. One remaining ordering gap is described inline; the existing tests do not cover failures from the RNG context itself.

— Codex review

Copy link
Copy Markdown

Updated the fatal whitelist using installed MUSA 5.2.0 driver_types.h restart contracts and actual musaGetErrorString results, including AXI codes 796/797/798. Verified torch_musa 2.9.1.post1+musa5.2.0 native and generated CUDA-compatible prefixes; all 30 confirmed fatal codes now match both. Removed unverified XID category names. Added real-exit subprocess cases and negative tests for OOM, ECC 214, old XID names, near matches, embedded text and non-RuntimeError exceptions. All 57 targeted tests passed, plus Ruff lint/format, Python compilation and diff checks. No real hardware fault injection or watchdog was introduced.

@NorthCedar
NorthCedar force-pushed the fix/fatal-device-exit branch from 4b3fbfa to 7689bdc Compare November 10, 2026 07:10
NorthCedar pushed a commit to NorthCedar/LightX2V that referenced this pull request Nov 16, 2026
Add per-rank CPU monitor processes, nested stage and request deadlines, and state-based health responses. Preserve fatal-device handling from PR ModelTC#1685 and leave idle keepalive out of scope.

Validation: 15 watchdog tests, 22 inference-error tests, and 40 fatal-error regression tests passed. Ruff, Python compilation, and diff checks passed. No target GPU runtime deployment or hardware fault validation performed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants