Skip to content

Fix chatml template - #406

Merged
merrymercy merged 1 commit into
mainfrom
template
Apr 30, 2024
Merged

merrymercy merged 1 commit into
mainfrom
template

Conversation

@merrymercy

Copy link
Copy Markdown
Collaborator

No description provided.

@merrymercy
merrymercy merged commit ba67101 into main Apr 30, 2024
@merrymercy
merrymercy deleted the template branch April 30, 2024 22:53
timethink pushed a commit to timethink/sglang that referenced this pull request Mar 9, 2025
Hide-on-bushsh added a commit to Hide-on-bushsh/sgl-project that referenced this pull request Apr 22, 2026
efschu added a commit to efschu/htsglang that referenced this pull request Aug 2, 2026
The sgl-project#397 audit named two callers it could not reach: both passed a CUDA
ordinal straight into nvmlDeviceGetHandleByIndex. NVML enumerates in PCI bus
order, CUDA does not, and on this rig they disagree -- the RTX 5090 is NVML
index 1 and CUDA ordinal 0 -- so both read a card their caller was not asking
about. Neither was display-only.

barlink bar1_free sized the BAR1 receive window from the wrong card's free
aperture. That number is transport-load-bearing in both directions: too large
and the holder answers ENOMEM, too small and every message above the clipped
size drops to the gloo layer while the log still says transport=matrix. It now
resolves the card through the sgl-project#331 identity map, over the PCI address the
device itself reports and, when it has none, over the map's CUDA-ordinal side.
When neither route places the card there is a named DeviceOrderUnresolvedError
and the NVML read is SKIPPED: bar1_free reports "free unknown", which the
caller already handles and states in its arithmetic, instead of another card's
free bytes, which it cannot detect. The refusal is logged at warning level, not
swallowed into the function's debug path.

utils/common min_visible_cuda_capability_no_init indexed the NVML-ordered
device list with a CUDA_VISIBLE_DEVICES entry, and it feeds Triton constexpr
and JIT-backend selection for the whole process. _nvml_cuda_device0, twenty
lines below, already emulated the enumeration order correctly; that emulation
is now a shared helper (_nvml_devices_in_cuda_order) rather than a second,
wrong answer to the same question. Where FASTEST_FIRST leaves a position
unspecified -- past device 0 on a mixed rig -- the answer is the floor over
every card NVML reports, not an error: this is a MINIMUM, the floor over a
superset can only be lower than the true floor, and low forgoes an
optimization while high arms a variant a card cannot launch. The neighbouring
_nvml_cuda_device0 still refuses the same input, because it is asked for the
identity of a card rather than a bound over them.

Tests, the sgl-project#392 falsifier pattern, injected NVML/CUDA orders, no driver:

  test_bar1_card_identity_406.py            12 tests, OK
  test_min_visible_capability_device_order_406.py  14 tests, OK

Both pin the exact pre-fix answer. Reverting each fix in place turns exactly
the divergence cases red and leaves the control rigs green:

  bar1_free with the ordinal restored: 4 red -- 240 MiB free read off the
  3080 where the 5090 has 100, and window_for handing out the full 96 MiB
  request on a card that has 68 MiB to give.
  min_visible with the NVML list restored: 4 red -- CUDA_VISIBLE_DEVICES=0
  answering sm86 for the 5090, and CUDA_VISIBLE_DEVICES=1 answering sm120
  for a 3080, which is the dangerous direction.

Regression, all green: test_per_device_capability (21),
test_cuda_context_free_imports (16), test_device_order_bridges_397 (26),
test_budget_guard_device_order_392 (13), test_barlink_transport_seam (17).
ruff and codespell clean on the four files (common.py's five ruff findings are
pre-existing lines outside the change).

Sibling audit of the barlink transport files: bar1_free held the only NVML
handle acquisition in barlink.py, barlink_matrix.py, barlink_bar1.py and
barlink_matrix_transport.py. The one other NVML-by-index in
device_communicators is upstream custom_all_reduce_utils.is_full_nvlink, which
treats CUDA_VISIBLE_DEVICES entries as NVML indices -- the same question, in
upstream code and out of this task's scope.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 2, 2026
…rough IdentityMap (PCI-BDF first — the identity that survives CUDA_VISIBLE_DEVICES — cuda-ordinal second; unresolvable = named error, and the NVML read degrades to the existing free-unknown contract because a wrong-card free value is UNDETECTABLE while sysfs-gross still answers); min_visible_cuda_capability reuses the adjacent correct enumeration and indexes CVD entries against the CUDA-ordered list, unresolvable = conservative floor over every card (a minimum over a superset can only be lower; too high arms a variant the card cannot launch — the can-fail reproduced exactly that: sm120 armed for a 3080); can-fail proofs 4+4 red on reverted fixes incl. a BAR1 window the hosting card cannot hold; barlink sibling audit: bar1_free was the ONLY NVML acquisition across the four transport files; upstream sibling recorded not touched (custom_all_reduce_utils.is_full_nvlink treats CVD entries as NVML indices — foreign code, NVLink-less rig) (sgl-project#406)
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 31, 2026
…ys so

Boot 24's 774 MiB -> 21.69 MiB gap had a live alternative explanation: a guard
reading a FOREIGN card for its rank (the sgl-project#392/sgl-project#406/sgl-project#589 device-order family).
Settled on the LIVE boot 25 rather than by reading code, because the code alone
cannot answer it -- `torch.cuda.mem_get_info(self.device_index)` is correct or
catastrophic depending on what the process can see.

MEASURED: every rank process carries CUDA_VISIBLE_DEVICES set to a SINGLE GPU
UUID (PP0 -> GPU-31d7ef41 = the 5090, PP1 -> GPU-5c648f96, PP2 ->
GPU-62dbbae1), cross-checked against nvidia-smi's per-PID compute-apps list,
which shows that same pid holding 30996 MiB on that UUID. So torch sees exactly
one device per process and index 0 IS that process's own card. Isolation is at
the process level -- the canonical form -- not an in-process index map.

CONSEQUENCE, and it is why this is worth a commit rather than a note: "cleared
on device 0" appears on PP0 AND PP2 and is correct on both, because they are
different physical cards. The number is PROCESS-LOCAL and reads as if it were
physical. Anyone diffing those lines across ranks would conclude two ranks
share a card. Annotated at the reading site so the next reader does not
re-open the question.

RULED OUT, explicitly: the guard is not reading a foreign card. The 774 -> 21.69
MiB gap is a REAL transient spike between the two readings, not a wrong-card
artifact, and the memory campaign proceeds on that basis.

EVIDENCE TIER: BOOT-PROVEN (live process environments + NVML per-PID, boot 25).
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