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

[Feature] Distributed data collector (ray) #930

Merged
merged 86 commits into from
Apr 5, 2023

Conversation

albertbou92
Copy link
Contributor

@albertbou92 albertbou92 commented Feb 21, 2023

Description

new class DistributedCollector, which allows to do distributed data collection with TorchRL collectors using Ray.

@vmoens This approach required adding a new function to the collectors, one that takes a single step of the iterator. I have done it with SyncDataCollector. Do you think it is fine?

The PR also includes an example of distributed data collection for the SyncDataCollector case.

Types of changes

What types of changes does your code introduce? Remove all that do not apply:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds core functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (update in the documentation)
  • Example (update in the folder of examples)

Checklist

Go over all the following points, and put an x in all the boxes that apply.
If you are unsure about any of these, don't hesitate to ask. We are here to help!

  • I have read the CONTRIBUTION guide (required)
  • My change requires a change to the documentation.
  • I have updated the tests accordingly (required for a bug fix or a new feature).
  • I have updated the documentation accordingly.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 21, 2023
@albertbou92 albertbou92 marked this pull request as draft February 21, 2023 10:17
@vmoens vmoens changed the title [Feature] Distributed data collector [Feature] Distributed data collector (ray) Feb 21, 2023
torchrl/collectors/distributed/distributed_collector.py Outdated Show resolved Hide resolved
torchrl/collectors/distributed/distributed_collector.py Outdated Show resolved Hide resolved
torchrl/collectors/distributed/distributed_collector.py Outdated Show resolved Hide resolved
torchrl/collectors/distributed/distributed_collector.py Outdated Show resolved Hide resolved
torchrl/collectors/distributed/distributed_collector.py Outdated Show resolved Hide resolved
torchrl/collectors/distributed/distributed_collector.py Outdated Show resolved Hide resolved
# Broadcast agent weights
self.local_collector().update_policy_weights_()
state_dict = {"policy_state_dict": self._local_collector.policy.state_dict()}
state_dict = ray.put(state_dict)
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: in regular data collectors we leave this to the user or ask explicitly if the update should be done at each iter.
Do we want to do the same here? ie isolating the weight updating in a dedicated method that can or won't be called at each iteration.

torchrl/collectors/distributed/distributed_collector.py Outdated Show resolved Hide resolved
samples_ready = []
while len(samples_ready) < self.num_collectors:
samples_ready, samples_not_ready = ray.wait(
pending_samples, num_returns=len(pending_samples), timeout=0.001)
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the role of timeout here? Is the value standard? Should it be a hyperparam or a global variable?

Copy link
Contributor Author

@albertbou92 albertbou92 Feb 22, 2023

Choose a reason for hiding this comment

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

If timeout is set, the function returns either when the requested number of IDs are ready or when the timeout is reached, whichever occurs first. If it is not set, the function simply waits until that number of objects is ready and returns that exact number of object refs. Default value is None.

Actually for now we can just set timeout=None, but if we want to implement the preemption mechanism, we will need to check regularly how many of the tasks have ended. We can either set it to a reasonable value of allow the users to define it.

torchrl/collectors/distributed/distributed_collector.py Outdated Show resolved Hide resolved
@vmoens
Copy link
Contributor

vmoens commented Mar 29, 2023

Sorry for the late reply

@vmoens This approach required adding a new function to the collectors, one that takes a single step of the iterator. I have done it with SyncDataCollector. Do you think it is fine?

I can't spot it, what is it that you changed?
We have a collector.next() method now if that's what you need.

Also why aren't the test following the same pattern than other distributed collectors? I think it's fine if there is a good reason.

Copy link
Contributor

@vmoens vmoens left a comment

Choose a reason for hiding this comment

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

LGTM, see my comment in the PR

torchrl/collectors/distributed/ray.py Outdated Show resolved Hide resolved
Copy link
Contributor

@vmoens vmoens left a comment

Choose a reason for hiding this comment

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

Awesome!

Copy link
Contributor

Choose a reason for hiding this comment

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

Lovely! You went the extra length with this!

@vmoens vmoens merged commit 60d2dc5 into pytorch:main Apr 5, 2023
albertbou92 added a commit to PyTorchRL/rl that referenced this pull request Apr 12, 2023
Co-authored-by: Vincent Moens <vincentmoens@gmail.com>
@albertbou92 albertbou92 deleted the distributed_collector branch January 18, 2024 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants