Closed avacaondata closed 2 years ago
@alexvaca0, I'm running into the same problem. Did You manage to solve it somehow? Thank You
same problem here, any solution yet?
I'm not sure yet, but I think the reasons I get this error is because my (custom) environment use a multi dimensional observations space:
self.observation_space=Box(-1.0,1.0,(8,7))
Moving to stable-baselines3
, I discovered that most of the algorithms use in rl
support only flatten spaces (in the library there's a check_env
utility function).
I have modify my environment accordingly and in stable-baselines3
now it work just fine.
I suspect that if I test it on ray
it will work just as well but I have not tested it yet.
I hope this may help You
I'm not sure yet, but I think the reasons I get this error is because my (custom) environment use a multi dimensional observations space:
self.observation_space=Box(-1.0,1.0,(8,7))
Moving to
stable-baselines3
, I discovered that most of the algorithms use inrl
support only flatten spaces (in the library there's acheck_env
utility function).I have modify my environment accordingly and in
stable-baselines3
now it work just fine.I suspect that if I test it on
ray
it will work just as well but I have not tested it yet.I hope this may help You
@easysoft2k15 you are partially right, in my experiments: Ray does not work with multi dimentional observation spaces, unless you use "conv_filters", as per documentaiton here: the bug we see here is due to Torch moving tensors from GPU to CPU which is causing the issue when you train on CPU and GPU, so when i disabled GPU and trained only on CPU all went well.
thanks! flattening the observation fixed the problem
Yeah, it seems if you have any observations like gym.spaces.Box(shape=(2, 1))
, you will get this error. Making this gym.spaces.Box(shape=(2,))
fixes the problem. IMO this is a very confusing bug for a common use case. Why does the observation space mess with the underlying torch.device
? @sven1977 maybe we should assert that all spaces are flattened or something?
This problem was solved for me by pip install ray[default,tune,rllib,serve]==1.9.2
Hope it helps!
This problem was solved for me by pip install ray[default,tune,rllib,serve]==1.9.2
Hope it helps!
This works, it seems like the built-in ModelV2
had some problems with non-flat observations. In my case, I also got the same error, as I forgot to define the custom_model
(-> fallback to the built-in model) in the trainer config. There are a couple of solutions: defining a custom model, which flattens the input space or can handle your multidimensional observations, or writing a Gym.Wrapper for flattening observations.
This is a real bug in ray/rllib/models/torch/complex_input_net.py
, and has been fixed in the master branch. I independently made the same changes as this commit, and they fixed my problem.
https://github.com/ray-project/ray/commit/a598458c464b88535e711ef7ef55f88e25c1820f
The problem inComplexInputNetwork
was that the Torch sub-modules for "one-hot" and "flatten" were not all being registered, so their parameters were not moved to GPU.
the bug we see here is due to Torch moving tensors from GPU to CPU which is causing the issue when you train on CPU and GPU, so when i disabled GPU and trained only on CPU all went well.
Not using the GPU won't work for me unfortunately (need it for speed)... is there any fix for this which includes being able to use the GPU? Do I need to flatten the observations... if so, how do I do this? Do I flatten them before they're fed to the network... how does this work when I am using CNNs?
Search before asking
Ray Component
Ray Tune, RLlib
What happened + What you expected to happen
When trying a RLLib experiment following these guidelines: https://www.tensortrade.org/en/latest/examples/train_and_evaluate_using_ray.html with this config: ` tune.run( run_or_experiment="PPO", # We'll be using the builtin PPO agent in RLLib name="MyExperiment1", metric='episode_reward_mean', mode='max',
resources_per_trial= {"cpu": 8, "gpu": 1},
` I encountered the following error:
I would expect tensors to be placed on the same device.
Versions / Dependencies
OS: Windows 10 Ray: 2.0.0.dev0 Python: 3.8 Torch: 1.10.1 CUDA: 11.4
Reproduction script
https://www.tensortrade.org/en/latest/examples/train_and_evaluate_using_ray.html
Anything else
No response
Are you willing to submit a PR?