Repository navigation
[BugFix] Keep the first element of the discount series in _geom_series_like when gamma * lmbda is 0 or below the threshold - #4502
Draft
Nicholas022400701 wants to merge 3 commits into
Conversation
Sync main with upstream
Sync main with pytorch/rl
…mbda is 0 or below the threshold Fixes pytorch#4489
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/4502
Note: Links to docs will display an error until the docs builds have been completed.
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
_geom_series_like(torchrl/objectives/value/functional.py) returned a 1Dzeros_like(t)forr == 0.0, skipping thers[0] = 1.0and theunsqueeze(-1)below it, so_custom_conv1dgot a 1D filter and raisedIndexError: tuple index out of range; for0 < r < thrit computedlim = int(log(thr) / log(r)) == 0, sot[:lim]was empty andrs[0] = 1.0raisedIndexError: index 0 is out of bounds for dimension 0 with size 0.risgamma * lmbdain_fast_vec_gaeand_fast_td_lambda_return_estimateandgammainreward2go, sovec_generalized_advantage_estimate(gamma, 0.0, ...),GAE(lmbda=0.0, vectorized=True),TDLambdaEstimator(lmbda=0.0)(vectorized by default) andreward2go(gamma=0.0)all crashed, while the non-vectorizedgeneralized_advantage_estimatereturned the TD(0) advantage.The series now always keeps its first element:
r ** 0is 1 whateverr, solim = max(int(log(thr) / log(r)), 1), andr == 0islim = 1(the series is[1, 0, 0, ...], a single-tap filter that makes_custom_conv1dthe identity). Ther >= 1.0branch is unchanged.Checked on
mainb8b6f0c (the patch applies unchanged to a4592ec) with 3 trajectories of 8 steps, float64, gamma 0.9, randomdonewith aterminatedsubset: vectorized and non-vectorized GAE match exactly atlmbda=0and to 3.3e-9 atlmbda=1e-9;vec_td_lambda_return_estimatematchestd_lambda_return_estimateto 6e-8 (the same gap as atlmbda=0.5, from the float32gamma_tensorthere);reward2go(gamma=0)equals the reward.pytest test/objectives/test_values.py -k "test_gae or tdlambda or reward2go": 1833 passed. The newtest_vec_estimates_zero_lmbda(lmbda0.0 and 1e-9) fails onmainwith the two errors above and passes here.Draft until a maintainer confirms the direction in #4489; I will mark it ready for review then.
Motivation and Context
Fixes #4489.
lmbda=0is the TD(0) advantage andgamma=0reward-to-go is the reward itself; the vectorized paths should return what the non-vectorized ones return.Types of changes
Checklist
AI disclosure: I used an AI coding agent to help write this patch, the tests and this description. I have read the change and the tests myself and I will answer review comments personally.