Skip to content

Commit

Permalink
Use np.int8 instead of np.int64 for action mask dtype
Browse files Browse the repository at this point in the history
This is more memory sufficient for only 0-1's.
And seems to be the standard for action mask at least for ray.rllib,
as shown in `action_mask_key` documentation at
https://docs.ray.io/en/latest/rllib/rllib-training.html
  • Loading branch information
nhuet committed Dec 13, 2024
1 parent e955ec1 commit 85f6c59
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions skdecide/builders/domain/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def _get_action_mask(
1 if applicable_actions.contains(a) else 0
for a in action_space.get_elements()
],
dtype=np.int64,
dtype=np.int8,
)
else:
# multi agent
Expand All @@ -394,7 +394,7 @@ def _get_action_mask(
1 if agent_applicable_actions.contains(a) else 0
for a in action_space[agent].get_elements()
],
dtype=np.int64,
dtype=np.int8,
)
for agent, agent_applicable_actions in applicable_actions.items()
}
Expand Down
2 changes: 1 addition & 1 deletion skdecide/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ def cast_evaluate_function(memory, action, next_state):
# The following alias is needed in core module so that autocast works:
# - `autocast` does not like "." after strings other than "D",
# - `autocast` needs types in annotations to be evaluable in `skdecide.core` namespace.
Mask = npt.NDArray[np.int64]
Mask = npt.NDArray[np.int8]
"""Alias for single agent action mask."""


Expand Down
6 changes: 3 additions & 3 deletions skdecide/hub/solver/ray_rllib/ray_rllib.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def _init_algo(self) -> None:
0,
1,
shape=(len(self._wrapped_action_space[k].get_elements()),),
dtype=np.int64,
dtype=np.int8,
),
}
)
Expand Down Expand Up @@ -539,7 +539,7 @@ def __init__(
self._wrapped_action_space[k].get_elements()
),
),
dtype=np.int64,
dtype=np.int8,
),
}
)
Expand Down Expand Up @@ -569,7 +569,7 @@ def __init__(
self._wrapped_action_space[k].get_elements()
),
),
dtype=np.int64,
dtype=np.int8,
),
}
)
Expand Down

0 comments on commit 85f6c59

Please sign in to comment.