Repository navigation
Conversation
exp(temperature * advantage) overflows float32 above ~88.7 and underflows below ~-103.9, so the normalized weights became inf/inf or 0/0 and the planner returned NaN actions. Subtracting the max leaves the normalized weights unchanged. Fixes pytorch#4717.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/4721
Note: Links to docs will display an error until the docs builds have been completed.
|
|
Hi @Aarav500! Thank you for your pull request and welcome to our community. Action RequiredIn 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. ProcessIn 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 If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Description
MPPIPlanner.planningcomputed the top-k weights as(self.temperature * vals).exp()and then normalized them by their sum. In float32,expoverflows above about 88.7 and underflows below about -103.9, so the normalization became inf/inf or 0/0 and the planner returned NaN actions.This subtracts the max of
temperature * valsover the top-k dimension beforeexp. The weights are normalized right after, so their values don't change when nothing overflows.TdMpc2Planneralready does the same.Test:
test_MPPI_advantage_offset_invariantshifts every advantage by +200 and by -200 and checks that the plan equals the unshifted one, since MPPI weights are a softmax and can't depend on a constant offset. Before the fix both cases return NaN; after it they match.The issue's Pendulum reproduction, before and after:
pytest test/modules/test_planners.py: 24 passed, 6 skipped (Hydra not installed), CPU only.ufmt checkandflake8 --config=setup.cfgpass on both files with the versions pinned in.pre-commit-config.yaml.AI disclosure: the change, the test and this description were written by Claude (an AI assistant) working for me, and run on my machine.
Motivation and Context
close #4717 (an existing issue, filed by someone else)
Types of changes
Checklist