Skip to content

test: add unit tests for configs, base utilities, and torch layers#394

Open
ademakdogan wants to merge 1 commit intogoogle-research:masterfrom
ademakdogan:test/add-unit-tests-configs-utils
Open

test: add unit tests for configs, base utilities, and torch layers#394
ademakdogan wants to merge 1 commit intogoogle-research:masterfrom
ademakdogan:test/add-unit-tests-configs-utils

Conversation

@ademakdogan
Copy link
Copy Markdown

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 under src/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)

  • ForecastConfig frozen immutability and default value regression guard
  • dataclasses.replace independence (used in the compile path)
  • Structural equality semantics
  • ResidualBlockConfig, TransformerConfig, StackedTransformersConfig

tests/test_base_utils.py (16 tests)

  • strip_leading_nans: edge cases including all-NaN behavior
  • 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 verified against 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 (18 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

Quality Checks

  • ruff check tests/ — All checks passed
  • ruff format --check tests/ — All files formatted
  • pytest tests/ -v — 58 passed in <1s
  • No model checkpoint or GPU required
  • Apache 2.0 license headers matching existing source files
  • 2-space indent per pyproject.toml ruff config

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant