-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
GPUDirect Storage prototype tutorial #3317
base: main
Are you sure you want to change the base?
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/tutorials/3317
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New Failure, 1 Unrelated FailureAs of commit a5f98f1 with merge base 63295e8 ( NEW FAILURE - The following job has failed:
BROKEN TRUNK - The following job failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
@@ -31,6 +31,7 @@ | |||
"prototype_source/vmap_recipe", | |||
"prototype_source/torchscript_freezing", | |||
"prototype_source/nestedtensor", | |||
"prototype_source/gpu_direct_storage", # requires specific filesystem + GPUDirect Storage to be set up |
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.
Doesn't it run in compat mode with a random machine?
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.
You need a specific filesystem
# The loading flow is the inverse, we can ``torch.load`` under the ``torch.serialization.skip_data`` context | ||
# manager to load everything except the storage bytes. This means that any tensors in the checkpoint will be | ||
# created but their storages will be empty (i.e. the tensors will be created via ``torch.empty``). If the | ||
# tensors to be loaded to are persistent, one can use the ``torch.cuda.gds.gds_register_buffer`` API to register |
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.
The register API is not used here?
f.load_storage(v.untyped_storage(), offset) | ||
assert torch.equal(v, sd[k]) | ||
|
||
del f |
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.
Similar synchronization question as above
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.
I don't think synchronization is needed after the call as cuFileRead/Write
are blocking operations that block until IO is complete https://docs.nvidia.com/gpudirect-storage/api-reference-guide/index.html#cufileread. You might need to synchronize before these ops (rather than after) though

# We also provide ``torch.cuda.gds.gds_register_buffer`` to register the | ||
# tensor storages as GPUDirect Storage buffers. See `here | ||
# <https://docs.nvidia.com/gpudirect-storage/best-practices-guide/index.html#cufile-bufregister-fileread-filewrite>`_ | ||
# for when one should do this. |
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.
Not sure what this means?
We should either mention when you would want to do that. Or skip this section.
# If you are continuously saving the same state dictionary during training, you | ||
# would only need to obtain the offsets once and the same offsets can be re-used. Similarly if tensor is going to | ||
# be loaded to repeatedly one can use the ``torch.cuda.gds.gds_register_buffer`` which wraps | ||
# ``cuFileBufRegister`` to register the storages as gds buffers. |
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.
@albanD is this better?
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.
Just a few minor nits
GPUDirect Storage enabes a direct data path for direct memeory access transfers | ||
between GPU memory and storage, avoiding a bounce buffer through the CPU. | ||
|
||
In version ``2.7``, we introduced some prototype APIs to ``torch.cuda.gds`` that serve as thin wrappers around |
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.
In version ``2.7``, we introduced some prototype APIs to ``torch.cuda.gds`` that serve as thin wrappers around | |
In version **2.7**, we introduced a new prototype APIs to ``torch.cuda.gds`` that serve as thin wrappers around |
(prototype) Using GPUDirect Storage | ||
==================================== | ||
|
||
GPUDirect Storage enabes a direct data path for direct memeory access transfers |
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.
GPUDirect Storage enabes a direct data path for direct memeory access transfers | |
GPUDirect Storage enables a direct data path for direct memory access transfers |
|
||
In version ``2.7``, we introduced some prototype APIs to ``torch.cuda.gds`` that serve as thin wrappers around | ||
the `cuFile APIs <https://docs.nvidia.com/gpudirect-storage/api-reference-guide/index.html#cufile-io-api>`_ | ||
that can be used with ``torch.Tensor``. |
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.
wondering if we can continue the phrase to show the value proposition. For example (it's just an example):
that can be used with ``torch.Tensor``. | |
that can be used with ``torch.Tensor`` to achieve improved I/O performance. |
################################################################################ | ||
# Using GPUDirect Storage with ``torch.save`` and ``torch.load`` | ||
# ============================================================= | ||
# GPUDirect Storage requires a storage alignment of 4KB. One can toggle this using |
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.
# GPUDirect Storage requires a storage alignment of 4KB. One can toggle this using | |
# GPUDirect Storage requires a storage alignment of 4KB. You can toggle this by using |
# Using GPUDirect Storage with ``torch.save`` and ``torch.load`` | ||
# ============================================================= | ||
# GPUDirect Storage requires a storage alignment of 4KB. One can toggle this using | ||
# ``torch.utils.serialization.config.save.storage_alignment`` to toggle this |
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.
# ``torch.utils.serialization.config.save.storage_alignment`` to toggle this | |
# ``torch.utils.serialization.config.save.storage_alignment``: |
# If you are continuously saving the same state dictionary during training, you | ||
# would only need to obtain the offsets once and the same offsets can be re-used. Similarly if tensor is going to | ||
# be saved or loaded to repeatedly one can use the ``torch.cuda.gds.gds_register_buffer`` which wraps | ||
# ``cuFileBufRegister`` to register the storages as gds buffers. |
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.
# ``cuFileBufRegister`` to register the storages as gds buffers. | |
# ``cuFileBufRegister`` to register the storages as GDS buffers. |
assert torch.equal(v, sd[k]) | ||
|
||
################################################################################ | ||
# The loading flow is the inverse, we can ``torch.load`` under the ``torch.serialization.skip_data`` context |
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.
# The loading flow is the inverse, we can ``torch.load`` under the ``torch.serialization.skip_data`` context | |
# The loading flow is the inverse: you can use ``torch.load`` with the ``torch.serialization.skip_data`` context |
################################################################################ | ||
# The loading flow is the inverse, we can ``torch.load`` under the ``torch.serialization.skip_data`` context | ||
# manager to load everything except the storage bytes. This means that any tensors in the checkpoint will be | ||
# created but their storages will be empty (i.e. the tensors will be created via ``torch.empty``). |
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.
# created but their storages will be empty (i.e. the tensors will be created via ``torch.empty``). | |
# created but their storages will be empty (for example, the tensors will be created via ``torch.empty``). |
|
||
del f | ||
|
||
# Summary |
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.
# Summary | |
# Conclusion |
# in conjunction with ``torch.save`` and ``torch.load`` on local filesystem. Do | ||
# file in issue in the PyTorch GitHub repo if you have any feedback. |
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.
# in conjunction with ``torch.save`` and ``torch.load`` on local filesystem. Do | |
# file in issue in the PyTorch GitHub repo if you have any feedback. | |
# in conjunction with ``torch.save`` and ``torch.load`` on local filesystem. | |
# Please file an issue in the PyTorch GitHub repo if you have any feedback. |
@@ -0,0 +1,126 @@ | |||
""" | |||
(prototype) Using GPUDirect Storage |
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.
I know next to nothing about SEO, but it feels like one can discover this tutorial only if user knows a very specific technical term. Shouldn't it be something like "Accelerating data loading with GPU Direct Storage"?
No description provided.