-
Notifications
You must be signed in to change notification settings - Fork 51
Manual memory pinning #1533
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
Closed
Closed
Manual memory pinning #1533
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
970c4dc
add pin mem to IOReaderData
5c566df
add pin mem to sample & modelbatch class
e85309d
add pin mem to stream data
ac3b089
add pin mem to training loop
c3fc9a7
run /scripts/actions.sh lint
7ac3b3e
run ./scripts/actions.sh unit-test
a65f561
ignore check torch import in package
98f4e0b
move pinning to MultiStreamDataSampler
bc80b26
add _pin_tensor & _pin_tensor_list helper func
8f98482
ruff the code
ea8f16c
move back pin mem. to train loop
61433eb
Remove the ignore-import-error rule and revert to the state before th…
48c51e3
create protocol for pinnable obj
dc40a2f
remove pin_mem from IOReaderData class
36c4b9c
add pin_memory to Trainer.validate
ebec481
remove pin_memory from loader_params
62c4e02
Rever export/export_inference.py to state before c3fc9a78
6a22234
change name
3796bc8
revise Pinnable class description
e29160a
Merge branch 'ecmwf:develop' into javad/dev/manual-mem-pinning-1399
javak87 7fe5b44
add memory_pinning in config, train & va loop
20944f3
Merge branch 'develop' into javad/dev/manual-mem-pinning-1399
javak87 08078e8
use getattr to avoid CICD warning
bd57cf4
use setattr to avoid CICD warning
503d742
disable pylint for self.source_tokens_lens
71461b6
Merge branch 'develop' into javad/dev/manual-mem-pinning-1399
clessig a31d6ea
changes based on #1615
7a98a08
Merge branch 'javad/dev/manual-mem-pinning-1399' of https://github.co…
039121b
Merge branch 'develop' into javad/dev/manual-mem-pinning-1399
javak87 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| from typing import Protocol, runtime_checkable | ||
|
|
||
| import torch | ||
|
|
||
| from weathergen.common.io import IOReaderData | ||
|
|
||
|
|
||
| @runtime_checkable | ||
| class Pinnable(Protocol): | ||
| """ | ||
| Protocol that allows the pytorch content of a data structure | ||
| to be pinned to the memory of the current accelerator. | ||
|
|
||
| This extends the pin_memory() capability of a torch Tensor | ||
| to other classes. | ||
|
|
||
| It is blocking. | ||
| """ | ||
|
|
||
| def pin_memory(self): ... | ||
|
|
||
|
|
||
| def pin_object(obj: Pinnable | torch.Tensor | IOReaderData | list | dict | None): | ||
| if obj is None: | ||
| return | ||
| elif isinstance(obj, torch.Tensor | Pinnable): | ||
| obj.pin_memory() | ||
| elif isinstance(obj, IOReaderData): | ||
| # Special case: IOReaderData is in common package and can't have torch deps | ||
| # Note: These SHOULD be numpy arrays per the type hints, but might be tensors | ||
| pin_object(obj.coords) | ||
| pin_object(obj.data) | ||
| pin_object(obj.geoinfos) | ||
|
|
||
| elif isinstance(obj, list): | ||
| # Assume the list is a list of potentially pinnable objects and traverse it. | ||
| for e in obj: | ||
| pin_object(e) | ||
| elif isinstance(obj, dict): | ||
| # Assume the values are pinnable. | ||
| for e in obj.values(): | ||
| pin_object(e) | ||
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.