-
Notifications
You must be signed in to change notification settings - Fork 4
fix(rf3): bind Fabric to caller-specified GPU #222
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
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| """Tests for RF3Wrapper device selection (issue #37). | ||
|
|
||
| Fabric's ``devices`` argument treats an ``int`` as "take this many GPUs, starting | ||
| from index 0", which pins every worker to ``cuda:0`` and serialises nominally | ||
| parallel jobs. The wrapper must accept an explicit device and bind Fabric to | ||
| that specific GPU index via ``devices_per_node=[idx]``. | ||
| """ | ||
|
|
||
| import pytest | ||
| import torch | ||
| from sampleworks.utils.imports import require_rf3, RF3_AVAILABLE | ||
|
|
||
|
|
||
| pytestmark = pytest.mark.skipif(not RF3_AVAILABLE, reason="RF3 dependencies not installed") | ||
|
|
||
| if RF3_AVAILABLE: | ||
| from sampleworks.models.rf3.wrapper import _cuda_index, RF3Wrapper | ||
|
|
||
|
|
||
| class TestCudaIndex: | ||
| """Validate CUDA index extraction used to drive Fabric device selection.""" | ||
|
|
||
| @pytest.mark.parametrize( | ||
| ("device", "expected"), | ||
| [ | ||
| ("cuda:0", 0), | ||
| ("cuda:3", 3), | ||
| (torch.device("cuda", 5), 5), | ||
| ("cuda", 0), | ||
| ], | ||
| ) | ||
| def test_returns_index(self, device, expected): | ||
| assert _cuda_index(device) == expected | ||
|
|
||
| @pytest.mark.parametrize("device", ["cpu", torch.device("cpu")]) | ||
| def test_rejects_non_cuda(self, device): | ||
| with pytest.raises(ValueError, match="CUDA device"): | ||
| _cuda_index(device) | ||
|
|
||
|
|
||
| @pytest.mark.gpu | ||
| @pytest.mark.slow | ||
| class TestRF3WrapperDeviceBinding: | ||
| """Regression for issue #37: device must propagate to Fabric. | ||
|
|
||
| Prior behaviour: RF3Wrapper ignored caller-specified device and always | ||
| landed on ``cuda:0`` because Fabric defaults to ``devices=1``. | ||
| """ | ||
|
|
||
| @require_rf3() | ||
| def test_wrapper_honors_requested_cuda_index(self, rf3_checkpoint_path): | ||
| if torch.cuda.device_count() < 2: | ||
| pytest.skip("multi-GPU regression test needs >= 2 CUDA devices") | ||
|
|
||
| wrapper = RF3Wrapper(checkpoint_path=rf3_checkpoint_path, device="cuda:1") | ||
| assert wrapper.device == torch.device("cuda:1") |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make sure I understood this, I went searching in the foundry repo and found this line: https://github.com/RosettaCommons/foundry/blob/b071919caa19ff334bc04b1b41145cac61eba819/src/foundry/trainers/fabric.py#L92
Would probably be worth referencing this here for posterity