8000 Deprecate DataLoader pin_memory_device param by zeshengzong · Pull Request #146821 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

Deprecate DataLoader pin_memory_device param #146821

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

8000
Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

zeshengzong
Copy link
Contributor
@zeshengzong zeshengzong commented Feb 10, 2025

Following #131858 suggestion to optimize DataLoader code

cc @albanD

Copy link
pytorch-bot bot commented Feb 10, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/146821

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ No Failures

As of commit 0936a1a with merge base 97dfd8d (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot bot added the release notes: dataloader release notes category label Feb 10, 2025
@zeshengzong zeshengzong force-pushed the opt/dataloader/pin_memory_device branch from 6957150 to d390aeb Compare February 11, 2025 07:34
@zeshengzong zeshengzong marked this pull request as ready for review February 13, 2025 07:26
@janeyx99 janeyx99 requested a review from albanD February 13, 2025 18:42
@janeyx99 janeyx99 added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Feb 13, 2025
@zeshengzong
Copy link
Contributor Author

@albanD Hello, please check changes when available, thanks!

@zeshengzong zeshengzong force-pushed the opt/dataloader/pin_memory_device branch from d390aeb to b393a6a Compare March 4, 2025 02:37
@divyanshk
Copy link
Contributor

@zeshengzong Should we also update https://github.com/pytorch/pytorch/blob/main/torch/utils/data/_utils/pin_memory.py#L18-L33 ? We don't want _pin_memory_loop to act differently based on self._pin_memory_device.

Also, starting CI.

@zeshengzong zeshengzong force-pushed the opt/dataloader/pin_memory_device branch 2 times, most recently from 01b1d42 to 0dac805 Compare March 14, 2025 03:08
@@ -15,22 +15,13 @@
from . import MP_STATUS_CHECK_INTERVAL


def _pin_memory_loop(in_queue, out_queue, device_id, done_event, device):
def _pin_memory_loop(in_queue, out_queue, done_event, device):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think device_id param may not needed, the caller pass value of torch.accelerator.current_device_index() and here we set it to torch.accelerator.set_device_index(device_id), looks like its the same value, be like

current_device_index = torch.accelerator.current_device_index()
torch.accelerator.set_device_index(current_device_index)

So remove the set logic in below

Copy link
Collaborator

Choose a reason for hiding this comment

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

But this is called from a different thread. So we have to set the device again !

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, not aware of this point, restored change, thanks!

@zeshengzong
Copy link
Contributor Author

@zeshengzong Should we also update https://github.com/pytorch/pytorch/blob/main/torch/utils/data/_utils/pin_memory.py#L18-L33 ? We don't want _pin_memory_loop to act differently based on self._pin_memory_device.

Also, starting CI.

Changed

@zeshengzong
Copy link
Contributor Author

@pytorchbot rebase -b main

@pytorchmergebot
Copy link
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/main. Check the current status here

@pytorchmergebot
Copy link
Collaborator

Successfully rebased opt/dataloader/pin_memory_device onto refs/remotes/origin/main, please pull locally before adding more changes (for example, via git checkout opt/dataloader/pin_memory_device && git pull --rebase)

@pytorchmergebot pytorchmergebot force-pushed the opt/dataloader/pin_memory_device branch from 0dac805 to e9798b4 Compare March 21, 2025 02:10
custom_device_mod.set_device(device_id)
elif device is None:
torch.accelerator.set_device_index(device_id)
current_device_index = torch.accelerator.current_device_index()
Copy link
Contributor

Choose a reason for hiding this comment

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

@zeshengzong Can we create current_device_index in the except block, since it is used only for the ExceptionWrapper?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed, thanks!

< 8000 /div>
@divyanshk
Copy link
Contributor

@zeshengzong Left a minor comment, looking good otherwise.

@albanD Since your suggestion sparked this PR, can you give it a look as well. Thanks!

@zeshengzong
Copy link
Contributor Author

@pytorchbot rebase -b main

@pytorchmergebot
Copy link
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/main. Check the current status here

@pytorchmergebot
Copy link
Collaborator

Successfully rebased opt/dataloader/pin_memory_device onto refs/remotes/origin/main, please pull locally before adding more changes (for example, via git checkout opt/dataloader/pin_memory_device && git pull --rebase)

@pytorchmergebot pytorchmergebot force-pushed the opt/dataloader/pin_memory_device branch from 2a240ce to 490c0d5 Compare April 8, 2025 07:38
@zeshengzong
Copy link
Contributor Author

@albanD Hello, please help review the change, thanks!

@zeshengzong zeshengzong requested a review from ramanishsingh as a code owner May 6, 2025 03:04
@zeshengzong
Copy link
Contributor Author

@pytorchbot rebase -b main

@pytorchmergebot
Copy link
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/main. Check the current status here

@pytorchmergebot
Copy link
Collaborator

Successfully rebased opt/dataloader/pin_memory_device onto refs/remotes/origin/main, please pull locally before adding more changes (for example, via git checkout opt/dataloader/pin_memory_device && git pull --rebase)

@pytorchmergebot pytorchmergebot force-pushed the opt/dataloader/pin_memory_device branch from 9d2242a to 0936a1a Compare May 6, 2025 03:06
@@ -235,7 +234,7 @@ class DataLoader(Generic[_T_co]):
drop_last: bool
timeout: float
sampler: Union[Sampler, Iterable]
pin_memory_device: str
pin_memory_device: Optional[str]
Copy link
Contributor

Choose a reason for hiding this comment

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

@zeshengzong Let's align the type and default of pin_memory_device here with that defined in the function definition (line 260).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open source release notes: dataloader release notes category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0