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

Reference the shared memory object in a worker process when using spawn multiprocessing method #106

Merged
merged 1 commit into from
Dec 29, 2022

Conversation

karan6181
Copy link
Collaborator

Description of changes:

  • Torch DataLoader uses multiprocessing to spin up num_workers processes.
    • The Linux system by default start method is fork and when a process is forked the child process inherits all the same variables in the same state as they were in the parent.
    • The Mac system by default start method is spawn and when a process is spawned, it begins by starting a new Python interpreter. The current module is reimported and new versions of all the variables are created.
  • For the spawn processes, since the resources are not shared, any changes made in next_epoch variable by the num_workers will not be reflected in the main process and this results in the test_streamingdataloader_mid_epoch_resumption test failures when num_workers > 0.
  • The changes made in this PR would reference the same shared memory object in the num_workers processes which was created in the main process. This would ensure that the main process or a parent process would see the updated values when changes made by the num_workers processes.

Issue #, if available:

Merge Checklist:

Put an x without space in the boxes that apply. If you are unsure about any checklist, please don't hesitate to ask. We are here to help! This is simply a reminder of what we are going to look for before merging your pull request.

General

  • I have read the contributor guidelines
  • This is a documentation change or typo fix. If so, skip the rest of this checklist.
  • I certify that the changes I am introducing will be backward compatible, and I have discussed concerns about this, if any, with the MosaicML team.
  • I have updated any necessary documentation, including README and API docs (if appropriate).

Tests

  • I ran pre-commit on my change. (check out the pre-commit section of prerequisites)
  • I have added tests that prove my fix is effective or that my feature works (if appropriate).
  • I ran the tests locally to make sure it pass. (check out testing)
  • I have added unit and/or integration tests as appropriate to ensure backward compatibility of the changes.

Copy link
Contributor

@dakinggg dakinggg left a comment

Choose a reason for hiding this comment

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

Lgtm

@karan6181 karan6181 merged commit 0978985 into mosaicml:main Dec 29, 2022
@karan6181 karan6181 deleted the mac_fix branch December 29, 2022 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants