-
Notifications
You must be signed in to change notification settings - Fork 307
Validate checkpoint GPU UUID inputs early #2086
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
leofang
merged 6 commits into
NVIDIA:main
from
aryanputta:fix-checkpoint-gpu-uuid-validation
Jun 10, 2026
+9
−2
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c62413e
Validate checkpoint GPU UUID inputs
aryanputta 083e411
Narrow checkpoint GPU UUID restore inputs
aryanputta 3261c10
Restore checkpoint CUuuid compatibility
aryanputta 1520ee3
Retry CI after infra failures
aryanputta 41507c5
Merge remote-tracking branch 'upstream/main' into fix-checkpoint-gpu-…
aryanputta 1ff00e5
Merge branch 'main' into fix-checkpoint-gpu-uuid-validation
leofang 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
|
leofang marked this conversation as resolved.
Outdated
|
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,114 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Source-level tests for checkpoint helper validation. | ||
|
|
||
| These tests load ``cuda/core/checkpoint.py`` directly from source with small | ||
| stub modules, so they can run without importing the full built ``cuda.core`` | ||
| package. Run with ``--noconftest`` in environments that do not have the CUDA | ||
| extensions available: | ||
|
|
||
| pytest cuda_core/tests/test_checkpoint_helpers.py --noconftest | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import importlib.util | ||
| import sys | ||
| import types | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| def _load_checkpoint_module(monkeypatch): | ||
| cuda_pkg = types.ModuleType("cuda") | ||
| cuda_pkg.__path__ = [] | ||
| core_pkg = types.ModuleType("cuda.core") | ||
| core_pkg.__path__ = [] | ||
| utils_pkg = types.ModuleType("cuda.core._utils") | ||
| utils_pkg.__path__ = [] | ||
| bindings_pkg = types.ModuleType("cuda.bindings") | ||
| bindings_pkg.__path__ = [] | ||
|
|
||
| cuda_utils = types.ModuleType("cuda.core._utils.cuda_utils") | ||
| cuda_utils.handle_return = lambda result: result | ||
|
|
||
| version_mod = types.ModuleType("cuda.core._utils.version") | ||
| version_mod.binding_version = lambda: (13, 0, 2) | ||
| version_mod.driver_version = lambda: (12, 8, 0) | ||
|
|
||
| typing_mod = types.ModuleType("cuda.core.typing") | ||
| typing_mod.ProcessStateType = str | ||
|
|
||
| driver_mod = types.ModuleType("cuda.bindings.driver") | ||
|
|
||
| class CUuuid: | ||
| def __init__(self, value): | ||
| self.value = value | ||
|
|
||
| class CUcheckpointGpuPair: | ||
| def __init__(self): | ||
| self.oldUuid = None | ||
| self.newUuid = None | ||
|
|
||
| class CUcheckpointRestoreArgs: | ||
| def __init__(self): | ||
| self.gpuPairs = None | ||
| self.gpuPairsCount = 0 | ||
|
|
||
| driver_mod.CUuuid = CUuuid | ||
| driver_mod.CUcheckpointGpuPair = CUcheckpointGpuPair | ||
| driver_mod.CUcheckpointRestoreArgs = CUcheckpointRestoreArgs | ||
|
|
||
| modules = { | ||
| "cuda": cuda_pkg, | ||
| "cuda.core": core_pkg, | ||
| "cuda.core._utils": utils_pkg, | ||
| "cuda.core._utils.cuda_utils": cuda_utils, | ||
| "cuda.core._utils.version": version_mod, | ||
| "cuda.core.typing": typing_mod, | ||
| "cuda.bindings": bindings_pkg, | ||
| "cuda.bindings.driver": driver_mod, | ||
| } | ||
| for name, module in modules.items(): | ||
| monkeypatch.setitem(sys.modules, name, module) | ||
|
|
||
| checkpoint_path = Path(__file__).parent.parent / "cuda" / "core" / "checkpoint.py" | ||
| spec = importlib.util.spec_from_file_location("cuda.core._checkpoint_test", checkpoint_path) | ||
| module = importlib.util.module_from_spec(spec) | ||
| spec.loader.exec_module(module) | ||
| return module, driver_mod | ||
|
|
||
|
|
||
| def test_make_restore_args_rejects_non_uuid_values(monkeypatch): | ||
| checkpoint, driver = _load_checkpoint_module(monkeypatch) | ||
|
|
||
| with pytest.raises(TypeError, match="GPU UUID values must be CUDA UUID objects or UUID strings"): | ||
| checkpoint._make_restore_args(driver, {"01234567-89ab-cdef-0123-456789abcdef": object()}) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "bad_uuid", | ||
| [ | ||
| pytest.param("not-hex-uuid-0000-0000-000000000000", id="non_hex"), | ||
| pytest.param("01234567-89ab-cdef-0123-456789abcde", id="short"), | ||
| ], | ||
| ) | ||
| def test_make_restore_args_rejects_invalid_uuid_strings(monkeypatch, bad_uuid): | ||
| checkpoint, driver = _load_checkpoint_module(monkeypatch) | ||
|
|
||
| with pytest.raises(ValueError, match="GPU UUID string must be 32 hex characters"): | ||
| checkpoint._make_restore_args(driver, {bad_uuid: "01234567-89ab-cdef-0123-456789abcdef"}) | ||
|
|
||
|
|
||
| def test_make_restore_args_accepts_uuid_objects(monkeypatch): | ||
| checkpoint, driver = _load_checkpoint_module(monkeypatch) | ||
|
|
||
| old_uuid = driver.CUuuid(111) | ||
| new_uuid = driver.CUuuid(222) | ||
| args = checkpoint._make_restore_args(driver, {old_uuid: new_uuid}) | ||
|
|
||
| assert args.gpuPairsCount == 1 | ||
| assert args.gpuPairs[0].oldUuid is old_uuid | ||
| assert args.gpuPairs[0].newUuid is new_uuid |
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.