-
Notifications
You must be signed in to change notification settings - Fork 329
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
[BugFix] patch rand_action in TransformedEnv to read the base_env method #2699
base: gh/vmoens/68/base
Are you sure you want to change the base?
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/2699
Note: Links to docs will display an error until the docs builds have been completed. ❌ 13 New Failures, 5 Unrelated FailuresAs of commit 1024d61 with merge base 319bb68 (): NEW FAILURES - The following jobs have failed:
BROKEN TRUNK - The following jobs failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
@kurtamohler I'm not super happy with this, as the comment says it's far from accounting for transforms that do some kind of inverse mapping but the point is that without that, a transformed chess env cannot generate random actions (because the |
# env = PendulumEnv().append_transform(ActionDiscretizer(num_intervals=4)) | ||
# env.rand_action will NOT have a discrete action! | ||
# Getting a discrete action would require coding the inverse transform of an action within | ||
# ActionDiscretizer (ie, float->int, not int->float). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason we couldn't use self.action_spec.rand()
?
>>> import torchrl
>>> env = torchrl.envs.PendulumEnv().append_transform(torchrl.envs.ActionDiscretizer(num_intervals=4))
>>> env.action_spec.rand()
tensor([3])
>>> env.action_spec.rand().dtype
torch.int64
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, what I meant with that comment is that if your base env redefines the rand_action
then the action you'll get won't be transformed
import torchrl
Pendulum = torchrl.envs.PendulumEnv
rand_action = Pendulum.rand_action
Pendulum.rand_action = lambda *args, **kwargs: rand_action(*args, **kwargs)
env = Pendulum().append_transform(torchrl.envs.ActionDiscretizer(num_intervals=4))
print(env.action_spec.rand())
print(env.action_spec.rand().dtype)
print(env.rand_action())
which prints
tensor([3])
torch.int64
TensorDict(
fields={
action: Tensor(shape=torch.Size([1]), device=cpu, dtype=torch.float32, is_shared=False)},
batch_size=torch.Size([]),
device=None,
is_shared=False)
Stack from ghstack (oldest at bottom):