pytorch / rl

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

[BugFix] Fixed shape for MultiStep returns + Distributional loss #2270

Open roger-creus opened 5 days ago

roger-creus commented 5 days ago

Description

I encountered an error when combining MultiStep returns + Distributional DQN Loss. Because this line assumes discount is an integer but if using MultiStep returns it is a tensor of size (batch_size,).

This PR only changes that line to:

Tz = reward + (1 - terminated.to(reward.dtype)) * discount.unsqueeze(-1) * support.repeat(batch_size, 1)

which gives the same results if the discount is an integer but fixes the shape error if it is a batch.

Solves issue #2269

Types of changes

What types of changes does your code introduce? Remove all that do not apply:

Checklist

pytorch-bot[bot] commented 5 days ago

:link: Helpful Links

:test_tube: See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/2270

Note: Links to docs will display an error until the docs builds have been completed.

:x: 2 New Failures, 16 Pending, 5 Unrelated Failures

As of commit 5546b57ed668e422636385aeba01e0a6b72e9d06 with merge base 55f0a52ac7025c459dd71ec180c9c7d1c7576f9c (image):

NEW FAILURES - The following jobs have failed:

* [Lint / python-source-and-configs / linux-job](https://hud.pytorch.org/pr/pytorch/rl/2270#27147462189) ([gh](https://github.com/pytorch/rl/actions/runs/9813376043/job/27147462189)) `RuntimeError: Command docker exec -t 9709ca6a3e6a83901158002046e844c7621b2cbe9d1d530b2d179d6c822b92b2 /exec failed with exit code 1` * [Unit-tests on Linux / tests-cpu (3.9) / linux-job](https://hud.pytorch.org/pr/pytorch/rl/2270#27147463698) ([gh](https://github.com/pytorch/rl/actions/runs/9813376048/job/27147463698)) `RuntimeError: Command docker exec -t 372ddc3cbae4bfbfc1b1c802df394cbc5b2efad596b6627296164e66b744ea2b /exec failed with exit code 1`

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

* [Continuous Benchmark (PR) / CPU Pytest benchmark](https://hud.pytorch.org/pr/pytorch/rl/2270#27147458166) ([gh](https://github.com/pytorch/rl/actions/runs/9813376018/job/27147458166)) (detected as infra flaky with no log or failing log classifier) * [Wheels / build-wheel-linux (3.10, cp310-cp310, --index-url https://download.pytorch.org/whl/cpu, "['cpu', ...](https://hud.pytorch.org/pr/pytorch/rl/2270#27147461081) ([gh](https://github.com/pytorch/rl/actions/runs/9813376027/job/27147461081)) ([similar failure](https://hud.pytorch.org/pytorch/rl/commit/5546b57ed668e422636385aeba01e0a6b72e9d06#27147458166)) * [Wheels / build-wheel-linux (3.11, cp311-cp311, --index-url https://download.pytorch.org/whl/cpu, "['cpu', ...](https://hud.pytorch.org/pr/pytorch/rl/2270#27147462180) ([gh](https://github.com/pytorch/rl/actions/runs/9813376027/job/27147462180)) ([similar failure](https://hud.pytorch.org/pytorch/rl/commit/5546b57ed668e422636385aeba01e0a6b72e9d06#27147458166)) * [Wheels / build-wheel-linux (3.8, cp38-cp38, --index-url https://download.pytorch.org/whl/cpu, "['cpu', '11...](https://hud.pytorch.org/pr/pytorch/rl/2270#27147459169) ([gh](https://github.com/pytorch/rl/actions/runs/9813376027/job/27147459169)) ([similar failure](https://hud.pytorch.org/pytorch/rl/commit/5546b57ed668e422636385aeba01e0a6b72e9d06#27147458166)) * [Wheels / build-wheel-linux (3.9, cp39-cp39, --index-url https://download.pytorch.org/whl/cpu, "['cpu', '11...](https://hud.pytorch.org/pr/pytorch/rl/2270#27147460026) ([gh](https://github.com/pytorch/rl/actions/runs/9813376027/job/27147460026)) ([similar failure](https://hud.pytorch.org/pytorch/rl/commit/5546b57ed668e422636385aeba01e0a6b72e9d06#27147458166))

This comment was automatically generated by Dr. CI and updates every 15 minutes.

facebook-github-bot commented 5 days ago

Hi @roger-creus!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

facebook-github-bot commented 5 days ago

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!