You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[RLlib] Overhaul of the typing module & better device typing (#55291)
Resolves: #55288 (wrong `np.array` in `TensorType`)
Furthermore changes:
- Changed comments to (semi)docstring which will be displayed as
tooltips by IDEs (e.g. VSCode + Pylance) making that information
available to the user.
- `AgentID: Any -> Hashable` as it used for dict keys
- changed `DeviceType` to be not a TypeVar (makes no sense in the way it
is currently used), also includes DeviceLikeType (`int | str | device`)
from `torch`. IMO it can fully replace the current type but being
defensive I only added it as an extra possible type
- Used updated DeviceType to improve type of Runner._device and make it
more correct
- Used torch's own type in `data`, current code supports more than just
`str`. I refrained from adding a reference to `rllib` despite it being
nice if they would be in sync.
- Some extra formatting that is forced by pre-commit
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Revamps `rllib.utils.typing` (NDArray-based `TensorType`, broader
`DeviceType`, `AgentID` as `Hashable`, docstring cleanups) and updates
call sites to use optional device typing and improved hints.
>
> - **Types**:
> - Overhaul `rllib/utils/typing.py`:
> - `TensorType` now uses `numpy.typing.NDArray`; heavy use of
`TYPE_CHECKING` to avoid runtime deps on torch/tf/jax.
> - `DeviceType` widened to `Union[str, torch.device, int]` (was
`TypeVar`).
> - `AgentID` tightened to `Hashable`; `NetworkType` uses `keras.Model`.
> - Refined aliases (e.g., `FromConfigSpec`, `SpaceStruct`) and added
concise docstrings.
> - **Runners**:
> - `Runner._device` now `Optional` (`Union[DeviceType, None]`) with
updated docstring; same change in offline runners’ `_device` properties.
> - **Connectors**:
> - `NumpyToTensor`: `device` param typed as `Optional[DeviceType]` (via
`TYPE_CHECKING`).
> - **Utils**:
> - `from_config`: typed `config: Optional[FromConfigSpec]` with
`TYPE_CHECKING` import.
> - **Misc**:
> - Minor formatting/import ordering and comment typo fixes.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
ae2e422. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Signed-off-by: Daniel Sperber <github.blurry@9ox.net>
Signed-off-by: Daraan <github.blurry@9ox.net>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Kamil Kaczmarek <kaczmarek.poczta@gmail.com>
Co-authored-by: Kamil Kaczmarek <kamil@anyscale.com>
0 commit comments