-
Notifications
You must be signed in to change notification settings - Fork 18
fix(customizer): fix 500 on validation failure for automodel, busybox default #922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e59372d
fix(customizer): fix 500 on validation failure for automodel, choose …
soluwalana 62eb289
Merge branch 'main' into solu/500-on-validation
soluwalana c64115f
lint fix
soluwalana 38b8a80
Add fix for nccl on oci cluster
soluwalana e21bc92
simplify nccl line
soluwalana 6731310
resolve code rabbit comments
soluwalana 988fafd
Fix backend.py
soluwalana d924082
Merge branch 'main' into solu/500-on-validation
soluwalana 420a9b3
Remove duplcate test
soluwalana 7cbe3c6
Merge branch 'main' into solu/500-on-validation
soluwalana 13ba98f
Merge branch 'main' into solu/500-on-validation
soluwalana 1fd00f4
Merge branch 'main' into solu/500-on-validation
soluwalana File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
packages/nmp_customization_common/src/nmp/customization_common/training/nccl.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """NCCL environment helpers shared by customization training backends.""" | ||
|
|
||
| import logging | ||
| import os | ||
| from pathlib import Path | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| _IB_SYSFS = Path("/sys/class/infiniband") | ||
|
|
||
|
|
||
| def get_nccl_ib_env() -> dict[str, str]: | ||
| """Return NCCL overrides when Mellanox HCAs lack network devices.""" | ||
| if os.environ.get("NCCL_IB_HCA") or os.environ.get("NCCL_IB_DISABLE") or not _IB_SYSFS.is_dir(): | ||
| return {} | ||
|
|
||
| usable: list[str] = [] | ||
| phantom: list[str] = [] | ||
| try: | ||
| hcas = sorted(path for path in _IB_SYSFS.iterdir() if path.is_dir()) | ||
| except OSError: | ||
| return {} | ||
|
|
||
| for hca in hcas: | ||
| if not hca.name.startswith("mlx"): | ||
| continue | ||
| try: | ||
| has_netdev = any((hca / "device" / "net").iterdir()) | ||
| except OSError: | ||
| has_netdev = False | ||
| if has_netdev: | ||
| usable.append(hca.name) | ||
| else: | ||
| phantom.append(hca.name) | ||
|
|
||
| if not phantom: | ||
| return {} | ||
|
|
||
| if not usable: | ||
| logger.info("Disabling NCCL IB because all detected Mellanox HCAs lack network devices") | ||
| return {"NCCL_IB_DISABLE": "1"} | ||
|
|
||
| hca_filter = ",".join(f"={hca}" for hca in usable) | ||
| logger.info("Setting NCCL_IB_HCA=%s (excluded phantom HCAs: %s)", hca_filter, ",".join(phantom)) | ||
| return {"NCCL_IB_HCA": hca_filter} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import os | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| from nmp.customization_common.training import nccl as nccl_module | ||
| from nmp.customization_common.training.nccl import get_nccl_ib_env | ||
|
|
||
|
|
||
| def _make_hca(ib_root: Path, name: str, with_netdev: bool = False) -> None: | ||
| net = ib_root / name / "device" / "net" | ||
| net.mkdir(parents=True) | ||
| if with_netdev: | ||
| (net / "eth0").mkdir() | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def ib_sysfs(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path: | ||
| ib = tmp_path / "infiniband" | ||
| ib.mkdir() | ||
| monkeypatch.setattr(nccl_module, "_IB_SYSFS", ib) | ||
| monkeypatch.delenv("NCCL_IB_HCA", raising=False) | ||
| monkeypatch.delenv("NCCL_IB_DISABLE", raising=False) | ||
| return ib | ||
|
|
||
|
|
||
| def test_returns_exact_usable_hcas_when_phantoms_exist(ib_sysfs: Path) -> None: | ||
| _make_hca(ib_sysfs, "mlx5_1", with_netdev=True) | ||
| _make_hca(ib_sysfs, "mlx5_10", with_netdev=True) | ||
| _make_hca(ib_sysfs, "mlx5_2") | ||
|
|
||
| assert get_nccl_ib_env() == {"NCCL_IB_HCA": "=mlx5_1,=mlx5_10"} | ||
| assert "NCCL_IB_HCA" not in os.environ | ||
|
|
||
|
|
||
| def test_disables_ib_when_all_hcas_are_phantom(ib_sysfs: Path) -> None: | ||
| _make_hca(ib_sysfs, "mlx5_0") | ||
| _make_hca(ib_sysfs, "mlx5_1") | ||
|
|
||
| assert get_nccl_ib_env() == {"NCCL_IB_DISABLE": "1"} | ||
|
|
||
|
|
||
| def test_returns_no_overrides_without_phantoms(ib_sysfs: Path) -> None: | ||
| _make_hca(ib_sysfs, "mlx5_0", with_netdev=True) | ||
|
|
||
| assert get_nccl_ib_env() == {} | ||
|
|
||
|
|
||
| def test_respects_existing_nccl_configuration(ib_sysfs: Path, monkeypatch: pytest.MonkeyPatch) -> None: | ||
| _make_hca(ib_sysfs, "mlx5_0") | ||
| monkeypatch.setenv("NCCL_IB_HCA", "mlx5_custom") | ||
|
|
||
| assert get_nccl_ib_env() == {} |
57 changes: 57 additions & 0 deletions
57
packages/nmp_customization_common/tests/training/test_nccl.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import os | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| from nmp.customization_common.training import nccl as nccl_mod | ||
| from nmp.customization_common.training.nccl import maybe_set_nccl_ib_hca | ||
|
|
||
|
|
||
| def _make_hca(ib_root: Path, name: str, with_netdev: bool = False) -> None: | ||
| device = ib_root / name / "device" | ||
| net = device / "net" | ||
| net.mkdir(parents=True) | ||
| if with_netdev: | ||
| (net / "eth0").mkdir() | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def ib_sysfs(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path: | ||
| ib = tmp_path / "infiniband" | ||
| ib.mkdir() | ||
| monkeypatch.setattr(nccl_mod, "_IB_SYSFS", ib) | ||
| monkeypatch.delenv("NCCL_IB_HCA", raising=False) | ||
| return ib | ||
|
|
||
|
|
||
| def test_sets_nccl_ib_hca_when_phantoms_exist(ib_sysfs: Path) -> None: | ||
| _make_hca(ib_sysfs, "mlx5_0", with_netdev=True) | ||
| _make_hca(ib_sysfs, "mlx5_1", with_netdev=False) | ||
|
|
||
| maybe_set_nccl_ib_hca() | ||
| assert os.environ["NCCL_IB_HCA"] == "mlx5_0" | ||
|
|
||
|
|
||
| def test_noop_without_phantoms(ib_sysfs: Path) -> None: | ||
| _make_hca(ib_sysfs, "mlx5_0", with_netdev=True) | ||
|
|
||
| maybe_set_nccl_ib_hca() | ||
| assert "NCCL_IB_HCA" not in os.environ | ||
|
|
||
|
|
||
| def test_noop_without_ib(ib_sysfs: Path) -> None: | ||
| ib_sysfs.rmdir() | ||
|
|
||
| maybe_set_nccl_ib_hca() | ||
| assert "NCCL_IB_HCA" not in os.environ | ||
|
|
||
|
|
||
| def test_respects_existing_value(ib_sysfs: Path, monkeypatch: pytest.MonkeyPatch) -> None: | ||
| _make_hca(ib_sysfs, "mlx5_0", with_netdev=True) | ||
| _make_hca(ib_sysfs, "mlx5_1", with_netdev=False) | ||
| monkeypatch.setenv("NCCL_IB_HCA", "mlx5_custom") | ||
|
|
||
| maybe_set_nccl_ib_hca() | ||
| assert os.environ["NCCL_IB_HCA"] == "mlx5_custom" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.