Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TimesFM Time Series Forecasting Model #34082

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from

Conversation

jinan-zhou
Copy link

@jinan-zhou jinan-zhou commented Oct 11, 2024

What does this PR do?

This PR adds a new model, TimesFM, to HuggingFace. TimesFM is a time series forecasting model based on the transformer architecture. It was proposed in A decoder-only foundation model for time-series forecasting.

Code Example

import numpy as np
from transformers import TimesFMModel
from transformers import TimesFMConfig

config = TimesFMConfig()
model = TimesFMModel(config)

forecast_input = [
    np.sin(np.linspace(0, 20, 100)),
    np.sin(np.linspace(0, 20, 200)),
    np.sin(np.linspace(0, 20, 400)),
]
frequency_input = [0, 1, 2]

results = model(
    inputs=forecast_input,
    freq=frequency_input,
)

TODOs

  1. Unit Tests
  2. Documentations and doc strings
  3. Pretrained weights
  4. ONNX definition
  5. Model parallelism

Copy link

@rajatsen91 rajatsen91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work.

One general question: are there plans to support decoder only training and associated loss functions ?


# B x N x D
patched_inputs = patched_inputs * (1.0 - patched_pads)
print(">>> PatchedDecoder patched_inputs", patched_inputs.shape)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: not sure if these print statements are necessary.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR is still in progress. We will make sure to eliminate all debug info when ready for review.

patched_inputs = patched_inputs * (1.0 - patched_pads)
print(">>> PatchedDecoder patched_inputs", patched_inputs.shape)
concat_inputs = torch.cat([patched_inputs, patched_pads], dim=-1)
print(">>> PatchedDecoder concat_inputs", concat_inputs.shape)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: ditto

current_padding = paddings[:, 0 : final_out.shape[1]]
input_ts = final_out[:, -max_len:]
input_padding = current_padding[:, -max_len:]
fprop_outputs, all_attentions, all_hidden_states = self.forward(input_ts, input_padding, freq, output_attentions=output_attentions, output_hidden_states=output_hidden_states)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is caching being used to save on key value computations here? May be that is the purpose of output_attentions and output_hidden_states ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is required by the Hugging Face framework.

print(">>> TimesFMModel _preprocess", len(inputs), inputs[0].shape)
input_ts, input_padding, inp_freq = [], [], []

pmap_pad = (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this padding might not be required if we are not compiling the model.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it!

@rajatsen91
Copy link

Great work! I left some minor comments.

@rvt123
Copy link

rvt123 commented Nov 7, 2024

Would this PR add finetuning support for the model?

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.

4 participants