Skip to content

speedup accessing actions one agent at a time #4261

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ml-agents/mlagents/trainers/agent_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def _process_step(
action_pre = None
action_probs = stored_take_action_outputs["log_probs"][idx]
action_mask = stored_decision_step.action_mask
prev_action = self.policy.retrieve_previous_action([global_id])[0, :]
prev_action = self.policy.retrieve_previous_action_single(global_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you be opposed to renaming the method retrieve_previous_action and the old method to retrieve_previous_actions? Seems more descriptive and more similar to the methods in the LL-API.

experience = AgentExperience(
obs=obs,
reward=step.reward,
Expand Down
10 changes: 10 additions & 0 deletions ml-agents/mlagents/trainers/policy/tf_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,16 @@ def retrieve_previous_action(self, agent_ids: List[str]) -> np.ndarray:
action_matrix[index, :] = self.previous_action_dict[agent_id]
return action_matrix

def retrieve_previous_action_single(self, agent_id: str) -> np.ndarray:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this method needs to be moved to policy.py with the other retrieve methods (#4254).

"""
A more efficient version of retrieve_previous_action() for a single
agent at a time.
"""
prev_action = self.previous_action_dict.get(agent_id)
if prev_action is not None:
return prev_action
return np.zeros(self.num_branches, dtype=np.int)

def remove_previous_action(self, agent_ids):
for agent_id in agent_ids:
if agent_id in self.previous_action_dict:
Expand Down