-
Notifications
You must be signed in to change notification settings - Fork 6
[platform] refactor: refine detection and platform-specific installs #52
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 all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3b7d105
Refine platform detection and add tests
Wangmerlyn 94ae4ee
Make platform detection ROCm-aware and quieter
Wangmerlyn 12af290
Prioritize NVML for CUDA detection
Wangmerlyn 9c0fe38
Use nvidia-ml-py NVML for CUDA detection
Wangmerlyn 3e0b27b
Add ROCm extra and clarify NVML source
Wangmerlyn 86a5723
Document platform support and ROCm extra
Wangmerlyn b76ec3c
Add platform-specific install quick steps
Wangmerlyn d594119
Update src/keep_gpu/utilities/platform_manager.py
Wangmerlyn c0c0bc8
Update tests/utilities/test_platform_manager.py
Wangmerlyn 6bf17b4
Update tests/utilities/test_platform_manager.py
Wangmerlyn 55c7d2e
Remove unreachable return in CUDA check
Wangmerlyn 677983e
Fix formatting after lint
Wangmerlyn 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import sys | ||
|
|
||
| from keep_gpu.utilities import platform_manager as pm | ||
|
|
||
|
|
||
| def _reset_cache(monkeypatch): | ||
| monkeypatch.setattr(pm, "_cached_platform", None) | ||
| # isolate checks for each test | ||
| monkeypatch.setattr( | ||
| pm, | ||
| "_PLATFORM_CHECKS", | ||
| [ | ||
| (pm.ComputingPlatform.CUDA, lambda: False), | ||
| (pm.ComputingPlatform.ROCM, lambda: False), | ||
| (pm.ComputingPlatform.CPU, lambda: True), | ||
| ], | ||
| ) | ||
|
|
||
|
|
||
| def test_env_override_cpu(monkeypatch): | ||
| _reset_cache(monkeypatch) | ||
| monkeypatch.setenv("KEEP_GPU_PLATFORM", "cpu") | ||
| assert pm.get_platform() == pm.ComputingPlatform.CPU | ||
|
|
||
|
|
||
| def test_invalid_override_falls_back(monkeypatch): | ||
| _reset_cache(monkeypatch) | ||
| monkeypatch.setenv("KEEP_GPU_PLATFORM", "invalid") | ||
| calls = {"count": 0} | ||
|
|
||
| def fake_cuda(): | ||
| calls["count"] += 1 | ||
| return False | ||
|
|
||
| monkeypatch.setattr( | ||
| pm, | ||
| "_PLATFORM_CHECKS", | ||
| [ | ||
| (pm.ComputingPlatform.CUDA, fake_cuda), | ||
| (pm.ComputingPlatform.CPU, lambda: True), | ||
| ], | ||
| ) | ||
| assert pm.get_platform() == pm.ComputingPlatform.CPU | ||
| assert calls["count"] == 1 | ||
|
|
||
|
|
||
| def test_cached_result_reused(monkeypatch): | ||
| _reset_cache(monkeypatch) | ||
| calls = {"count": 0} | ||
|
|
||
| def _fake_check(): | ||
| calls["count"] += 1 | ||
| return True | ||
|
|
||
| monkeypatch.setattr( | ||
| pm, | ||
| "_PLATFORM_CHECKS", | ||
| [(pm.ComputingPlatform.CPU, _fake_check)], | ||
| ) | ||
|
|
||
| assert pm.get_platform() == pm.ComputingPlatform.CPU | ||
| assert pm.get_platform() == pm.ComputingPlatform.CPU | ||
| assert calls["count"] == 1 | ||
|
|
||
|
|
||
| def test_cuda_detected_via_torch_non_hip_build(monkeypatch): | ||
| _reset_cache(monkeypatch) | ||
| monkeypatch.setattr(pm.torch.cuda, "is_available", lambda: True) | ||
| monkeypatch.setattr(pm.torch, "version", type("v", (), {"hip": None})) | ||
| assert pm._check_cuda() is True | ||
|
|
||
|
|
||
| def test_rocm_detects_hip(monkeypatch): | ||
| _reset_cache(monkeypatch) | ||
| monkeypatch.setattr(pm.torch.cuda, "is_available", lambda: True) | ||
| monkeypatch.setattr(pm.torch, "version", type("v", (), {"hip": "6.0"})) | ||
| assert pm._check_rocm() is True | ||
|
|
||
|
|
||
| def test_cuda_detection_falls_back_to_nvml(monkeypatch): | ||
| _reset_cache(monkeypatch) | ||
| # Force torch to look like ROCm build to ensure NVML takes precedence | ||
| monkeypatch.setattr(pm.torch.cuda, "is_available", lambda: True) | ||
| monkeypatch.setattr(pm.torch, "version", type("v", (), {"hip": "6.0"})) | ||
|
|
||
| class DummyNVML: | ||
| @staticmethod | ||
| def nvmlInit(): | ||
| return None | ||
|
|
||
| monkeypatch.setitem(sys.modules, "pynvml", DummyNVML) | ||
| assert pm._check_cuda() is True |
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.