-
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 4 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
44 changes: 44 additions & 0 deletions
44
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,44 @@ | ||
| # 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 maybe_set_nccl_ib_hca() -> None: | ||
| """Set NCCL_IB_HCA to usable Mellanox HCAs when phantom devices are present. | ||
|
|
||
| Some hosts expose mlx InfiniBand devices in sysfs that have no netdev. NCCL | ||
| will try those and fail; filter them out when that happens. | ||
| """ | ||
| if os.environ.get("NCCL_IB_HCA") or not _IB_SYSFS.is_dir(): | ||
| return | ||
|
|
||
| usable: list[str] = [] | ||
| phantom: list[str] = [] | ||
| try: | ||
| hcas = sorted(p for p in _IB_SYSFS.iterdir() if p.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 | ||
| (usable if has_netdev else phantom).append(hca.name) | ||
|
|
||
| if not usable or not phantom: | ||
| return | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| os.environ["NCCL_IB_HCA"] = ",".join(usable) | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| logger.info("Setting NCCL_IB_HCA=%s (excluded phantom HCAs: %s)", os.environ["NCCL_IB_HCA"], ",".join(phantom)) | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
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
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,64 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Tests for AutomodelJob.compile error mapping. | ||
|
|
||
| ``validate_for_training`` rejects inconsistent parallelism/batch topologies. | ||
| Those are user input errors, so they have to leave ``compile`` as | ||
| ``PlatformJobCompilationError`` — the api_factory only maps that type to a | ||
| 422, and anything else escapes as a 500. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import asyncio | ||
| from typing import Any | ||
| from unittest.mock import patch | ||
|
|
||
| import pytest | ||
| from nemo_automodel_plugin.jobs.jobs import AutomodelJob | ||
| from nemo_automodel_plugin.schema import AutomodelJobOutput | ||
| from nemo_platform_plugin.jobs.exceptions import PlatformJobCompilationError | ||
|
|
||
|
|
||
| def _make_canonical(**parallelism: Any) -> AutomodelJobOutput: | ||
| return AutomodelJobOutput.model_validate( | ||
| { | ||
| "model": "default/base", | ||
| "dataset": {"training": "default/train"}, | ||
| "training": {"training_type": "sft"}, | ||
| "schedule": {"epochs": 1}, | ||
| "batch": {"global_batch_size": 4, "micro_batch_size": 1}, | ||
| "optimizer": {}, | ||
| "parallelism": {"num_nodes": 2, "num_gpus_per_node": 8, **parallelism}, | ||
| "output": {"name": "out", "type": "adapter", "fileset": "out-fs"}, | ||
| }, | ||
| ) | ||
|
|
||
|
|
||
| def _compile(canonical: AutomodelJobOutput) -> Any: | ||
| return asyncio.run( | ||
| AutomodelJob.compile( | ||
| workspace="default", | ||
| spec=canonical, | ||
| entity_client=object(), | ||
| job_name=None, | ||
| async_sdk=object(), | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| class TestCompileValidationErrors: | ||
| def test_indivisible_batch_raises_compilation_error(self) -> None: | ||
| # global_batch_size=4 with data_parallel_size=16 (2 nodes x 8 GPUs, TP=1). | ||
| canonical = _make_canonical(tensor_parallel_size=1) | ||
| with patch("nemo_automodel_plugin.jobs.jobs.require_container_runtime"): | ||
| with pytest.raises(PlatformJobCompilationError, match="global_batch_size"): | ||
| _compile(canonical) | ||
|
|
||
| def test_indivisible_model_parallel_raises_compilation_error(self) -> None: | ||
| # 16 total GPUs is not divisible by tensor_parallel_size=5. | ||
| canonical = _make_canonical(tensor_parallel_size=5) | ||
| with patch("nemo_automodel_plugin.jobs.jobs.require_container_runtime"): | ||
| with pytest.raises(PlatformJobCompilationError, match="Total GPUs"): | ||
| _compile(canonical) |
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.