You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test(cuda.bindings): set a valid power limit in test_set_power_management_limit - #3596
test_set_power_management_limit set every GPU's power limit to a hardcoded 10000 mW (10 W), which is below the minimum of every GPU in CI. Runners without permission skipped on NoPermissionError. Runners with permission skipped on the resulting InvalidArgumentError. So the test never ran.
for each device:
- set_power_management_limit_v2(GPU, 10000) # always invalid- NoPermissionError -> skip- InvalidArgumentError -> skip ("probably unsupported")+ limit = get_power_management_limit()+ min, max = get_power_management_limit_constraints()+ assert min <= limit <= max+ set_power_management_limit_v2(GPU, limit) # valid everywhere; GPU unchanged+ NoPermissionError -> skip+ try:+ assert get_power_management_limit() == limit+ finally:+ set_power_management_limit_v2(GPU, limit) # restore, even if the readback fails
The "not currently run in any CI job" markers are removed. The test is identical in cuda_bindings_12/tests/nvml/test_device.py and cuda_bindings_13/tests/nvml/test_device.py, and both get the same change.
Evidence
Before (main CI): 11 configurations had permission but skipped with InvalidArgumentError: every Windows row, and the two Linux 610.43.02 custom-driver rows. The other 19 skipped with NoPermissionError.
After (locally, CUDA 13 copy, RTX A400 and RTX 5070, not root): the read, range check, and assertion pass on both GPUs. The set call then skips with "No permission", as expected without root.
Confirming it runs in CI: in this PR's CI run, the Windows jobs and the Linux 610.43.02 jobs (CUDA 12 and CUDA 13 bindings) should report test_set_power_management_limit PASSED with SUBPASSED subtests, where main reports SUBSKIPPED. For example:
gh run view <CI run id> --repo NVIDIA/cuda-python --log | grep -F "test_set_power_management_limit"
The Linux rows without root still skip. Running it there is #3582.
Merge Danger
Door: two-way. Test-only change.
Blast Radius: CI runners that have NVML permission. The test now actually calls the power-limit setter there, but with the GPU's current limit, so the setting doesn't change. It can now fail on those runners if NVML rejects a valid limit, which is the point.
Reviewers: please feel free to push commits directly to this PR to improve it.
…ment_limit
The test set every GPU's power limit to a hardcoded 10 W, which is below
the minimum of every GPU in CI. Runners without permission skipped on
NoPermissionError, and runners with permission (Windows, and the Linux
custom-driver rows) skipped on the resulting InvalidArgumentError, so the
test never ran.
Read the current limit and its constraints, re-apply the current limit
(valid on every device, and it leaves a shared GPU unchanged), and assert
that it reads back. InvalidArgumentError is no longer treated as
"unsupported". Remove the "not currently run in any CI job" markers.
Same change in cuda_bindings_12 and cuda_bindings_13.
ClosesNVIDIA#3564
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Updated CUDA 12 and 13 power-limit checks to verify the initial setting is within the device’s supported range, then apply and confirm both the minimum and maximum limits.
Tests restore and verify the original limit afterward. They skip devices whose minimum and maximum limits are equal, and skip when permission is denied while setting the minimum limit. Other errors during that initial setting attempt are reported as failures.
Both NVML power-limit tests now use device-reported constraints, verify minimum and maximum settings, and restore and verify the initial limit. They skip single-value ranges and permission failures.
Changes: Power-limit test
Layer / File(s)
Summary
Validate, set, and restore power limits cuda_bindings_12/tests/nvml/test_device.py, cuda_bindings_13/tests/nvml/test_device.py
Both tests check the supported range, verify minimum and maximum settings, and restore and verify the initial limit in a finally block. They skip on NoPermissionError and no longer skip on InvalidArgumentError.
Assessment against linked issues
Objective
Addressed
Explanation
Read the valid range and current limit, set an in-range value, verify the result, and stop skipping on InvalidArgumentError [#3564]
✅
Restore the saved limit in a finally block [#3564]
✅
Remove the “not currently run in any CI job” markers from both bindings roots [#3564]
❓
The supplied change summaries do not state whether those markers were removed.
This updates the NVML power-limit tests to use device-reported bounds, verify the readbacks and restore the original limit. It does not change the bindings' public behavior, and no concrete merge-blocking risk remains. The tests will only be confirmed on hardware once CI runs on the target rows.
Security architecture risk: Low · up to 69f95
The tests use existing GPU permissions and try to restore the original limit. If restoration fails or the test process stops before cleanup, a GPU can retain the test limit and affect later workloads on that device.
Retained concerns
Trivial · reliability · inferred: The new device-wide writes rely on the test process to restore an in-memory snapshot. If the restore write fails or the process terminates without running cleanup after a successful write, a GPU can retain a test limit. A repeat run can then snapshot and restore that stale value instead of recovering the original. If the GPU is reused without a reset, later workloads inherit the changed limit.
inferred — A permitted invocation can change the device-wide limit on every GPU it enumerates for which the setter succeeds. Another workload on the same GPU can be affected while a limit is changed; if another writer updates the limit during the test, snapshot-based cleanup can overwrite that update. The thread-unsafe marker does not itself establish exclusive GPU ownership across jobs or processes.
Trust Boundaries and Controls
observed — The pytest code passes driver-reported bounds, not request-supplied values, to the existing NVML setter. The first write still runs under the caller's NVML authority and skips if NVML denies permission. The change adds no permission grant.
Hardening Proposals
proposed — Run the mutating tests only on exclusively assigned GPUs, and have the runner verify or reset the power limit before reuse. If the runner cannot confirm recovery after interruption or cleanup failure, keep the GPU out of service until recovery is verified.
- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Finishing TouchesFix failing CI checks
Reviewing files that changed from the base of the PR and between c29b214 and 5bbfb4c.
Files selected for processing: 2
cuda_bindings_12/tests/nvml/test_device.py
cuda_bindings_13/tests/nvml/test_device.py
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 9 remain after this review.
…ment_limit
Wrap the readback assertion in try/finally and set the original limit
again in the finally block, so a failed or mismatched readback still
attempts to restore the GPU's power limit. The restore runs only after the
setter succeeded, so runners without permission still skip cleanly.
Addresses review feedback on NVIDIA#3596.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
— codex GPT-6 on behalf of Ralf —
We already have min_limit and max_limit, so we can use them to verify that the setter actually changes the GPU’s power limit. I’d set and read back both endpoints, then restore and verify the original limit in finally.
The power limit is shared device state. I’d mark the test thread_unsafe to serialize its pytest invocations and run it on GPUs whose power settings the runner controls exclusively. A concurrent writer can make the readback flaky, and cleanup can overwrite that writer’s update.
I’d scope unsupported_before to the initial queries and the first setter call. Once that write succeeds, a failed readback, second write, or restore should fail the subtest.
I’d use this in both bindings roots.
@pytest.mark.thread_unsafe(reason="Changes the device-wide power limit")deftest_set_power_management_limit(all_devices, subtests):
fordeviceinall_devices:
withsubtests.test(device_index=nvml.device_get_index(device)):
withunsupported_before(device, None):
initial_limit=nvml.device_get_power_management_limit(device)
min_limit, max_limit=nvml.device_get_power_management_limit_constraints(device)
assertmin_limit<=initial_limit<=max_limitifmin_limit==max_limit:
pytest.skip("Device supports only one power limit")
try:
nvml.device_set_power_management_limit_v2(device, nvml.PowerScope.GPU, min_limit)
exceptnvml.NoPermissionError:
pytest.skip("No permission to set power management limit")
try:
assertnvml.device_get_power_management_limit(device) ==min_limitnvml.device_set_power_management_limit_v2(device, nvml.PowerScope.GPU, max_limit)
assertnvml.device_get_power_management_limit(device) ==max_limitfinally:
nvml.device_set_power_management_limit_v2(device, nvml.PowerScope.GPU, initial_limit)
assertnvml.device_get_power_management_limit(device) ==initial_limit, "Power limit was not restored"
…ment_limit
Set and read back both constraint endpoints so the test verifies the setter
changes the limit, restore and verify the initial limit in finally, scope
unsupported_before to the initial queries and first write, and mark the test
thread_unsafe since the power limit is device-wide state.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
Architecture findings (1)
Advisory architecture findings (1)
Trivial — The new device-wide writes rely on the test process to restore an in-memory snapshot. If the restore write fails or the process terminates without running cleanup after a successful write, a GPU can retain a test limit. A repeat run can then snapshot and restore that stale value instead of recovering the original. If the GPU is reused without a reset, later workloads inherit the changed limit.
Reviewing files that changed from the base of the PR and between 54fbf3d and 69f9558.
Files selected for processing: 2
cuda_bindings_12/tests/nvml/test_device.py
cuda_bindings_13/tests/nvml/test_device.py
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 7 remain after this review.
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
cuda.bindingsEverything related to the cuda.bindings moduletestImprovements or additions to tests
2 participants
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.
Closes #3564. Part of #2077.
Summary
test_set_power_management_limitset every GPU's power limit to a hardcoded 10000 mW (10 W), which is below the minimum of every GPU in CI. Runners without permission skipped onNoPermissionError. Runners with permission skipped on the resultingInvalidArgumentError. So the test never ran.The "not currently run in any CI job" markers are removed. The test is identical in
cuda_bindings_12/tests/nvml/test_device.pyandcuda_bindings_13/tests/nvml/test_device.py, and both get the same change.Evidence
mainCI): 11 configurations had permission but skipped withInvalidArgumentError: every Windows row, and the two Linux610.43.02custom-driver rows. The other 19 skipped withNoPermissionError.Confirming it runs in CI: in this PR's CI run, the Windows jobs and the Linux
610.43.02jobs (CUDA 12 and CUDA 13 bindings) should reporttest_set_power_management_limitPASSED withSUBPASSEDsubtests, wheremainreportsSUBSKIPPED. For example:The Linux rows without root still skip. Running it there is #3582.
Merge Danger
Door: two-way. Test-only change.
Blast Radius: CI runners that have NVML permission. The test now actually calls the power-limit setter there, but with the GPU's current limit, so the setting doesn't change. It can now fail on those runners if NVML rejects a valid limit, which is the point.
Reviewers: please feel free to push commits directly to this PR to improve it.
🤖 Generated with Claude Code