Skip to content

deepseek: fail fast on a lost CUDA context and on stalled engine operations - #1646

Merged
ashhart merged 7 commits into
ashhart:mainfrom
jayleaton:dsv41-up/supervision
Oct 30, 2026
Merged

ashhart merged 7 commits into
ashhart:mainfrom
jayleaton:dsv41-up/supervision

Conversation

@jayleaton

@jayleaton jayleaton commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

On TP=2, a sticky CUDA context fault or a wedged operation left the DeepSeek-V4.1 server up but unable to answer. Peers waited, and nothing reached the existing fail-fast channel until an HTTP health poll. This adds supervision on top of the existing Fate and fail-fast contract. Each piece is its own commit:

commit what it supervises
fail fast when CUDA context health is lost A host monitor, owned from TP start through teardown. It sends a sticky context fault to fail-fast once, without waiting for a health poll.
supervise stalled owned engine operations An owned progress watchdog, default off, in core/lane_activity.zig. On a stall it withdraws readiness and hands off a fatal error.
exit without synchronous abort when fate is disabled With TF_TP_FAILFAST off, the callback exits directly (status 70) instead of waiting on communicator teardown (the old status 71 path).
supervise blocked session snapshots An owned progress scope around snapshot synchronization, which notifies before a partial publication.
supervise blocked KV union synchronization The same for the KV union/glue synchronization; tables stay unchanged.
attach supervision hooks only where they apply Review follow-up: no progress pointers or activity hooks without the watchdog, the fatal-error handoff only under fail-fast, LaneHost.words a plain lookup again, and a failed boot joins the supervisor before the session closes.

Defaults:

  • Stall watchdog: off unless TF_DSV41_STALL_EXIT_S is non-zero. When it is off, the runner, the follower and the lane host get no progress pointer and no activity hooks, so a launch costs one null check.
  • Fatal-error handoff: only under fail-fast. It is attached only when the TP session has a Fate, which TF_TP_FAILFAST (default on) provides. There, a lockstep-fatal round error (CudaFailed, OutOfMemory, Timeout, …) takes every rank down through Fate, because the ranks cannot resynchronize after one. With TF_TP_FAILFAST=0 it is not attached: the round's requests fail and the server keeps serving, as before.
  • Context monitor: always on. A sticky CUDA context fault goes to Fate. Without a Fate the process exits with status 70, since the context cannot serve again (commit 3).

The shared core gains lane_activity: a progress scope a family can own and a failure hook. The lane host calls the hook where a round or request fails. LaneHost.words stays a plain lookup, and failAll still gives every stream the error's name. Rounds, scheduling and verification stay in the lane core as they are.

Issue: none open upstream. Reported downstream by justonehe and ilonalumina, eduffd, Jenpo, and tanchunsiong (jayleaton/deepseek-v41-tensorfold-spark#31, #59, #38, #64). Stacked on: nothing (based on main 3f0a715c4; the 28 later main commits, to f350cd3ea, touch none of its files).

Receipt

  • Environment, with the TensorFold commit, MLX or PyTorch version, machine and GPU, checkpoint and revision: head 879f2d1b4b21 on main 3f0a715c4; Zig 0.17.0. Host checks for the review follow-up on Linux x86_64 (no GPU); the earlier commits' host checks ran on a Linux aarch64 DGX Spark (GB10, CUDA 13.0). Real-pack boot on two GB10s, TP=2 over RoCE, checkpoint jayleaton/DeepSeek-V4.1-Flash-1017-EXL3-2.8bpw revision 859396591c34, TF_EXPERIMENTAL=deepseek.

  • Exactness: n/a; no arithmetic or token path changes, and the watchdog is off by default.

  • Decode speed before and after: n/a. With the watchdog off, the hot path's only addition is one null check per launch; no progress state is read or written.

  • Prompt speed before and after: n/a, for the same reason.

  • Host regressions:

    • Each rank gets exactly one notification, detected from an independent thread, with a joined shutdown.
    • Blocked work stalls, while healthy idle or advancing work does not.
    • A fault fixture blocks the real snapshot synchronization call and the real union synchronization driver call, then checks a fresh synchronization.
    • The production callback child, with Fate off, recorded status 71 before the fix and records 70 after it.
    • Review follow-up:
      • Watchdog off and no Fate: no progress pointer, activity hook or failure hook is attached, and CudaFailed reaches nothing. It fails with the gating reverted.
      • Watchdog on with a Fate: attached, and only lockstep-fatal errors are reported. This is a positive control.
      • A failed lane round reaches the failure hook while its stream keeps the error's name, even with a family explain. With failAll(h.words(e)) restored, it fails with "a family's words".
      • bootAborted has joined the supervisor before the session step. It fails with the old order.
  • These are bounded recovery checks. They do not establish the cause of any GPU or distributed wedge.

  • Tests run, with pass, fail and skip counts:

    review follow-up at 879f2d1b4 (Linux x86_64 host):
    zig fmt --check (changed files)                    exit 0
    git diff --check c2c0108d3..HEAD                    exit 0
    python3 tools/zig/lean_check.py                     base 425 problems, head 425, new 0 (lean_new.py)
    zig build                                           exit 0
    zig build test-dsv41-shared test-dsv41-state test-dsv41-forward test-dsv41-kv test-dsv41-device-host test-dsv41-draft test-dsv41-cuda-host test-draft-dsv41-host test-tp test-tp-fate-host  all success (device-host 159/159, draft 104/104)
    zig build test-lane-api-host test-lane-lone-host test-lane-halt-host test-lane-interrupted-host  12/12 steps, 76/76 tests
    core engine_api tests (lane host, including lane_host_fail_test's "GpuFailed" message)  406/406
    zig build test-cuda-host --summary all              270/270 steps, 960/960 and 972/972 tests on the last three runs
    

    test-cuda-host note: under a loaded build runner, keepalive_test sometimes ended early. It failed in 4 of 8 head runs, all early in the session; the last four passed, and the same binary passed 871/871 run alone. It failed in 0 of 3 runs on c2c0108d3. The test ends through serve's shutdown path, which exits when client connections are still open after 2 s, and this PR does not change that path.

    earlier commits, at c2c0108 (DGX Spark):

    zig build test-cuda-host --summary all              exit 0, 271/271 steps, 3909/3918 tests passed, 9 skipped (with test-server-cpu)
    zig build test-dsv41-shared test-dsv41-state test-dsv41-forward test-dsv41-kv test-dsv41-device-host test-dsv41-draft test-dsv41-cuda-host test-draft-dsv41-host test-tp test-tp-fate-host  exit 0, 86/86 steps, 689/692 tests passed, 3 skipped
    
  • Real-pack TP=2 boot of main + every PR in this series (and the DeepSeek image path that is not yet proposed), at 83ba53298924: passed. Both ranks reached readiness; the recipe smoke, the canary and a strict tool call passed; MissingTritonVariant 0 in both rank logs; 2048 greedy tokens in 51.1 s with token_sha256 7538b20557b1…, the same as the downstream build of this series. The boot runs with the context monitor in place.

  • Not run, and why: Metal (it compiles only lane_activity; the host tests are CUDA-family); injecting a real GPU fault.

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Not measured for this change alone.)
  • No precision traded for speed. If the bits change, the description says which sums change and why.
  • A new or changed GPU kernel is registered with the kernel contract (docs/kernel-contract.md); each backend's SUMMARY line is in the receipt. (No kernel changes.)
  • Prompt processing is no slower than the last release. (The watchdog is off by default.)
  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. (The Fate-off callback test records 71 before the fix and 70 after, and three of the review follow-up's tests fail with their fixes reverted, the fourth being a positive control; the earlier stall tests had no reverted-fix control.)
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths. No AI attribution lines.

@ashhart

ashhart commented Oct 30, 2026

Copy link
Copy Markdown
Owner

Thanks for this. It's a careful series, and the host fixtures that block the real snapshot and union synchronization calls are a nice way to test it. There are a few things to change before we can take it:

  1. The watchdog is off by default, but the hot path still runs it. Runner.issue now calls progress.touch() after every launch, which reads the clock and takes the spin lock. m.runner.progress, m.f.progress and the lane host's begin/end activity hooks are attached whether or not TF_DSV41_STALL_EXIT_S is set. When the timeout is 0 nothing reads that state, so please attach the progress pointers and activity hooks only when the timeout is non-zero. The default path then costs one null check per launch, and no speed measurement is needed. If you'd rather keep them always on, we'd need decode and prompt timings before and after at 1 and 4 streams on TP=2, showing no slowdown.

  2. The fatal-error handoff is on by default. Through executionFailed, any error in the lockstep fatal list that reaches the lane host now exits the process with status 70. That includes CudaFailed, OutOfMemory and Timeout, and it applies with TF_TP_FAILFAST=0 and when there is no Fate. Before, the round's requests failed and the server kept serving. That may be right for TP=2, since the ranks can't resync after those errors. But the description says serving is unchanged until the watchdog is enabled. Please either say in the description that this part is on by default and why that is safe when there is no Fate, or limit the exit to the cases where fail-fast applies.

  3. LaneHost.words is shared by every family. It now has a side effect: it calls activity.failed. failAll now passes h.words(e) instead of @errorName(e), so other CUDA families that set explain change the message every stream gets when a round fails. Could you keep words a plain lookup and call the failure hook explicitly where a round or request fails? failAll's message would then stay as it is for the other families.

  4. A small one: in Model.open, when boot fails, bootFailed closes the session before the errdefer joins the supervisor thread. That thread can still call model_health.failed and read m.session.fate. Stopping the supervisor before bootFailed, as close() already does, would remove that window.

Once these are in, we'll rerun our checks and take it. Thanks again for tracking these reports down.

jayleaton added a commit to jayleaton/TensorFold that referenced this pull request Oct 30, 2026
Address the review on ashhart#1646. The runner, follower and lane host get the progress scopes only when TF_DSV41_STALL_EXIT_S is non-zero, so the default path costs one null check per launch. Lockstep-fatal round errors reach the supervisor only when a Fate exists (TP fail-fast on); with TF_TP_FAILFAST=0 the round's requests fail and the server keeps serving, as before. LaneHost.words is a plain lookup again: a separate failure hook is called where a round or request fails, and failAll keeps the error's name for every family. A failed boot joins the supervisor before bootFailed closes the session it reads.
@jayleaton

Copy link
Copy Markdown
Contributor Author

Thanks. All four are in 879f2d1:

  1. The runner, follower and lane host get the progress pointers and activity hooks only when TF_DSV41_STALL_EXIT_S is non-zero; at the default, each launch costs one null check.
  2. The fatal-error handoff is attached only when the session has a Fate. With TF_TP_FAILFAST=0 the round's requests fail and the server keeps serving, as before. The description now spells out each default.
  3. LaneHost.words is a plain lookup again. A separate failure hook is called where a round or request fails, and failAll passes @errorName(e) again, so other families' messages are unchanged.
  4. A failed boot now goes through bootAborted, which joins the supervisor before bootFailed closes the session.

Each change has a host test. Three of them fail with their fix reverted; the fourth (watchdog on with a Fate) is a positive control. The receipt in the description is updated.

jayleaton and others added 7 commits October 30, 2026 23:20
Own a host monitor from TP startup through model teardown so a sticky context fault reaches the existing fail-fast channel without waiting for an HTTP health poll. Readiness and admission already observe the published context fault before notification.

Host regressions cover each rank, once-only notification, independent thread detection and joined shutdown. This addresses justonehe’s issue jayleaton/deepseek-v41-tensorfold-spark#31 recovery report and ilonalumina’s additional rank-specific incidents; the original kernel fault remains unqualified.

(cherry picked from commit fe07080)
Address eduffd's issue jayleaton/deepseek-v41-tensorfold-spark#59 with an owned progress watchdog, default off, readiness withdrawal and fatal-error handoff. Host fixtures exercise blocked work and healthy idle or advancing work. This does not establish the cause of a GPU or distributed wedge.

(cherry picked from commit 53033f7)
Complete the sticky-error fail-fast contract from justonehe and ilonalumina's issue jayleaton/deepseek-v41-tensorfold-spark#31. Notify an existing Fate directly, or exit without waiting on communicator teardown when TF_TP_FAILFAST is off. The actual model callback child test records the old synchronous abort path as status 71 and requires direct status 70 after correction; generic TP behavior is unchanged.

(cherry picked from commit 5368c7a)
Address Jenpo's issue jayleaton/deepseek-v41-tensorfold-spark#38 recovery contract through an owned snapshot progress scope. The host fault fixture blocks the actual snapshot synchronization call and proves independent stall notification before partial publication, then checks a fresh synchronization. This is a bounded recovery check, not proof of the original GPU stall cause.

(cherry picked from commit aee5011)
Address tanchunsiong's issue jayleaton/deepseek-v41-tensorfold-spark#64 recovery contract through an owned KV union progress scope. Exercise the actual union/glue synchronization path with a host-only blocked driver call and verify independent failure notification and unchanged tables. Distributed kernel and transport causes still require pair traces.

(cherry picked from commit d6dbc87)
Address the review on ashhart#1646. The runner, follower and lane host get the progress scopes only when TF_DSV41_STALL_EXIT_S is non-zero, so the default path costs one null check per launch. Lockstep-fatal round errors reach the supervisor only when a Fate exists (TP fail-fast on); with TF_TP_FAILFAST=0 the round's requests fail and the server keeps serving, as before. LaneHost.words is a plain lookup again: a separate failure hook is called where a round or request fails, and failAll keeps the error's name for every family. A failed boot joins the supervisor before bootFailed closes the session it reads.
@ashhart
ashhart force-pushed the dsv41-up/supervision branch from 879f2d1 to d7e3a7f Compare October 30, 2026 23:20
@ashhart
ashhart merged commit 19372fb into ashhart:main Oct 30, 2026
7 of 9 checks passed
ashhart pushed a commit that referenced this pull request Oct 30, 2026
Address the review on #1646. The runner, follower and lane host get the progress scopes only when TF_DSV41_STALL_EXIT_S is non-zero, so the default path costs one null check per launch. Lockstep-fatal round errors reach the supervisor only when a Fate exists (TP fail-fast on); with TF_TP_FAILFAST=0 the round's requests fail and the server keeps serving, as before. LaneHost.words is a plain lookup again: a separate failure hook is called where a round or request fails, and failAll keeps the error's name for every family. A failed boot joins the supervisor before bootFailed closes the session it reads.
ashhart added a commit that referenced this pull request Oct 31, 2026
…ig under 600 lines

#1327 and #1646 each added lines to lane_host.zig, and together they took it to 604.
The function moves unchanged.
@ashhart

ashhart commented Oct 31, 2026

Copy link
Copy Markdown
Owner

Thank you @jayleaton. This is in TensorFold 1.2.0, released today: https://github.com/ashhart/TensorFold/releases/tag/v1.2.0

It landed with your commits under your own name, so you're listed as a TensorFold contributor, and it's credited to you in the release notes and the changelog.

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.

2 participants