Skip to content
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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

mikaylagawarecki
Copy link
Contributor

No description provided.

Copy link

pytorch-bot bot commented Apr 8, 2025

🔗 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 Failure

As of commit a5f98f1 with merge base 63295e8 (image):

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.

@mikaylagawarecki mikaylagawarecki requested a review from albanD April 8, 2025 14:24
@mikaylagawarecki mikaylagawarecki marked this pull request as draft April 8, 2025 14:24
@@ -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
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor Author

@mikaylagawarecki mikaylagawarecki Apr 8, 2025

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

Screenshot 2025-04-08 at 11 21 32 AM

# 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.
Copy link
Contributor

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.

Comment on lines 68 to 71
# 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.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@albanD is this better?

Copy link
Contributor

@svekars svekars left a 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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``.
Copy link
Contributor

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):

Suggested change
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# ``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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# ``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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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``).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Summary
# Conclusion

Comment on lines +125 to +126
# 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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
Copy link
Contributor

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"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants