Skip to content

Fix the flaky test test_moe_eval_accuracy_large.py - #1326

Merged
merrymercy merged 1 commit into
mainfrom
merrymercy-patch-1
Sep 4, 2024
Merged

merrymercy merged 1 commit into
mainfrom
merrymercy-patch-1

Conversation

@merrymercy

Copy link
Copy Markdown
Collaborator

No description provided.

@merrymercy
merrymercy merged commit 843e63d into main Sep 4, 2024
@merrymercy
merrymercy deleted the merrymercy-patch-1 branch September 4, 2024 11:15
timethink pushed a commit to timethink/sglang that referenced this pull request Mar 9, 2025
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 12, 2026
…lf (W85, weg2xsn21b)

BOOT weg2xsn21b's flip killer, attributed from the two logs with numbers.
D rank 0, card GPU-31d7ef41-f574-4d0e-21ad-e773fd938f6d (the 5090), one flip
after LAUNCH, first D wake:

    16:06:26 TP0 WEG2-VRAM-CREDIT tag=weights_6 waited=526 ms
                 credit=2560 MiB requested=1906 MiB free_mib=3276  -> GRANTED
    16:06:26 TP0 W85 Weg2VramCreditAllocatableShort tag=weights_7
                 credit=2560 MiB requested=1906 MiB free_mib=1370  -> REFUSED
                 -> _weg2_leg_failed -> _weg2_group_fence
                 -> monitored_barrier 120 s -> SIGQUIT

THE COUNTING PROBE CLOSES WITH NO UNNAMED REMAINDER, which is what makes the
root a defect and not a hypothesis:

  * 3276 - 1906 = 1370. The free the refusal read is EXACTLY the free the
    grant one line above read, minus the bytes that grant then mapped. Nothing
    else on the card moved between them.
  * the whole 2560 MiB of credit is ONE peer release: P rank 0's `weights_4`
    (P log 16:06:27Z, 2560 MiB); its `weights_6`/`weights_7`/`weights_5` are
    0 MiB on that rank, so they published nothing.
  * the 1190 MiB "gap" between `credit=2560` and `free_mib=1370` is held by
    NOBODY. It is 1906 already-spent minus 716 MiB of card-free that was never
    credit (3276 - 2560). The predicted "shadow VRAM in no budget" (sgl-project#1326) is
    REFUTED by this arithmetic: there is no unbooked resident to find.

THE DEFECT. `VramCredit` had `publish` (S adds what a tag's pause freed) and
NOTHING that ever subtracted. `wait_for` graded every tag against the gross
`credit_bytes`, so one leg's released bytes funded EVERY tag of that leg in
turn -- a double-spend, tag after tag. The second consequence is the one that
killed the boot: because the spent credit still covered the request, the tag
was sent straight to sgl-project#1331's device check instead of back into the wait, and
was refused on a leg the peer was STILL FUNDING -- P's next release (2988 MiB)
landed about one second later, well inside the 120 s budget.

THE FIX, in the authority that already holds the credit (no second ledger):

  * `VramCredit.claim` is the debit half. Balance = credit_bytes -
    consumed_bytes; `begin_leg` resets both. `claims` beside `tags` so the file
    says who took what.
  * the grant runs INSIDE claim's exclusive lock, with the sgl-project#1331 device read as
    a gate between the decision and the write: a refused tag consumes nothing,
    and no claimant can slip between granting and debiting.
  * the early exit ("the card already holds the bytes") debits too, partially:
    it was the second route to the same wall, since on a co-located pair that
    free is largely the peer's just-released pages. A boot with no peer has an
    empty counter, claims 0, writes nothing and stays exactly as quiet as before.
  * before the W35 `leg_complete` refusal the card is asked ONCE MORE, and a
    card that holds the bytes is granted. Without it the debit would have bought
    the W85 fix with a new false W35 -- the refusal MOVED, not removed, which is
    the named danger direction of this slice.
  * W85/W35 messages and the WEG2-VRAM-CREDIT line now carry credit (unspent),
    published, consumed and available_after, so the double-spend is readable in
    the log instead of reconstructed from a free that fell by the request size.
    The line now also prints for a tag that claimed without waiting.

NOT DONE, deliberately: the corridor floor is untouched, no reserve is turned
up, W85 is not weakened. Those are the danger direction, and M2/M3 below are
the mutants that prove the tests see them.

TESTS. 12 new cases in test_weg2_flip_cost_1235.py::VramCreditTest, written on
the boot's own numbers (2560 / 1906 / 654 / 2988). LOCAL, HERMETIC, every run
under CUDA_VISIBLE_DEVICES="": 31/31 green in that class.

Three mutants, each run against the full class, baseline green after each:
  M1 balance = gross credit again (the defect restored)          -> 3 failed
  M2 the W85 device check removed (grant always)                 -> red
  M3 the late leg_complete re-read licenses unconditionally      -> red

ruff clean on all three files.

WHAT THE NEXT BOOT MUST PRINT, on the 5090's D rank 0 at the first wake:
two consecutive WEG2-VRAM-CREDIT lines whose `consumed=` RISES and whose
`credit=` FALLS by the previous request -- e.g. weights_6 credit=2560
consumed=1906 available_after=654, then weights_7 credit>=1906 only after a
further published= rise. A second line repeating `credit=2560` would mean the
debit did not land.
randgun pushed a commit to randgun/sglang that referenced this pull request Oct 13, 2026
…end 950 (sgl-project#1326)

* [NPU] Route DSV4 hc_pre through torch_npu mHC ops on Ascend 950

Ascend 950 (arch35) is the only SKU that ships the official torch_npu.npu_mhc_pre / npu_mhc_sinkhorn ops, so gate the hc_pre dispatch on is_npu_arch35(): only 950 switches over, while A2/A3 keep the cann-recipes custom.npu_hc_pre path unchanged.

npu_mhc_pre returns h_res before the Sinkhorn normalisation, so comb is produced by chaining npu_mhc_sinkhorn (the A2/A3 fused op does it inline).

* [NPU] Unify hc_pre arch dispatch behind a single call

The arch35 and legacy paths take identical arguments; pick the impl via a function alias and call it once instead of duplicating the arg list.

* [NPU] Drop redundant hc_pre arch wrapper; call is_npu_arch35() directly

The _npu_use_torch_npu_mhc() helper only wrapped a lazy import of is_npu_arch35(); inline it at the dispatch site.

* [NPU] Rename hc_pre dispatch alias to hc_pre_impl

impl was too generic; name it after what it holds (the selected hc_pre implementation).

* [NPU] Inline the hc_pre A3/A5 dispatch

For a static two-way arch branch, the separate _npu_hc_pre_arch35/_npu_hc_pre_custom helpers plus an alias were needless indirection. Inline both paths in npu_hc_pre with an early return, matching the neighbouring hc_post style.

* [NPU] Drop dead x_op reshape in hc_pre arch35 path

custom.npu_hc_pre TORCH_CHECKs x.dim() in {3,4}, and SGLang passes x through unchanged, so x is always 3D/4D and the 2-D reshape branch never runs. Pass x directly.
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