-
Notifications
You must be signed in to change notification settings - Fork 88
hotfix: inplace pin memory caused cudaErrorHostMemoryAlreadyRegistered
#69
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
6 commits
Select commit
Hold shift + click to select a range
a3323db
fix: unpin the manually pinned memory using cudaHostUnregister
specture724 17edc0f
fix: support default inplace pin memory in test
specture724 e49924f
feat: test for unpinning inplace pinned memory
specture724 91fcc01
renamed: tests/test_pin_memory.py -> tests/test_reuse_pin_memory.py
specture724 f2af6e3
fix: fix pr issues
specture724 ea934a0
fix: only cuda devices support inplace pin memory
specture724 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import os | ||
| import subprocess | ||
| import time | ||
|
|
||
| import pytest | ||
| import torch.distributed as dist | ||
| from test_update import device_manager, gen_test_tensors, get_world_size | ||
|
|
||
| from checkpoint_engine.ps import ParameterServer | ||
|
|
||
|
|
||
| dev_shm_dir = "/dev/shm/checkpoint_engine_tests" # noqa: S108 | ||
|
|
||
|
|
||
| def get_files() -> list[str]: | ||
| rank = int(os.getenv("RANK")) | ||
| named_tensors = dict(gen_test_tensors(rank)) | ||
| import safetensors.torch | ||
|
|
||
| files = [] | ||
| os.makedirs(dev_shm_dir, exist_ok=True) | ||
| tensors_in_dev_shm = named_tensors | ||
| time.sleep(1) | ||
| dev_shm_files = [ | ||
| os.path.join(dev_shm_dir, f"rank{rank}_checkpoint.safetensors") | ||
| for _ in range(get_world_size()) | ||
| ] | ||
| safetensors.torch.save_file(tensors_in_dev_shm, dev_shm_files[rank]) | ||
| time.sleep(1) | ||
| files.append(dev_shm_files[rank]) | ||
| return files | ||
|
|
||
|
|
||
| def run_pin_and_unpin(num_runs: int): | ||
| ps = ParameterServer(auto_pg=True) | ||
| checkpoint_name = "test_with_files" | ||
| for _ in range(num_runs): | ||
| files = get_files() | ||
| ps.register_checkpoint(checkpoint_name, files=files) | ||
| ps.gather_metas(checkpoint_name) | ||
| dist.barrier() | ||
| ps.unregister_checkpoint(checkpoint_name) | ||
|
specture724 marked this conversation as resolved.
|
||
| if ps._rank == 0: | ||
| import shutil | ||
|
|
||
| shutil.rmtree(dev_shm_dir) | ||
|
|
||
| dist.destroy_process_group() | ||
|
|
||
|
|
||
| @pytest.mark.gpu | ||
| def test_unpin_files(): | ||
| world_size = device_manager.device_module.device_count() | ||
| assert world_size >= 2, "This test requires at least 2 GPUs." | ||
| master_addr = "localhost" | ||
| master_port = 25400 | ||
| cmd = [ | ||
| "torchrun", | ||
| "--nproc_per_node", | ||
| str(world_size), | ||
| "--master_addr", | ||
| master_addr, | ||
| "--master_port", | ||
| str(master_port), | ||
| __file__, | ||
| ] | ||
|
|
||
| result = subprocess.run( # noqa: S603 | ||
| cmd, | ||
| capture_output=False, | ||
| text=True, | ||
| cwd=os.path.dirname(os.path.dirname(os.path.abspath(__file__))), | ||
| shell=False, | ||
| check=False, | ||
| ) | ||
|
|
||
| assert result.returncode == 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| run_pin_and_unpin(3) | ||
File renamed without changes.
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
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.