Open PhilippWillms opened 3 months ago
Got the error below with version 2.9.2, might due to the same issue. What is the version that works with the correct encoder config supporting MultiDiscrete obs space?
ValueError: No default encoder config for obs space=MultiDiscrete([2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2]), lstm=False and attention=False found.
@simonsays1980 , @sven1977 : Any update on this issue? Can you probably give an outlook when it will be fixed? Thank you very much!
@simonsays1980 It appears that the pull request https://github.com/ray-project/ray/pull/46146 doesn't fully resolve the observation wrapper issue. Nonetheless, I've built my work (action masking with the new API) on that pull request, so thank you for your contribution. @PhilippWillms, you're correct, the issue at https://github.com/ray-project/ray/issues/46631 is very similar to this one. Have you found a solution?
@simonsays1980 It appears that the pull request #46146 doesn't fully resolve the observation wrapper issue. Nonetheless, I've built my work (action masking with the new API) on that pull request, so thank you for your contribution. @PhilippWillms, you're correct, the issue at #46631 is very similar to this one. Have you found a solution?
No, I continue to use old API stack at the moment.
@simonsays1980 It appears that the pull request #46146 doesn't fully resolve the observation wrapper issue. Nonetheless, I've built my work (action masking with the new API) on that pull request, so thank you for your contribution. @PhilippWillms, you're correct, the issue at #46631 is very similar to this one. Have you found a solution?
No, I continue to use old API stack at the moment.
I'm exploring the possibility of using a custom CNNEncoder as it's the only viable option. The most viable implementation being close to:
import torch
import torch.nn as nn
import numpy as np
from gymnasium.spaces import Box
# Define the observation space
window_size = 1000
n_features = 50
box = Box(
low=-np.inf,
high=np.inf,
shape=(window_size, n_features),
dtype=np.float32,
)
class ConvObservationEncoder(nn.Module):
def __init__(self, input_shape, output_dim):
super(ConvObservationEncoder, self).__init__()
self.conv1 = nn.Conv1d(in_channels=input_shape[1], out_channels=64, kernel_size=3, stride=1, padding=1)
self.conv2 = nn.Conv1d(in_channels=64, out_channels=128, kernel_size=3, stride=1, padding=1)
self.flatten = nn.Flatten()
self.linear = nn.Linear(128 * input_shape[0], output_dim)
def forward(self, x):
x = x.permute(0, 2, 1) # Change shape to (batch_size, n_features, window_size)
x = self.conv1(x)
x = nn.ReLU()(x)
x = self.conv2(x)
x = nn.ReLU()(x)
x = self.flatten(x)
x = self.linear(x)
return x
# Example usage
input_shape = box.shape
output_dim = 128 # Example output dimension
encoder = ConvObservationEncoder(input_shape, output_dim)
# Create a dummy observation
observation = np.random.rand(*input_shape).astype(np.float32)
observation_tensor = torch.tensor(observation).unsqueeze(0) # Add batch dimension
# Encode the observation
encoded_observation = encoder(observation_tensor)
print(encoded_observation.shape) # Should print: torch.Size([1, 128])
In this code:
This approach can be more efficient and effective, especially if your observations have spatial or temporal dependencies as is my case. Of course, I'll have to make further mods to ensure that it fits RLlib's new API stack
What happened + What you expected to happen
The new API stack for RLlib seems to have challenges with observation wrappers, which are quite handy for action masking models. Unlike #44452, it is now the
SingleAgentEnvRunner
finding no default encoder config for the 2D box space. This error message sounds familiar, however, in the stable RLlib stack this topic was overcome by using a wrapper. This wrapper does not seem to be recognized correctly.Versions / Dependencies
Python==3.10.13 ray==3.0.0.dev0 gymnasium==0.28.1 numpy==1.24.4 torch==2.2.1+cu121 tensorflow==2.16.1 Windows 11
Reproduction script
Issue Severity
High: It blocks me from completing my task.