rl icon indicating copy to clipboard operation
rl copied to clipboard

[BUG] IndependentNormal ignores tanh_loc during construction

Open resonance-null opened this issue 1 month ago • 1 comments

At main 37ac1bd07d6633742b1bc208d53b03c91ce22b30, IndependentNormal(..., tanh_loc=True) leaves the location unchanged on construction, but .update() applies the documented upscale * tanh(loc / upscale) transform. Consequently, a freshly constructed policy distribution has different action means and log probabilities from the same distribution after an identical parameter update. SafeProbabilisticModule with its default deterministic interaction also emits the unscaled location as its action.

import torch
from torchrl.modules import IndependentNormal

loc = torch.tensor([[10.0, -10.0]], dtype=torch.float64)
scale = torch.ones_like(loc)
dist = IndependentNormal(loc, scale, tanh_loc=True, upscale=5.0)
print(dist.mean)  # [[10., -10.]]
dist.update(loc, scale)
print(dist.mean)  # [[4.8201, -4.8201]]

Both means should equal 5 * tanh(loc / 5), as stated by the distribution's location-scaling contract and as already implemented by update. The constructor should share that existing initialization path. A regression should check means, Gaussian log-probabilities and location gradients against independently calculated values, with location scaling enabled/disabled and supported scale input forms.

Reproduced with Python 3.13.7, official torch 2.11.0+cpu, tensordict 0.15.2, current unmodified TorchRL source imported normally. No CUDA, simulator, model weights or optional backend. The unavailable C++ replay-buffer extension does not participate in this distribution path.

Searches on 2026-11-01 for open IndependentNormal and location scaling issues/PRs returned no matching open items; a historical TruncatedNormal documentation issue #1202 describes a different defect. No issue has been filed and no assignment claimed by the local worker.

AI assistance: OpenAI Codex performed this source investigation and local reproduction with synthetic inputs. No human review or upstream approval is claimed.

Checklist

  • [x] I have checked that there is no similar issue in the repo (required)
  • [x] I have read the relevant distribution documentation (required)
  • [x] I have provided a minimal working example to reproduce the bug (required)

resonance-null avatar Oct 31 '26 23:10 resonance-null

/assign

resonance-null avatar Oct 31 '26 23:10 resonance-null