Fix GaussianPosterior input whitening buffers to float64#88
Merged
Conversation
_input_mean and _input_std were initialised with the default dtype (float32), causing the float64 condition inputs to be silently downcast before whitening statistics were computed. This is inconsistent with the output-side buffers which are explicitly float64, and loses precision when the whitened value could still be computed precisely before the cast into the float32 MLP. Fix: initialise both buffers as float64, add them to the to() override so they survive .to(device) calls, and decouple the dtype cast — whitening now runs in float64, with an explicit cast to the MLP's dtype immediately before the net() call. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #88 +/- ##
=====================================
Coverage 9.72% 9.72%
=====================================
Files 33 33
Lines 4154 4154
=====================================
Hits 404 404
Misses 3750 3750
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Summary
_input_meanand_input_stdinGaussianPosteriorwere initialised without an explicit dtype, defaulting to float32. This caused float64 condition inputs to be silently downcast before whitening statistics were computed — inconsistent with the output-side buffers (_output_mean,_output_std,_residual_cov, etc.) which are all explicitly float64.dtype=torch.float64, and are added to theto()override so they survive.to(device)calls._forward_mean: whitening runs in float64, and the explicit cast to the MLP's dtype (next(self.net.parameters()).dtype, i.e. float32) happens only immediately beforeself.net(...).Precision pipeline before and after
(c - mean) / stdWhy it matters
The
_input_mean.dtypewas implicitly serving two roles: statistics precision and the gate cast into the float32 MLP. Making it float32 meant any catastrophic cancellation in the whitening step (e.g. conditions with large values and small variance, as inx = exp(z)withznear 5) was amplified before the MLP could even see the data. The fix separates the two concerns.Test plan
examples/04_gaussian:falcon launch -o output/run && falcon sample posterior -o output/run🤖 Generated with Claude Code