Skip to content

[bug] Flash-Next NVFP4: shutdown exits before teardown finishes, and teardown hits ~147k invalid frees #122

Open

Description

@andrew-vogulkin

Status (updated 2026-10-01 20:10Z)

State: fix in draft #148. Cause (a) is verified on strix; cause (b) is waiting on a Flash-Next shutdown run.


Atlas version / docker tag

main at df051b35 (source build, ATLAS_TARGET_MODEL=qwen3.8-flash-next ATLAS_TARGET_QUANT=nvfp4)

Model

RadixArk/Qwen3.8-Flash-Next-NVFP4 (qwen4_exp)

Hardware

1× GB10 (DGX Spark), single-GPU

Launch command

spark serve /path/to/radixark-fn-nvfp4 --port 8890 --kernel-target qwen3.8-flash-next \
  --max-seq-len 8192 --kv-cache-dtype bf16 --gpu-memory-utilization 0.93 \
  --max-num-seqs 2 --max-batch-size 2
# then: three short greedy chat requests, then SIGTERM

Expected behaviour

On SIGTERM the server drains, Scheduler stopped follows a clean model.teardown(), and the process exits after that. Teardown frees what the model owns, with no invalid frees.

Actual behaviour

Two separate problems. Both reproduce on every run.

1. The process exits without waiting for teardown.

  • After serve() returns (Shutdown complete), main returns without joining the scheduler thread, so model.teardown() races process exit.
  • In four plain runs:
    • two exited with nothing logged after Shutdown complete;
    • two logged a teardown about 100 ms later with a sweep of only 2,151 allocations and no failures. That teardown was cut short by the exiting process: a complete one takes about 2.3 s (below).
  • So a normal shutdown never shows teardown's real result.
13:19:02.680874Z INFO spark::tui::shutdown: Shutdown requested (SIGTERM) — draining in-flight requests
13:19:02.680995Z INFO spark::tui::shutdown: Drain complete — no active requests
13:19:02.681023Z INFO spark::main_modules::serve_router: Shutdown complete
<process exit; no teardown or "Scheduler stopped" line>

2. When teardown does finish, it fails: about 147,400 invalid frees.

  • With a local-only 3 s pause added at the end of main (not committed), teardown always completes. It logs:
13:34:14.471716Z INFO  spark::main_modules::serve_router: Shutdown complete
13:34:15.823055Z WARN  spark_runtime::cuda_backend: sweep: cuMemFree failed for 0xfffa3dec8000: status 1
   … 147,444 such lines …
13:34:16.768984Z WARN  spark_model::model::types: teardown swept 149595 allocation(s) that no ModelResource released — they are reclaimed, but each one is memory whose owner is unaccounted for
13:34:16.768989Z ERROR spark::scheduler: model teardown reported a failure: ssm state pool: cuMemFree_v2 failed: status 1, ptr DevicePtr(0xffd785d00000); pointer restored to backend cleanup ledger
13:34:16.768995Z INFO  spark::scheduler: Scheduler stopped
  • The counts were identical across 3 runs: 149,595 swept, 147,444 failed with status 1 (invalid value).
  • Nearly everything the sweep finds is already invalid. Status 1 from cuMemFree means the pointer was already freed or isn't the base of an allocation.
  • Teardown records only its first error (ssm state pool), so failures from later steps (for example the weight store) are not reported.

Additional context

