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

[RLlib] minor fix for get_init_state annotation in torch #27791

Merged
Merged
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
6 changes: 3 additions & 3 deletions rllib/models/modelv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ def __init__(
# TODO: (sven): Get rid of `get_initial_state` once Trajectory
# View API is supported across all of RLlib.
@PublicAPI
def get_initial_state(self) -> List[np.ndarray]:
def get_initial_state(self) -> List[TensorType]:
"""Get the initial recurrent state values for the model.

Returns:
List of np.array objects containing the initial hidden state
of an RNN, if applicable.
List of np.array (for tf) or Tensor (for torch) objects containing the
initial hidden state of an RNN, if applicable.

Examples:
>>> import numpy as np
Expand Down
3 changes: 2 additions & 1 deletion rllib/utils/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Union,
)

import numpy as np
import gym

from ray.rllib.utils.annotations import ExperimentalAPI
Expand All @@ -29,7 +30,7 @@

# Represents a generic tensor type.
# This could be an np.ndarray, tf.Tensor, or a torch.Tensor.
TensorType = Any
TensorType = Union[np.array, "tf.Tensor", "torch.Tensor"]

# Either a plain tensor, or a dict or tuple of tensors (or StructTensors).
TensorStructType = Union[TensorType, dict, tuple]
Expand Down