test: add unit tests for configs, base utilities, and torch layers#394
Open
ademakdogan wants to merge 1 commit intogoogle-research:masterfrom
Open
test: add unit tests for configs, base utilities, and torch layers#394ademakdogan wants to merge 1 commit intogoogle-research:masterfrom
ademakdogan wants to merge 1 commit intogoogle-research:masterfrom
Conversation
Add comprehensive test suite for TimesFM v2.5 components that previously had no test coverage. All 58 tests run on CPU without model checkpoint. tests/test_configs.py (11 tests): - ForecastConfig frozen immutability and default value regression guard - dataclasses.replace independence (used in compile path) - Structural equality semantics - ResidualBlockConfig, TransformerConfig, StackedTransformersConfig tests/test_base_utils.py (16 tests): - strip_leading_nans: edge cases including all-NaN behavior documentation (actual behavior differs from docstring — returns full array, not empty) - linear_interpolation: interior/leading/trailing NaN filling, monotonicity preservation, single-value extrapolation, output NaN-freedom guarantee tests/test_torch_utils.py (14 tests): - update_running_stats: mathematical correctness vs numpy, incremental accumulation equivalence, masked element exclusion, batch independence, constant-input zero-sigma - revin: forward/reverse identity invariant, zero-sigma NaN guard, tolerance threshold, 3D and 4D broadcasting matching actual decode shapes - DecodeCache: mutability contract, key/value shape consistency tests/test_torch_layers.py (17 tests): - ResidualBlock: output shapes (2D/3D), residual path isolation, gradient flow through both paths, all activations, invalid activation rejection - RMSNorm: zero-scale initialization property, unit-scale RMS magnitude, zero-input NaN safety - RandomFourierFeatures: output shape, dim%4 constraint, numerical bounds
darkpowerxo
added a commit
to darkpowerxo/timesfm
that referenced
this pull request
Apr 8, 2026
Apply changes from PR google-research#394 by @cj-wong: - tests/__init__.py: package marker - tests/test_base_utils.py: strip_leading_nans + linear_interpolation tests - tests/test_configs.py: frozen dataclass, defaults, replace, equality tests - tests/test_torch_layers.py: ResidualBlock, RMSNorm, RandomFourierFeatures - tests/test_torch_utils.py: update_running_stats, revin, DecodeCache tests Co-authored-by: cj-wong <cj-wong@users.noreply.github.com>
darkpowerxo
added a commit
to darkpowerxo/timesfm
that referenced
this pull request
Apr 8, 2026
Apply changes from PR google-research#394 by @cj-wong: - tests/__init__.py: package marker - tests/test_base_utils.py: strip_leading_nans + linear_interpolation tests - tests/test_configs.py: frozen dataclass, defaults, replace, equality tests - tests/test_torch_layers.py: ResidualBlock, RMSNorm, RandomFourierFeatures - tests/test_torch_utils.py: update_running_stats, revin, DecodeCache tests
darkpowerxo
added a commit
to darkpowerxo/timesfm
that referenced
this pull request
Apr 8, 2026
Apply changes from PR google-research#394 by @cj-wong: - tests/__init__.py: package marker - tests/test_base_utils.py: strip_leading_nans + linear_interpolation tests - tests/test_configs.py: frozen dataclass, defaults, replace, equality tests - tests/test_torch_layers.py: ResidualBlock, RMSNorm, RandomFourierFeatures - tests/test_torch_utils.py: update_running_stats, revin, DecodeCache tests
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
Add a comprehensive test suite for TimesFM v2.5 components that previously had no test coverage. All 58 tests run on CPU without requiring a model checkpoint and complete in under 1 second.
Motivation
The current test suite (
v1/tests/test_timesfm.py) only covers the archived v1 API. The v2.5 source code undersrc/timesfm/— including configs, NaN-handling utilities, running statistics, RevIN normalization, and layer building blocks — has zero test coverage. These functions sit on the critical inference path; silent regressions here would manifest as degraded forecast quality rather than immediate errors.What's Tested
tests/test_configs.py(10 tests)ForecastConfigfrozen immutability and default value regression guarddataclasses.replaceindependence (used in the compile path)ResidualBlockConfig,TransformerConfig,StackedTransformersConfigtests/test_base_utils.py(16 tests)strip_leading_nans: edge cases including all-NaN behaviorlinear_interpolation: interior/leading/trailing NaN filling, monotonicity preservation, single-value extrapolation, output NaN-freedom guaranteetests/test_torch_utils.py(14 tests)update_running_stats: mathematical correctness verified against NumPy, incremental accumulation equivalence, masked element exclusion, batch independence, constant-input zero-sigmarevin: forward/reverse identity invariant, zero-sigma NaN guard, tolerance threshold, 3D and 4D broadcasting matching actual decode shapesDecodeCache: mutability contract, key/value shape consistencytests/test_torch_layers.py(18 tests)ResidualBlock: output shapes (2D/3D), residual path isolation, gradient flow through both paths, all activations, invalid activation rejectionRMSNorm: zero-scale initialization property, unit-scale RMS magnitude, zero-input NaN safetyRandomFourierFeatures: output shape,dim % 4constraint, numerical boundsQuality Checks
ruff check tests/— All checks passedruff format --check tests/— All files formattedpytest tests/ -v— 58 passed in <1spyproject.tomlruff config