-
Notifications
You must be signed in to change notification settings - Fork 7k
[RLlib] Attention Net prep PR #1: Smaller cleanups. #12447
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,7 +47,12 @@ def ppo_surrogate_loss( | |
|
|
||
| # RNN case: Mask away 0-padded chunks at end of time axis. | ||
| if state: | ||
| max_seq_len = tf.reduce_max(train_batch["seq_lens"]) | ||
| # Derive max_seq_len from the data itself, not from the seq_lens | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prep for attention nets, where dynamic max'ing over the given sequences is not allowed. |
||
| # tensor. This is in case e.g. seq_lens=[2, 3], but the data is still | ||
| # 0-padded up to T=5 (as it's the case for attention nets). | ||
| B = tf.shape(train_batch["seq_lens"])[0] | ||
| max_seq_len = tf.shape(logits)[0] // B | ||
|
|
||
| mask = tf.sequence_mask(train_batch["seq_lens"], max_seq_len) | ||
| mask = tf.reshape(mask, [-1]) | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1033,7 +1033,9 @@ def _process_observations_w_trajectory_view_api( | |
| agent_id) | ||
| episode._set_last_observation(agent_id, filtered_obs) | ||
| episode._set_last_raw_obs(agent_id, raw_obs) | ||
| episode._set_last_info(agent_id, infos[env_id].get(agent_id, {})) | ||
| # Infos from the environment. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding "infos" to the collector's, if required. |
||
| agent_infos = infos[env_id].get(agent_id, {}) | ||
| episode._set_last_info(agent_id, agent_infos) | ||
|
|
||
| # Record transition info if applicable. | ||
| if last_observation is None: | ||
|
|
@@ -1058,15 +1060,20 @@ def _process_observations_w_trajectory_view_api( | |
| "new_obs": filtered_obs, | ||
| } | ||
| # Add extra-action-fetches to collectors. | ||
| values_dict.update(**episode.last_pi_info_for(agent_id)) | ||
| pol = policies[policy_id] | ||
| for key, value in episode.last_pi_info_for(agent_id).items(): | ||
| values_dict[key] = value | ||
| # Env infos for this agent. | ||
| if "infos" in pol.view_requirements: | ||
| values_dict["infos"] = agent_infos | ||
| _sample_collector.add_action_reward_next_obs( | ||
| episode.episode_id, agent_id, env_id, policy_id, | ||
| agent_done, values_dict) | ||
|
|
||
| if not agent_done: | ||
| item = PolicyEvalData( | ||
| env_id, agent_id, filtered_obs, infos[env_id].get( | ||
| agent_id, {}), None if last_observation is None else | ||
| env_id, agent_id, filtered_obs, agent_infos, None | ||
| if last_observation is None else | ||
| episode.rnn_state_for(agent_id), None | ||
| if last_observation is None else | ||
| episode.last_action_for(agent_id), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is the more accurate kwarg to use (torch did not have a loss init step before, so this is new). The old after_init still works the exact same and thus this does not cause an API-break.