Skip to content

[Bugfix][Examples] Handle zero NVLink matches without masking topology query errors - #438

Closed
0z5a wants to merge 2 commits into
vllm-project:0z5a-branchfrom
0z5a:fix/memagent-zero-nvlink
Closed

0z5a wants to merge 2 commits into
vllm-project:0z5a-branchfrom
0z5a:fix/memagent-zero-nvlink

Conversation

@0z5a

@0z5a 0z5a commented Sep 18, 2026 •

Copy link
Copy Markdown

Incremental review: Files changed.

Base: 0z5a-branch at 791f101e20db377b28e15f12a00863baaea2605f.

Allow a successful topology query with no NVLink matches under set -euo pipefail. The previous grep exit status aborted the launcher before it could export NCCL_NVLS_ENABLE=0.

Separate topology retrieval from counting. Report query failures, reject an empty matrix, and scope the empty-match handling to counting. The literal legend token NV# cannot match the numeric NVLink pattern.

Check Before Candidate
Isolated detector checks 6 failed, 3 passed 9 passed
bash -n — Passed
Existing docs / DP schedule checks — Passed

The checks source the real detector under set -euo pipefail and mock only nvidia-smi; launcher and cleanup functions are not invoked. This is a startup correctness fix, with no runtime speedup claim. Added tests and CI registration were removed.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the mem_agent_detect_nvlink function in examples/mem_agent/_common.sh to safely handle cases where nvidia-smi topo -m returns no matches or fails, preventing unexpected script aborts under set -euo pipefail. It also introduces a comprehensive suite of regression tests in tests/test_mem_agent_nvlink_detect.py. Feedback on the tests suggests adding dirname to the mocked tool path in _tool_path to ensure the test for a missing nvidia-smi command does not fail prematurely during the sourcing of _common.sh.

Comment thread tests/test_mem_agent_nvlink_detect.py Outdated
Comment on lines +86 to +89
for tool in ("grep", "wc"):
real = shutil.which(tool)
assert real is not None, f"{tool} is required to run these tests"
(bin_dir / tool).symlink_to(real)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In test_missing_nvidia_smi_is_not_reported_as_no_nvlink, with_nvidia_smi=False is passed to _tool_path. This returns a restricted PATH containing only grep and wc to simulate the absence of nvidia-smi.

However, when _common.sh is sourced (line 68 of CHILD_SCRIPT), it executes dirname on line 5:
MEM_AGENT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"

Since dirname is not in the restricted PATH, the sourcing of _common.sh fails immediately with a 'command not found' error. As a result, the test passes (since proc.returncode != 0), but for the wrong reason: it fails during sourcing due to a missing dirname command, rather than failing inside mem_agent_detect_nvlink due to a missing nvidia-smi command.

To fix this and ensure the test validates the actual behavior of mem_agent_detect_nvlink when nvidia-smi is missing, we should also symlink dirname in _tool_path.

Suggested change
for tool in ("grep", "wc"):
real = shutil.which(tool)
assert real is not None, f"{tool} is required to run these tests"
(bin_dir / tool).symlink_to(real)
for tool in ("grep", "wc", "dirname"):
real = shutil.which(tool)
assert real is not None, f"{tool} is required to run these tests"
(bin_dir / tool).symlink_to(real)

@read-the-docs-community

read-the-docs-community Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

@0z5a
0z5a force-pushed the fix/memagent-zero-nvlink branch 2 times, most recently from 8468f5e to e5fdf90 Compare September 18, 2026 20:26
@0z5a
0z5a changed the base branch from 0z5a-branch to main September 19, 2026 01:25
@0z5a
0z5a changed the base branch from main to 0z5a-branch September 19, 2026 06:03
@0z5a
0z5a force-pushed the fix/memagent-zero-nvlink branch from e5fdf90 to 0d2bf83 Compare September 24, 2026 05:54
…y query errors

mem_agent_detect_nvlink() ran the topology query and the match counting as one
pipeline under 'set -euo pipefail'. On a machine without NVLink the grep matches
nothing, exits 1, and pipefail therefore aborted the calling launcher instead of
exporting NCCL_NVLS_ENABLE=0; the '2>/dev/null' on the query also hid genuine
nvidia-smi failures, making both cases look identical from the outside.

Split the query from the counting: a successful query with zero matches is a
legal no-NVLink result and keeps setting NCCL_NVLS_ENABLE=0, while a failing or
empty query is reported on stderr and returns non-zero.

Adds tests/test_mem_agent_nvlink_detect.py, which drives the real _common.sh in
isolated bash subprocesses with only nvidia-smi mocked (cleanup and launcher are
never called). Covers pci-only, legend output, NVLink output, query failure,
empty output, a missing nvidia-smi, and a pre-set NCCL_NVLS_ENABLE.

Signed-off-by: 0z5a <0z5a@users.noreply.github.com>
Signed-off-by: 0z5a <dezhen.lu@student.uni-tuebingen.de>
@0z5a
0z5a force-pushed the fix/memagent-zero-nvlink branch from 0d2bf83 to 1c46441 Compare September 24, 2026 07:07
Signed-off-by: 0z5a <dezhen.lu@student.uni-tuebingen.de>
@0z5a

0z5a commented Oct 6, 2026

Copy link
Copy Markdown
Author

Superseded by #460, now merged into 0z5a-branch. The consolidated implementation and validation are retained there; closing this duplicate PR.

@0z5a 0z5a closed this Oct 6, 2026
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