You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix TanhNormal.rsample() -> log_prob() when finite-precision tanh saturation prevents atanh(action) from recovering the generating preimage, corrupting SAC scores and gradients.
TanhNormal now retains one forward-produced preimage and reuses it only for its unchanged sample. External or mutated values use the ordinary inverse path, and update() clears the cache. Compilation, inference, and CUDA capture validate the sample through a tensor snapshot. There are no clamps, flags, or training-specific defaults.
Testing
Direct final-head checks: main misses the score by 16,312 and the scale gradient by 165,992; this PR is within 7.63e-6 and 9.54e-7 in eager, Dynamo eager, and Inductor.
Matched MultiWalker SAC, 3 seeds × 2M frames: every main run develops score corruption and exploding losses; corrected runs keep score error at 0.0 and raw critic loss at or below 23.6. E2E ran at efb3a592b; final head only adds the CUDA-capture dispatch validated below.
Final head be7a48dba: focused H100 18 passed; distributions 974 passed; pre-commit passes. Objectives at the behavior-identical E2E head: 7528 passed, 2324 skipped, 6 deselected.
Safe/unsafe tanh with ordinary/custom bounds passes inference and CUDA graph within 7.63e-6; scale-gradient error is at most 4.55e-7, with zero allocated-memory growth across 20,000 iterations.
The cached sample keeps its generating loc/scale gradient path. Cloned and external actions retain ordinary action gradients.
Note: Links to docs will display an error until the docs builds have been completed.
✅ No Failures
As of commit be7a48d with merge base d7659c7 ():
💚 Looks good so far! There are no failures yet. 💚
This comment was automatically generated by Dr. CI and updates every 15 minutes.
meta-claBot
added
the
CLA Signed
This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
label
Aug 9, 2026
gtnv
changed the title
[BugFix] Fix TanhNormal sample scoring at finite-precision saturation
[BugFix] Fix TanhNormal sample scoring at tanh saturation
Aug 9, 2026
Reviewed latest head be7a48dba7, including the CUDA-capture follow-up commit and the current approval. The single-sample cache is invalidated on update(), detects eager in-place mutation via tensor versioning, uses a snapshot for compile/inference/capture paths, and falls back to the ordinary inverse path for external or stale samples; custom affine bounds are included because the composed transform is cached as a whole. The focused eager/compiled consistency and invalidation matrix passes locally (18 passed), and git diff --check is clean. No blocking finding from this review; the remaining platform-specific coverage is the CUDA-capture path already described in the PR.
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
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
Fix
TanhNormal.rsample() -> log_prob()when finite-precision tanh saturation preventsatanh(action)from recovering the generating preimage, corrupting SAC scores and gradients.TanhNormalnow retains one forward-produced preimage and reuses it only for its unchanged sample. External or mutated values use the ordinary inverse path, andupdate()clears the cache. Compilation, inference, and CUDA capture validate the sample through a tensor snapshot. There are no clamps, flags, or training-specific defaults.Testing
mainmisses the score by16,312and the scale gradient by165,992; this PR is within7.63e-6and9.54e-7in eager, Dynamo eager, and Inductor.mainrun develops score corruption and exploding losses; corrected runs keep score error at0.0and raw critic loss at or below23.6. E2E ran atefb3a592b; final head only adds the CUDA-capture dispatch validated below.be7a48dba: focused H10018 passed; distributions974 passed; pre-commit passes. Objectives at the behavior-identical E2E head:7528 passed, 2324 skipped, 6 deselected.7.63e-6; scale-gradient error is at most4.55e-7, with zero allocated-memory growth across 20,000 iterations.The cached sample keeps its generating loc/scale gradient path. Cloned and external actions retain ordinary action gradients.
Closes #2199
cc @vmoens @theap06