TimesFM (Time Series Foundation Model) is a pretrained time-series foundation model developed by Google Research for time-series forecasting.
Python
fix(timesfm3): keep old top-level import paths working after the torch move
rachittshahfea9c86dd0c2
diff --git a/src/timesfm3/backward_compat_test.py b/src/timesfm3/backward_compat_test.pynew file mode 100644index 0000000..c3af8c1--- /dev/null+++ b/src/timesfm3/backward_compat_test.py@@ -0,0 +1,69 @@+# Copyright 2026 Google LLC+#+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.++"""The PyTorch backend moved into ``timesfm3.torch``; the old top-level import+paths (``from timesfm3.model import ...``) must keep working via thin shims.+These need PyTorch, so the module is skipped when it is not installed.+"""++import importlib+import unittest+++def _torch_available() -> bool:+ try:+ import torch # noqa: F401++ return True+ except ImportError:+ return False++[email protected](_torch_available(), "torch backend not installed")+class BackwardCompatImportTest(unittest.TestCase):+ """Legacy `timesfm3.<module>` import paths still resolve to the torch backend."""++ def test_legacy_named_imports(self):+ from timesfm3.timesfm3_forecaster import TimesFM3Forecaster+ from timesfm3.model import TimesFM3Torch+ from timesfm3.configs import TransformerConfig+ from timesfm3.evaluator import TimesFM3Evaluator++ from timesfm3.torch.timesfm3_forecaster import (+ TimesFM3Forecaster as _CanonForecaster,+ )+ from timesfm3.torch.model import TimesFM3Torch as _CanonTorch++ self.assertIs(TimesFM3Forecaster, _CanonForecaster)+ self.assertIs(TimesFM3Torch, _CanonTorch)+ self.assertTrue(TransformerConfig and TimesFM3Evaluator)++ def test_every_moved_module_is_importable(self):+ for name in (+ "configs",+ "cpm_revin_refine",+ "dense",+ "evaluator",+ "model",+ "normalization",+ "timesfm3_forecaster",+ "transformations",+ "transformer",+ "util",+ ):+ importlib.import_module(f"timesfm3.{name}")+++if __name__ == "__main__":+ unittest.main()diff --git a/src/timesfm3/configs.py b/src/timesfm3/configs.pynew file mode 100644index 0000000..74ac900--- /dev/null+++ b/src/timesfm3/configs.py@@ -0,0 +1,22 @@+# Copyright 2026 Google LLC+#+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.++"""Backward-compatibility shim for ``timesfm3.configs``.++The PyTorch backend moved to ``timesfm3.torch.configs``. This re-exports it so that+existing ``from timesfm3.configs import ...`` imports keep working; new code should+import from ``timesfm3.torch.configs`` (or the top-level ``timesfm3`` API).+"""++from .torch.configs import * # noqa: F401,F403diff --git a/src/timesfm3/cpm_revin_refine.py b/src/timesfm3/cpm_revin_refine.pynew file mode 100644index 0000000..a4bfd3d--- /dev/null+++ b/src/timesfm3/cpm_revin_refine.py@@ -0,0 +1,22 @@+# Copyright 2026 Google LLC+#+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.++"""Backward-compatibility shim for ``timesfm3.cpm_revin_refine``.++The PyTorch backend moved to ``timesfm3.torch.cpm_revin_refine``. This re-exports it so that+existing ``from timesfm3.cpm_revin_refine import ...`` imports keep working; new code should+import from ``timesfm3.torch.cpm_revin_refine`` (or the top-level ``timesfm3`` API).+"""++from .torch.cpm_revin_refine import * # noqa: F401,F403diff --git a/src/timesfm3/dense.py b/src/timesfm3/dense.pynew file mode 100644index 0000000..089cb13--- /dev/null+++ b/src/timesfm3/dense.py@@ -0,0 +1,22 @@+# Copyright 2026 Google LLC+#+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.++"""Backward-compatibility shim for ``timesfm3.dense``.++The PyTorch backend moved to ``timesfm3.torch.dense``. This re-exports it so that+existing ``from timesfm3.dense import ...`` imports keep working; new code should+import from ``timesfm3.torch.dense`` (or the top-level ``timesfm3`` API).+"""++from .torch.dense import * # noqa: F401,F403diff --git a/src/timesfm3/evaluator.py b/src/timesfm3/evaluator.pynew file mode 100644index 0000000..cb28bfb--- /dev/null+++ b/src/timesfm3/evaluator.py@@ -0,0 +1,22 @@+# Copyright 2026 Google LLC+#+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.++"""Backward-compatibility shim for ``timesfm3.evaluator``.++The PyTorch backend moved to ``timesfm3.torch.evaluator``. This re-exports it so that+existing ``from timesfm3.evaluator import ...`` imports keep working; new code should+import from ``timesfm3.torch.evaluator`` (or the top-level ``timesfm3`` API).+"""++from .torch.evaluator import * # noqa: F401,F403diff --git a/src/timesfm3/model.py b/src/timesfm3/model.pynew file mode 100644index 0000000..c26162d--- /dev/null+++ b/src/timesfm3/model.py@@ -0,0 +1,22 @@+# Copyright 2026 Google LLC+#+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.++"""Backward-compatibility shim for ``timesfm3.model``.++The PyTorch backend moved to ``timesfm3.torch.model``. This re-exports it so that+existing ``from timesfm3.model import ...`` imports keep working; new code should+import from ``timesfm3.torch.model`` (or the top-level ``timesfm3`` API).+"""++from .torch.model import * # noqa: F401,F403diff --git a/src/timesfm3/normalization.py b/src/timesfm3/normalization.pynew file mode 100644index 0000000..be0ebb2--- /dev/null+++ b/src/timesfm3/normalization.py@@ -0,0 +1,22 @@+# Copyright 2026 Google LLC+#+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.++"""Backward-compatibility shim for ``timesfm3.normalization``.++The PyTorch backend moved to ``timesfm3.torch.normalization``. This re-exports it so that+existing ``from timesfm3.normalization import ...`` imports keep working; new code should+import from ``timesfm3.torch.normalization`` (or the top-level ``timesfm3`` API).+"""++from .torch.normalization import * # noqa: F401,F403diff --git a/src/timesfm3/timesfm3_forecaster.py b/src/timesfm3/timesfm3_forecaster.pynew file mode 100644index 0000000..e08716c--- /dev/null+++ b/src/timesfm3/timesfm3_forecaster.py@@ -0,0 +1,22 @@+# Copyright 2026 Google LLC+#+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.++"""Backward-compatibility shim for ``timesfm3.timesfm3_forecaster``.++The PyTorch backend moved to ``timesfm3.torch.timesfm3_forecaster``. This re-exports it so that+existing ``from timesfm3.timesfm3_forecaster import ...`` imports keep working; new code should+import from ``timesfm3.torch.timesfm3_forecaster`` (or the top-level ``timesfm3`` API).+"""++from .torch.timesfm3_forecaster import * # noqa: F401,F403diff --git a/src/timesfm3/transformations.py b/src/timesfm3/transformations.pynew file mode 100644index 0000000..8e27495--- /dev/null+++ b/src/timesfm3/transformations.py@@ -0,0 +1,22 @@+# Copyright 2026 Google LLC+#+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.++"""Backward-compatibility shim for ``timesfm3.transformations``.++The PyTorch backend moved to ``timesfm3.torch.transformations``. This re-exports it so that+existing ``from timesfm3.transformations import ...`` imports keep working; new code should+import from ``timesfm3.torch.transformations`` (or the top-level ``timesfm3`` API).+"""++from .torch.transformations import * # noqa: F401,F403diff --git a/src/timesfm3/transformer.py b/src/timesfm3/transformer.pynew file mode 100644index 0000000..9ca894b--- /dev/null+++ b/src/timesfm3/transformer.py@@ -0,0 +1,22 @@+# Copyright 2026 Google LLC+#+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.++"""Backward-compatibility shim for ``timesfm3.transformer``.++The PyTorch backend moved to ``timesfm3.torch.transformer``. This re-exports it so that+existing ``from timesfm3.transformer import ...`` imports keep working; new code should+import from ``timesfm3.torch.transformer`` (or the top-level ``timesfm3`` API).+"""++from .torch.transformer import * # noqa: F401,F403diff --git a/src/timesfm3/util.py b/src/timesfm3/util.pynew file mode 100644index 0000000..c9c3105--- /dev/null+++ b/src/timesfm3/util.py@@ -0,0 +1,22 @@+# Copyright 2026 Google LLC+#+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.++"""Backward-compatibility shim for ``timesfm3.util``.++The PyTorch backend moved to ``timesfm3.torch.util``. This re-exports it so that+existing ``from timesfm3.util import ...`` imports keep working; new code should+import from ``timesfm3.torch.util`` (or the top-level ``timesfm3`` API).+"""++from .torch.util import * # noqa: F401,F403