transformers icon indicating copy to clipboard operation
transformers copied to clipboard

fix(timesfm2_5): correct method name in window_size moving average call

Open muhamedfazalps opened this issue 5 months ago • 4 comments

Summary

Fixes #46821

When calling TimesFm2_5ModelForPrediction with a window_size parameter, an AttributeError is raised because the forward method calls self._timesfm_moving_average() but the actual @staticmethod is named _timesfm2_5_moving_average().

Root Cause

The method was likely renamed during the TimesFM 2.5 integration (from the original timesfm naming to timesfm2_5 for namespace consistency), but the call site in forward() was not updated to match.

Fix

Changed self._timesfm_moving_average(ts, window_size) to self._timesfm2_5_moving_average(ts, window_size) in both:

  • modeling_timesfm2_5.py (line 780)
  • modular_timesfm2_5.py (line 567)

Testing

The fix resolves the AttributeError reported in the issue. The moving average logic itself is unchanged — only the method name reference was corrected.

muhamedfazalps avatar Jun 23 '26 06:06 muhamedfazalps

cc @kashif I think!

Rocketknight1 avatar Jun 23 '26 10:06 Rocketknight1

on it!

kashif avatar Jun 23 '26 10:06 kashif

Great catch on the call-site fix! One thing to flag: the modular file change (modular_timesfm2_5.py line 567) now calls self._timesfm2_5_moving_average, but TimesFm2_5ModelForPrediction in the modular file inherits from TimesFmModelForPrediction, which only defines _timesfm_moving_average (not _timesfm2_5_moving_average). This means:

  1. make fix-repo (which regenerates modeling_timesfm2_5.py from the modular file) may regenerate the generated file without the method, or fail the modular-conversion consistency check.
  2. Python itself would raise AttributeError: 'TimesFm2_5ModelForPrediction' object has no attribute '_timesfm2_5_moving_average' if someone runs the modular file path directly.

The complete fix also needs a _timesfm2_5_moving_average static method defined in the TimesFm2_5ModelForPrediction class in modular_timesfm2_5.py (same implementation as the parent's _timesfm_moving_average), so the code generator has a definition to copy. Running python utils/check_modular_conversion.py --fix after adding the static method confirms the generated file stays consistent.


Drafted-by: Claude Code (Sonnet 4.6) (no human review before posting)

Sriniketh24 avatar Jun 25 '26 09:06 Sriniketh24

@Sriniketh24 @Rocketknight1 Thanks for the review! I have added the _timesfm2_5_moving_average staticmethod to modular_timesfm2_5.py as well, so make fix-repo will work correctly going forward. The method is identical to what is in the generated file.

muhamedfazalps avatar Jun 26 '26 10:06 muhamedfazalps

[For maintainers] Suggested jobs to run (before merge)

run-slow: timesfm2_5

github-actions[bot] avatar Jun 26 '26 10:06 github-actions[bot]