Keep normalization results floating point for integer inputs - #758
Open
catplotlib wants to merge 1 commit into
Open
catplotlib wants to merge 1 commit into
catplotlib wants to merge 1 commit into
Conversation
normalize_values_minmax, normalize_values_meanstd and
unnormalize_values_meanstd size their output with np.zeros_like(values),
which inherits an integer input dtype. The subsequent division is then
truncated on assignment, so an integer state or action array is silently
corrupted rather than normalized:
values [[5, 7]] in range [0, 10]
minmax -> [[-1, -1]] expected [[0.0, 0.4]]
meanstd -> [[ 0, 1]] expected [[0.333, 1.0]]
Every value collapses to the truncated result, with no warning. Pick a
float result type instead, preserving float32 inputs as float32 so the
common path keeps its dtype.
Add direct tests for the four normalization primitives, which had no
coverage: roundtrips for both schemes, the documented degenerate cases
(min == max, std == 0), per-step 2D bounds, batched inputs, and the
integer-dtype regressions above.
catplotlib
force-pushed
the
normalization-integer-dtype
branch
from
August 24, 2026 01:35
4affbb9 to
a6287cd
Compare
Author
|
Bumping this one — CI is green. Anything I can do to help move it along, or anyone I should tag? |
Author
|
Following up once more on this one. CI is green and the change is contained to the normalization helper, so it should be cheap to review. If it isn't a priority or the approach isn't what you want, that's completely fine - just say and I'll close it. |
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.
Changes proposed in this pull request:
gr00t/data/utils.pya floating-point result dtype, so integer inputs are no longer silently truncated.tests/gr00t/data/test_normalization_values.py, the first direct coverage for these four functions.The bug
normalize_values_minmax,normalize_values_meanstdandunnormalize_values_meanstdsize their output withnp.zeros_like(values), which inherits an integer input dtype. The division is then truncated on assignment, so an integer state or action array is silently corrupted rather than normalized:For min/max every value collapses to
-1, because the truncated0then goes through2 * 0 - 1. There is no warning; training or inference would just consume wrong numbers.Passing the same values as
float64gives the correct results, so the behaviour depends entirely on the caller's dtype.StateActionProcessorforwardsstate[joint_group]andaction[joint_group]straight into these functions without casting, and only one dataset path (sharded_single_step_dataset.py) casts tofloat32on the way in.To be clear about severity: every dataset shipped in
demo_data/declaresdtype=float32, so I do not believe this is reachable through the datasets in this repo today. It is a latent trap for anyone feeding integer-valued state or action features — discrete grippers, mode flags, indices.The fix uses
np.result_type(values, np.float32), which keepsfloat32inputs asfloat32(no upcast on the common path) and promotes integers tofloat64.Tests
normalize_values_*had no direct tests, so the new file covers the primitives rather than only the regression:min == max→ 0,std == 0→ pass through)(B, T, D)inputsfloat32/float64preserved14 passed with this change. With the
utils.pychange reverted, the 3 dtype tests fail and the other 11 still pass, so the new coverage documents existing behaviour and only the regressions are new.Wider suite on this branch:
pytest tests/gr00t/data/ -m "not gpu"gives 213 passed. The 3 failures intest_dataset_factory.pyand the collection error intest_embodiment_tags.pyare pre-existing — they reproduce identically with this change stashed, and both come from an unrelatednon-default argument 'diffusion_model_cfg' follows default argumenterror in my environment.No new dependencies: the tests use seeded
numpyrather than adding a property-testing library.Before submitting
CONTRIBUTINGdocs.