Repository navigation
refactor/ppo #1856
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
refactor/ppo #1856
Changes from 1 commit
ed6b129
814fb03
f6a8b2e
fd9379a
64a0cf6
cb44255
58b9c0b
5b155fd
f811c44
fc70dd2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,9 +108,25 @@ def async_init(self, args, role, with_ref=False, with_opd_teacher=False): | |
| for actor in self._actor_handlers | ||
| ] | ||
|
|
||
| def async_train(self, rollout_id, rollout_data_ref): | ||
| """Do one rollout training""" | ||
| return [actor.train.remote(rollout_id, rollout_data_ref) for actor in self._actor_handlers] | ||
| def async_train(self, rollout_id, rollout_data_ref, external_data=None): | ||
| """Do one rollout training. Returns a list of Ray refs (one per worker). | ||
|
|
||
| For critics, each ref resolves to ``{"values": [cpu tensors...]}`` (or ``{}`` | ||
| for non-last-PP-stage workers). Actor refs resolve to ``None``. | ||
|
|
||
| ``external_data`` may be a list (one item per worker) or a single dict | ||
| broadcast to all workers. | ||
| """ | ||
| if isinstance(external_data, list): | ||
| assert len(external_data) == len(self._actor_handlers) | ||
| return [ | ||
| actor.train.remote(rollout_id, rollout_data_ref, external_data=ed) | ||
| for actor, ed in zip(self._actor_handlers, external_data, strict=False) | ||
| ] | ||
| return [ | ||
| actor.train.remote(rollout_id, rollout_data_ref, external_data=external_data) | ||
| for actor in self._actor_handlers | ||
| ] | ||
|
Comment on lines
+111
to
+129
|
||
|
|
||
| def save_model(self, rollout_id, force_sync=False): | ||
| """Save actor model""" | ||
|
|
@@ -129,13 +145,12 @@ def offload(self): | |
| def clear_memory(self): | ||
| return ray.get([actor.clear_memory.remote() for actor in self._actor_handlers]) | ||
|
|
||
| def connect(self, critic_group): | ||
| return ray.get( | ||
| [ | ||
| actor.connect_actor_critic.remote(critic) | ||
| for actor, critic in zip(self._actor_handlers, critic_group._actor_handlers, strict=False) | ||
| ] | ||
| ) | ||
|
|
||
| def set_rollout_manager(self, rollout_manager): | ||
| return ray.get([actor.set_rollout_manager.remote(rollout_manager) for actor in self._actor_handlers]) | ||
|
|
||
| def get_parallel_value_info(self): | ||
| """Return value-shard identities for all workers in this group. | ||
|
|
||
| Each item is ``(dp_rank, cp_rank, dp_world_size, cp_world_size)``. | ||
| """ | ||
| return ray.get([actor.get_parallel_value_info.remote() for actor in self._actor_handlers]) | ||
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.
compute_advantages_and_returnsassumes a custom advantage function will always populaterollout_data['advantages']androllout_data['returns'], but if it doesn't, the code will fail later with aKeyError/unclear error. Consider validating aftercustom_adv_fn(...)returns and raising a clearValueErrorif required keys are missing or have the wrong type/shape.