Activity

  1. AzeezIsh commented on Sep 28, 2026

    @AzeezIsh
    Contributor

    Both halves are covered by integration train #129: the exit race is #123 (join the scheduler before exit) and the invalid frees are #121 (WeightStore aliases go through reclaim). This issue closes when #129 lands, after its GB10 clean-shutdown check.

  2. AzeezIsh commented on Sep 28, 2026

    @AzeezIsh
    Contributor

    Update: the fixes now ride separate per-deployment trains. #121 (the invalid frees) is in #132 (GB10), and #123 (the exit race) is in #131 (HIP). I'll close this once both have landed and the GB10 clean-shutdown scan passes.

  3. andrew-vogulkin commented on Sep 28, 2026

    @andrew-vogulkin
    ContributorAuthor

    @AzeezIsh thanks for routing these. One correction before this closes: #121 covers only a small part of the invalid frees.

    From the GB10 before/after on #121 (#121 (comment)): Flash-Next NVFP4, main vs main + #121, 3 runs each. Counts were identical across runs.

    main main + #121
    sweep: cuMemFree failed … status 1 147,444 147,406
    teardown swept N allocation(s) 149,595 149,591
    First teardown failure ssm state pool: cuMemFree_v2 failed: status 1 same

    So once #121 and #123 land, part 2 of this issue is still open: Flash-Next NVFP4 teardown hits ~147k invalid frees and reports a failure.

    • It isn't root-caused yet. 147,444 ≈ 512 experts × 48 layers × 6 (147,456) points at the MoE unified-layout transpose ("originals freed"), but that's unconfirmed.
    • It matters for in-process hot-swap.

    Could this stay open, or be split into its own issue, until the GB10 clean-shutdown scan passes with both fixes in? We can run that scan on a train build if useful.

  4. AzeezIsh commented on Sep 29, 2026

    @AzeezIsh
    Contributor

    Correction: the "0 invalid frees" results I reported for #132 (625zzz3) and for #121 proved nothing. Main never reaches model teardown, so the teardown sweep that produces these warnings never ran.

    Reiner 639 compared main b03dc7363 (which has #121) with the HIP train at 56b3d6a05 (main plus #123), on the same 4 models:

    "scheduler joined; model torn down" sweep: cuMemFree failed lines
    main, Flash-Next 0 0 (the log ends at "Shutdown complete")
    train, Flash-Next 1 147,373
    train, 27B / Lightning / Qwen3.6 1 94 / 45 / 59

    What this shows:

    This issue stays open for the sweep double-frees. It's a teardown-only bug: the process is exiting anyway, and the pre-exit output is unaffected.

  5. AzeezIsh commented on Sep 29, 2026

    @AzeezIsh
    Contributor

    Diagnosis so far (main b2814e06e, reiner 653)

    1. Confirmed: the SsmStatePool teardown frees offset views. This produces the one ERROR model teardown reported a failure: ssm state pool: cuMemFree_v2 failed: status 1 on every model. alloc_layer_pools (model/ssm_pool.rs:147) allocates one contiguous block and returns base.offset(l * bytes) per layer. SsmStatePool::release then calls gpu.free on every entry of all six pools. Only layer 0 is a real allocation, so every other free returns status 1, and free() puts each rejected pointer back on the ledger, where the sweep fails on it again.

    The Marconi snapshot pool already handles this correctly: ssm_snapshot_teardown.rs frees h_blob_base and conv_blob_base, never the views. The fix is the same shape: keep the block base (or a contiguous flag) and free per layer only on the fallback path.

    2. Not yet located: Flash-Next's ~147k sweep failures.

    Model Swept Sweep frees that fail (status 1)
    Flash-Next NVFP4 149,524 147,374
    27B 1,307 95

    147,374 is about 48 layers × 256 experts × 12 per-expert tensors. So these are per-expert allocations that are still on the ledger but are no longer valid allocations: they were either freed through a path that bypasses GpuBackend::free/forget_alloc, or they are views that were restored to the ledger. WeightStore::release is not the cause, since it reported no error. Candidates to check next are the qwen4_exp MoE transpose orchestrator, which re-lays out expert weights, and WeightStore::reclaim.

    Impact: at process exit, memory is reclaimed either way, so nothing leaks. The cost is a false ERROR on every shutdown and the noise from 147k warnings. It is not a runtime correctness issue.

  6. AzeezIsh commented on Oct 1, 2026

    @AzeezIsh
    Contributor

    Root-caused. Fix in draft #148 (off main be435875c, unit-tested, not yet run on GB10).

    Two independent sources:

    1. SsmStatePool::release frees offset views. The 09-29 diagnosis was right. On strix, the 27B log has 282 failures = 6 MTP pool families × 47 non-base layers, with uniform address strides. That is every 27B failure. The pool now frees its real allocations only.
    2. The ~147k on Flash-Next is the unified MoE transpose plus WeightStore. Phase B/D of the transpose free each expert's original weights, which are store tensors, and WeightStore::release frees them again. 48 layers × 512 experts × 6 tensors = 147,456.
      • The 09-29 note "WeightStore::release is not the cause, since it reported no error" was mistaken. release_pools keeps only the first error, and that was always the SSM pool's, so the store's errors were never visible.
      • The transpose now returns what it freed, and callers mark it in the store. The qwen35 and laguna loaders had the same inline double free, so Qwen3.6-35B-A3B is covered too.

    Expected after #148: 0 sweep: cuMemFree failed lines and no model teardown reported a failure. Needs a GB10 Flash-Next shutdown run; reiner was unreachable at 06:40Z.

  7. maplepaladin73 commented on Oct 20, 2026

    @maplepaladin73
    Contributor

    Clean-shutdown check on current main: 0 invalid frees, and teardown completes before exit.

    This is the boot + SIGTERM run the status block was still waiting for, done on our GB10s.

    Build: main e29809db (includes #80, #131 and #148), built with the SparkQwen Dockerfile for qwen3.8-flash-next / nvfp4. Checkpoint: nvidia/Qwen3.8-Flash-Next-NVFP4. The original report used the RadixArk NVFP4 pack; this is the same qwen4_exp architecture.

    Each run: boot, three short greedy chat requests, then docker stop (SIGTERM, 120 s grace).

    TP=1, one GB10, the issue's launch (run 1) TP=1 (run 2) TP=EP=2, two GB10s, rank 0
    launch defaults, --max-seq-len 8192 --kv-cache-dtype bf16 --max-num-seqs 2 --max-batch-size 2, util 0.90 same our NVFP4 production profile, 6 × 262K, util 0.80
    Shutdown complete → scheduler joined; model torn down 5.35 s 5.40 s 3.09 s
    sweep: cuMemFree failed 0 0 0
    model teardown reported a failure 0 0 0
    teardown swept N allocation(s) (WARN, reclaimed) 2,160 2,160 6,969
    exit code / panics / ERROR lines 0 / 0 / 0 0 / 0 / 0 0 / 0 / 0

    So both halves of the issue look fixed on GB10:

    • The process waits for teardown: Scheduler stopped and scheduler joined; model torn down appear before exit, about 5 s after Shutdown complete at TP=1.
    • The ~147k invalid frees are gone (0 in every run).

    Two things left, if you want them tracked (neither is a failure):

    1. Teardown still sweeps 2,160 allocations at TP=1 (6,969 on rank 0 at TP=2) that no ModelResource released. They are reclaimed without error. The WARN text says each is memory with no accounted owner.
    2. At TP=2, rank 1 (the EP worker) logs EP worker stopped (rank 1) and then backend drop reclaimed 114040 allocation(s) that no owner released, with 0 free failures. The worker never runs model teardown, so all of its model memory goes through the backend drop.

    The full server logs from all three runs are available if useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions