-
Notifications
You must be signed in to change notification settings - Fork 15
fix(slurm): make the generated job script portable across clusters #163
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
Open
mkuznet1
wants to merge
6
commits into
develop
Choose a base branch
from
mkuznet1/slurm-portability
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+260
−8
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7cf7528
feat(slurm): allow opting out of the --gpus-per-node sbatch directive
2498808
fix(slurm): raise the madengine availability probe timeout
dcebddd
fix(run): cap the informational rocm-libs package query
3f03629
fix(slurm): inherit the submitter's PATH in the sbatch job
469d34e
fix(slurm): match nfs4 in the shared-filesystem probe
fb5ac4a
fix(slurm): read the filesystem type, not the whole df line
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,201 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| Unit tests for the generated SLURM job script (`job.sh.j2`). | ||
|
|
||
| Locks in the portability contract points that clusters keep re-discovering | ||
| downstream (see ROCm/rocm-systems#9055, which patched madengine's source | ||
| rather than filing them): | ||
|
|
||
| 1. The job script puts madengine back on PATH itself instead of assuming the | ||
| batch environment inherited the submitter's PATH. | ||
| 2. The shared-filesystem probe recognizes `nfs4`, which is what `df -T` | ||
| reports on most modern NFS mounts. | ||
| 3. `slurm.skip_gpus_directive` removes `#SBATCH --gpus-per-node`, which a | ||
| cluster advertising no GPU GRES rejects outright. | ||
|
|
||
| Copyright (c) Advanced Micro Devices, Inc. All rights reserved. | ||
| """ | ||
|
|
||
| import json | ||
| import re | ||
| from pathlib import Path | ||
| from unittest.mock import patch | ||
|
|
||
| import pytest | ||
|
|
||
| from madengine.deployment.base import DeploymentConfig | ||
| from madengine.deployment.slurm import SlurmDeployment | ||
|
|
||
|
|
||
| MODEL_ENTRY = { | ||
| "name": "dummy_torchrun_multinode", | ||
| "url": "", | ||
| "dockerfile": "docker/dummy", | ||
| "scripts": "scripts/dummy/run.sh", | ||
| "n_gpus": "8", | ||
| "owner": "mad.support@amd.com", | ||
| "training_precision": "", | ||
| "tags": ["pyt", "training"], | ||
| "timeout": -1, | ||
| "args": "", | ||
| } | ||
|
|
||
|
|
||
| def _build_deployment( | ||
| tmp_path: Path, | ||
| slurm_overrides: dict = None, | ||
| distributed_overrides: dict = None, | ||
| ) -> SlurmDeployment: | ||
| """SlurmDeployment over a minimal torchrun manifest, output_dir under tmp_path.""" | ||
| manifest = { | ||
| "built_images": {"dummy-image": {"docker_image": "dummy:latest"}}, | ||
| "built_models": {"dummy-image": MODEL_ENTRY}, | ||
| "context": { | ||
| "docker_env_vars": {}, | ||
| "docker_mounts": {}, | ||
| "docker_build_arg": {}, | ||
| "gpu_vendor": "AMD", | ||
| "guest_os": "UBUNTU", | ||
| "docker_gpus": "all", | ||
| }, | ||
| } | ||
| manifest_path = tmp_path / "build_manifest.json" | ||
| manifest_path.write_text(json.dumps(manifest)) | ||
|
|
||
| slurm_config = { | ||
| "partition": "test-partition", | ||
| "nodes": 2, | ||
| "gpus_per_node": 8, | ||
| "time": "01:00:00", | ||
| "output_dir": str(tmp_path / "slurm_output"), | ||
| "exclusive": True, | ||
| } | ||
| slurm_config.update(slurm_overrides or {}) | ||
|
|
||
| distributed_config = { | ||
| "launcher": "torchrun", | ||
| "nnodes": 2, | ||
| "nproc_per_node": 8, | ||
| "backend": "nccl", | ||
| "port": 29500, | ||
| } | ||
| distributed_config.update(distributed_overrides or {}) | ||
|
|
||
| cfg = DeploymentConfig( | ||
| target="slurm", | ||
| manifest_file=str(manifest_path), | ||
| additional_context={ | ||
| "deploy": "slurm", | ||
| "gpu_vendor": "AMD", | ||
| "guest_os": "UBUNTU", | ||
| "slurm": slurm_config, | ||
| "distributed": distributed_config, | ||
| }, | ||
| ) | ||
| return SlurmDeployment(cfg) | ||
|
|
||
|
|
||
| def _render(deployment: SlurmDeployment) -> str: | ||
| """Render job.sh.j2 exactly as prepare() does, without submitting anything.""" | ||
| context = deployment._prepare_template_context(MODEL_ENTRY) | ||
| return deployment.jinja_env.get_template("job.sh.j2").render(**context) | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # 1. PATH is re-established inside the job | ||
|
|
||
| class TestJobScriptPath: | ||
| """The job script must not depend on the submitter's PATH being inherited.""" | ||
|
|
||
| def test_user_bin_dir_is_prepended(self, tmp_path): | ||
| script = _render(_build_deployment(tmp_path)) | ||
| assert 'export PATH="$HOME/.local/bin:$PATH"' in script | ||
|
|
||
| def test_submission_bin_dir_is_prepended(self, tmp_path): | ||
| with patch("madengine.deployment.slurm.shutil.which", return_value="/opt/venv/bin/madengine"): | ||
| script = _render(_build_deployment(tmp_path)) | ||
| assert 'export PATH="/opt/venv/bin:$PATH"' in script | ||
|
|
||
| def test_no_empty_export_when_cli_not_on_path(self, tmp_path): | ||
| """madengine missing at submission time must not render an empty PATH entry.""" | ||
| with patch("madengine.deployment.slurm.shutil.which", return_value=None): | ||
| script = _render(_build_deployment(tmp_path)) | ||
| assert 'export PATH=":$PATH"' not in script | ||
| assert 'export PATH="$HOME/.local/bin:$PATH"' in script | ||
|
|
||
| def test_path_is_set_before_madengine_is_looked_up(self, tmp_path): | ||
| """The export is useless if it lands after `command -v madengine`.""" | ||
| with patch("madengine.deployment.slurm.shutil.which", return_value="/opt/venv/bin/madengine"): | ||
| script = _render(_build_deployment(tmp_path)) | ||
| assert script.index('export PATH="/opt/venv/bin:$PATH"') < script.index("command -v madengine") | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # 2. Shared-filesystem probe | ||
|
|
||
| class TestSharedFilesystemProbe: | ||
| """`df -T` reports nfs4 on modern mounts; the probe must not miss it. | ||
|
|
||
| And it must read the filesystem type, nothing else: the mount point travels on the | ||
| same `df -T` line, so a local disk under a path such as /mnt/nfs-scratch used to answer | ||
| yes and the job then trusted node-local storage to be visible from every node. | ||
| """ | ||
|
|
||
| @staticmethod | ||
| def _probe_pattern(script: str) -> str: | ||
| match = re.search(r"SUBMIT_FSTYPE\"?\s*\|\s*grep -qE '([^']+)'", script) | ||
| assert match, "shared-filesystem probe not found in rendered script" | ||
| return match.group(1) | ||
|
|
||
| @pytest.mark.parametrize("fstype,expected", [ | ||
| ("nfs", True), | ||
| ("nfs3", True), | ||
| ("nfs4", True), | ||
| ("lustre", True), | ||
| ("gpfs", True), | ||
| ("ceph", True), | ||
| ("beegfs", True), | ||
| ("panfs", True), | ||
| ("ext4", False), | ||
| ("xfs", False), | ||
| ("overlay", False), | ||
| ("tmpfs", False), | ||
| ]) | ||
| def test_probe_matches_shared_filesystems(self, tmp_path, fstype, expected): | ||
| # The probe only exists on the single-node branch of the template. | ||
| deployment = _build_deployment(tmp_path, {"nodes": 1}, {"nnodes": 1}) | ||
| pattern = self._probe_pattern(_render(deployment)) | ||
| assert bool(re.search(pattern, fstype)) is expected | ||
|
|
||
| def test_the_probe_reads_the_fstype_column_only(self, tmp_path): | ||
| script = _render(_build_deployment(tmp_path, {"nodes": 1}, {"nnodes": 1})) | ||
| assert 'df --output=fstype "$SUBMIT_DIR"' in script | ||
| assert 'df -T "$SUBMIT_DIR" 2>/dev/null | grep' not in script | ||
|
|
||
| def test_a_mount_point_that_says_nfs_does_not_make_a_disk_shared(self, tmp_path): | ||
| """/mnt/nfs-scratch on ext4 is local, whatever its name suggests.""" | ||
| script = _render(_build_deployment(tmp_path, {"nodes": 1}, {"nnodes": 1})) | ||
| pattern = self._probe_pattern(script) | ||
| df_line = "/dev/nvme0n1p2 ext4 104857600 50106368 54751232 48% /mnt/nfs-scratch" | ||
| assert re.search(pattern, df_line) is None | ||
| assert re.search(pattern, "ext4") is None | ||
|
|
||
| def test_there_is_a_fallback_for_df_without_output(self, tmp_path): | ||
| """--output is coreutils 8.21; older df still has to be read correctly.""" | ||
| script = _render(_build_deployment(tmp_path, {"nodes": 1}, {"nnodes": 1})) | ||
| assert "awk 'NR > 1 { print $2; exit }'" in script | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # 3. GPU GRES directive opt-out | ||
|
|
||
| class TestGpusPerNodeDirective: | ||
| """A cluster with GresTypes=(null) rejects any job carrying --gpus-per-node.""" | ||
|
|
||
| def test_directive_present_by_default(self, tmp_path): | ||
| script = _render(_build_deployment(tmp_path)) | ||
| assert "#SBATCH --gpus-per-node=8" in script | ||
|
|
||
| def test_directive_omitted_when_opted_out(self, tmp_path): | ||
| script = _render(_build_deployment(tmp_path, {"skip_gpus_directive": True})) | ||
| assert "--gpus-per-node" not in script |
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.