pytorch / rl

A modular, primitive-first, python-first PyTorch library for Reinforcement Learning.
https://pytorch.org/rl
MIT License
2.24k stars 296 forks source link

Not knowing Which key is causing shape mismatch #2222

Closed aminrezaee closed 3 months ago

aminrezaee commented 3 months ago

Hi there. I'm having problems with my environment rollout. Sometimes my environment shapes are changing somehow. If in the except block I'm going to mention, you don't set any type for the exception it would be much better. Because alongside the exception about shape mismatch another exception would raise saying which key caused this problem. here is the line I'm suggesting to change: https://github.com/pytorch/rl/blob/3787a9edeea03cb9e98b928824072b939c327776/torchrl/data/tensor_specs.py#L3978C20-L3978C28 and here is the line a raising shape mismatch: https://github.com/pytorch/rl/blob/3787a9edeea03cb9e98b928824072b939c327776/torchrl/data/tensor_specs.py#L587

note that if the shapes of observations are different currently just the shape mismatch exception would be raised due to different exception types.

vmoens commented 3 months ago

Sometimes my environment shapes are changing somehow

Is this expected? We have allowed dynamic shapes in nightlies, it will be part of the next major release. You can just set -1 to the shapes that should change.

RE your suggestion: what about capturing this RuntimeError separately, and tell user which key is the culprit of the shape mismatch?

aminrezaee commented 3 months ago

Is this expected?

No. The changes of shapes aren't desired. My codes are having a bug.

what about capturing this RuntimeError separately

I agree. That would be nicer.

vmoens commented 3 months ago

Ok I guess my initial understanding was that you were expecting your shapes to change and wanted to work around the exceptions, I now understand that the problem is that the exception are not informative enough I can patch that quickly! If you can think of anything else that would help you debug this sort of situation I'd be happy to help