Commit Graph

49 Commits

Author SHA1 Message Date
Abdul Fatir
d0c114c81d
Update README.md (#206)
Some checks failed
CI / type-check (ubuntu-latest, 3.11) (push) Has been cancelled
CI / test (ubuntu-latest, 3.11) (push) Has been cancelled
*Issue #, if available:*

*Description of changes:* Update README. 


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
2024-11-19 18:56:07 +01:00
Lorenzo Stella
d2eef92009
Force context scaling and quantization in float32, add assertions to tests (#197)
Some checks failed
CI / type-check (ubuntu-latest, 3.11) (push) Has been cancelled
CI / test (ubuntu-latest, 3.11) (push) Has been cancelled
*Issue #, if available:* Fixes #193

*Description of changes:* Passing in contexts in lower precision than
float32 may result in a drop of accuracy. This change ensures that the
tokenizer (which does scaling and quantization) operates on a float32
batch.

Tested across GPU/CPU and different context dtypes with

```python
from itertools import product

import pandas as pd
import torch
from chronos import ChronosPipeline

import matplotlib.pyplot as plt  # requires: pip install matplotlib
import numpy as np

df = pd.read_csv("https://raw.githubusercontent.com/AileenNielsen/TimeSeriesAnalysisWithPython/master/data/AirPassengers.csv")

for context_dtype, context_device, model_dtype, model_device in product(
    [torch.bfloat16, torch.float16, torch.float32],
    ["cpu"],  # only cpu input supported at the moment
    [torch.bfloat16, torch.float16, torch.float32],
    ["cpu", "cuda"],
):
    pipeline = ChronosPipeline.from_pretrained(
        "amazon/chronos-t5-tiny",
        device_map=model_device,
        torch_dtype=model_dtype,
    )

    forecast = pipeline.predict(
        context=torch.tensor(df["#Passengers"]).to(dtype=context_dtype, device=context_device),
        prediction_length=65,
        num_samples=20,
        limit_prediction_length=False,
    )

    assert forecast.dtype == context_dtype, f"{forecast.dtype=} but {context_dtype=}"
    assert str(forecast.device) == context_device, f"{forecast.device=} but {context_device=}"

    forecast_index = range(len(df), len(df) + 65)
    low, median, high = np.quantile(forecast[0].to(device="cpu", dtype=torch.float32).numpy(), [0.1, 0.5, 0.9], axis=0)

    plt.figure(figsize=(8, 4))
    plt.plot(df["#Passengers"], color="royalblue", label="historical data")
    plt.plot(forecast_index, median, color="tomato", label="median forecast")
    plt.fill_between(forecast_index, low, high, color="tomato", alpha=0.3, label="80% prediction interval")
    plt.legend()
    plt.grid()
    plt.show()
```


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
2024-11-18 09:55:54 +01:00
Alvaro Perez-Diaz
ac6ee36ace
Fix number of quantisation buckets (#182)
Some checks failed
CI / type-check (ubuntu-latest, 3.11) (push) Has been cancelled
CI / test (ubuntu-latest, 3.11) (push) Has been cancelled
Fixes https://github.com/amazon-science/chronos-forecasting/issues/181.

Chronos' tokenizer has a vocabulary size of `n_tokens`. Among these,
there are `n_special_tokens` reserved for EOS, PAD, etc. and `n_tokens -
n_special_tokens` allocated to numerical values. However, the provided
`MeanScaleUniformBins` tokenizer creates` n_tokens - n_special_tokens +
1` different buckets, resulting in a total of `n_tokens + 1` possible
tokens. This causes training and inference errors when one of the data
points gets allocated to the largest bucket, as the model requires 0 <=
token_id < n_tokens.

This PR modifies the `MeanScaleUniformBins` tokenizer, so that it
creates one less bucket for numerical values.

---

By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

---------

Co-authored-by: Lorenzo Stella <lorenzostella@gmail.com>
2024-10-04 23:00:42 +02:00
Lorenzo Stella
eb7bdfc047
Simplify pretraining README snippet (#160)
*Issue #, if available:*

*Description of changes:*


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
2024-07-24 11:23:33 +02:00
Lorenzo Stella
050d600f64
Bound number of workers by number of datasets (#157)
*Issue #, if available:* Fixes #154

*Description of changes:* Prior to the fix, some workers have no dataset
to consume if `dataloader_num_workers > len(training_data_paths)`.


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
2024-07-23 10:37:14 +02:00
Abdul Fatir
9d59057b72
Add generation params to eval script (#138)
*Description of changes:* Adds generation params to command line options
for the evaluation script.


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
2024-06-27 23:11:05 +02:00
Abdul Fatir
df67c3eb44
Add datasets badge (#137)
*Description of changes:* Title.


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
2024-06-27 20:22:16 +02:00
Abdul Fatir
61a9c4dded
Update README.md with dataset and evaluation details (#136)
*Description of changes:* This PR updates README.md with dataset and
evaluation details


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
2024-06-27 19:26:07 +02:00
Abdul Fatir
fead4ecbca
Add evaluation script (#134)
*Description of changes:* This PR adds configs and a script to evaluate
Chronos models in the same way as described in the paper.


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

Co-authored-by: Abdul Fatir Ansari <ansarnd@amazon.de>
2024-06-27 17:13:35 +02:00
Abdul Fatir
afd9cfd062
Update README.md 2024-06-22 10:08:45 +02:00
Abdul Fatir
d2e0c9d6d5
Set drop_prob = 0 for causal models (#125)
*Description of changes:* This PR sets `drop_prob = 0` when training
causal models. Missing values are problematic for causal model training.


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
2024-06-16 17:28:47 +02:00
Abdul Fatir
2f92a126d3
Add support for causal models (#113)
*Description of changes:* This PR adds support for training
causal/decoder-only models.


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

Co-authored-by: Abdul Fatir Ansari <ansarnd@amazon.de>
2024-06-13 17:37:04 +02:00
Lorenzo Stella
79028e3154
Add issue templates (#109)
*Description of changes:* adding templates for GitHub issues.


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
2024-06-12 18:09:17 +02:00
Abdul Fatir
f49c4ee4b5
Remove print statements from train.py (#101)
*Description of changes:* Removes print statements that got left inside
from a debugging session.


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
2024-06-07 23:36:45 +02:00
Lorenzo Stella
601d52db75
Add FAQ badge to README (#97)
By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
2024-06-03 15:04:06 +02:00
Abdul Fatir
c63145aeb9
Update ci.yml with schedule (#95)
*Description of changes:* Run CI at 8 AM UTC every day.


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

Co-authored-by: Lorenzo Stella <stellalo@amazon.com>
2024-06-03 09:16:36 +02:00
Lorenzo Stella
0ea0adb9b3
Uncap transformers dependency (#94)
*Issue #, if available:* We had to cap transformers in #77 due to
https://github.com/huggingface/transformers/issues/30892. The issue was
solved and released in [transformers
4.41.1](https://github.com/huggingface/transformers/releases/tag/v4.41.1).

*Description of changes:* Remove previous version cap introduced in #77.


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
2024-06-03 09:14:07 +02:00
Abdul Fatir
6bcd4584a3
Enhance training script: auto tf32 detection and reorder default seed setting (#91)
*Description of changes:* Automatically set `tf32` to `False` if used on
an older NVIDIA GPU. Reorder seed so that the seed is saved as part of
the training config.


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

---------

Co-authored-by: Abdul Fatir Ansari <ansarnd@amazon.de>
2024-05-31 15:13:49 +02:00
Abdul Fatir
b0bdbd9d1a
Fix citation (#86)
*Description of changes:* Updates the citation. 


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
2024-05-29 10:47:15 +02:00
Abdul Fatir
223e576e2e
Split input_transform into context_input_transform and label_input_transform (#82)
*Description of changes:* This splits `input_transform` into
`context_input_transform` and `label_input_transform`. Previously,
`input_transform` was being used for both context and label during
training which would lead to incorrect results where `prediction_length`
> `context_length`.

TODO:

- [x] Update docstrings
- [x] Test the training script

By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

---------

Co-authored-by: Abdul Fatir Ansari <ansarnd@amazon.com>
2024-05-28 09:58:22 +02:00
Abdul Fatir
ea26e3d7a7
Relax torch and transformers versions (#81)
*Description of changes:* This PR relaxes `torch` and `transformers`
versions to allow for older versions that were used during original
training. This is needed in light of recent `torch`/`transformers`
versions being slower with DDP.

Relevant issues (but the problem may be deeper than these):

- https://github.com/huggingface/transformers/issues/30840
- https://github.com/pytorch/pytorch/issues/127077
- https://github.com/NVIDIA/nccl/issues/1298


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

Co-authored-by: Abdul Fatir Ansari <ansarnd@amazon.com>
2024-05-27 13:54:53 +02:00
Abdul Fatir
16f927ccfe
Save training job info (#80)
*Description of changes:* This PR updates the training script to also
save the training details in the final checkpoint.


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

---------

Co-authored-by: Abdul Fatir Ansari <ansarnd@amazon.de>
2024-05-27 09:57:18 +02:00
Lorenzo Stella
55166d3227
Cap transformers <4.41 (#77)
*Issue #, if available:* #76

*Description of changes:* transformers 4.41 broke something for us, we
need to look into it deeper


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
2024-05-18 06:53:40 +02:00
Abdul Fatir
7a019b3432
Update README and bump version (#74)
Adds news about the fix to tokenizer `output_transform`.

Co-authored-by: Abdul Fatir Ansari <ansarnd@amazon.com>
2024-05-17 15:38:42 +02:00
HugoSenetaire
3fe24ff8cd
Fix output transform, add test to enforce tokenizer consistency (#73)
*Description of changes:* 

The bin indexes were shifted by one between input transform and output
transform. Subtracting 1 to the sampled tokens in output transform lead
to the correct reconstruction of the signal.

Add a test to ensure the consistency of the Chronos Tokenizer.

By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

Co-authored-by: Lorenzo Stella <stellalo@amazon.com> and Abdul Fatir
Ansari <ansarnd@amazon.com>
2024-05-17 15:29:18 +02:00
Abdul Fatir
02d1a1d73e
Use logo with transparent background (#72)
*Description of changes:* Looks better in dark mode. 


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

Co-authored-by: Abdul Fatir Ansari <ansarnd@amazon.com>
2024-05-15 10:02:09 +02:00
Huibin Shen
660756d045
Add one space after --config in training readme (#71)
*Issue #, if available:*

*Description of changes:*
There is one space missing in the example training command.

By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

Co-authored-by: Ubuntu <ubuntu@ip-172-31-43-83.us-west-2.compute.internal>
2024-05-14 18:43:46 +02:00
Abdul Fatir
e3abe439cb
Add details on pushing model to huggingface hub (#69)
*Description of changes:* Adds details to the Readme on how to push a
fine-tuned model to HF Hub.


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

---------

Co-authored-by: Abdul Fatir Ansari <ansarnd@amazon.de>
2024-05-13 11:10:16 +02:00
Lorenzo Stella
9500eefd47
Update README examples (#68)
*Description of changes:* Simplifies content in the "Usage" section, fix
a link.


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
2024-05-10 16:36:37 +02:00
Abdul Fatir
6732b1c2e3
Add a README file for the scripts (#67)
*Description of changes:* Adds usage examples for `scripts/`. 


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

---------

Co-authored-by: Abdul Fatir Ansari <ansarnd@amazon.com>
2024-05-10 16:04:24 +02:00
Abdul Fatir
1e102f6989
Merge kernel-synth extra into training (#66)
*Description of changes:* See title. 


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

Co-authored-by: Abdul Fatir Ansari <ansarnd@amazon.com>
2024-05-10 14:08:37 +02:00
Lorenzo Stella
069df04e01
Add missing headers (#65)
By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
2024-05-10 09:30:58 +02:00
Abdul Fatir
ecfabdbfd6
Add KernelSynth script (#64)
*Description of changes:* This PR adds the script to generate synthetic
data from KernelSynth.


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

---------

Co-authored-by: Abdul Fatir Ansari <ansarnd@amazon.com>
2024-05-09 23:01:46 +02:00
Lorenzo Stella
b4e8085c7f
Add training script (#63)
*Description of changes:* Add training script and config files. Can be
used for pre-training, or adapted for fine-tuning chronos models.


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

---------

Co-authored-by: Abdul Fatir <Abdulfatirs@gmail.com>
2024-05-09 17:52:01 +02:00
Caner Turkmen
6ae390f291
add AGv1.1 announcement to README (#58)
*Issue #, if available:*

*Description of changes:*


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

---------

Co-authored-by: Abdul Fatir <Abdulfatirs@gmail.com>
2024-04-19 10:13:26 +02:00
Abdul Fatir
07e2246f57
Revamp README: Add News, Coverage, Logo, Shields, Emojis, Zero-Shot results (#56)
*Description of changes:* This PR revamps the README. 


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

---------

Co-authored-by: Abdul Fatir Ansari <ansarnd@amazon.com>
2024-04-19 09:06:20 +02:00
Abdul Fatir
8991ae59ae
Add CITATION.cff (#48)
*Description of changes:* Adds `CITATION.cff` file so that we can get
the "Cite this repository" option in the sidebar.


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

Co-authored-by: Abdul Fatir Ansari <ansarnd@amazon.com>
2024-04-10 10:59:23 +02:00
Abdul Fatir
93bdda7f4b
Update README.md (#46)
*Issue #, if available:* #28 (also, PR #41)

*Description of changes:* This PR updates the README with information on
MLX support.


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
2024-04-08 17:27:11 +02:00
Lorenzo Stella
2042779efa
Simplify tokenizer creation (#44)
*Description of changes:* Minor simplification to how the tokenizer is
constructed from the config


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
2024-04-05 17:15:33 +02:00
Lorenzo Stella
b4423b8c4d
Speed up workflow (#43)
*Description of changes:* Speed up GH workflow by installing CPU-only
version of torch


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
2024-04-05 16:55:25 +02:00
Lorenzo Stella
4b1d1c818b
Fix types, add mypy to workflow (#42)
*Description of changes:* Fix some type checking issues, add mypy to
github workflow, apply black


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
2024-04-05 15:36:39 +02:00
Pixee OSS Assistant
96cedec3fa
Remove Unnecessary F-strings (#34)
*Issue #, if available:* N/A

*Description of changes:*
This codemod converts any f-strings without interpolated variables into
regular strings.
In these cases the use of f-string is not necessary; a simple string
literal is sufficient.

While in some (extreme) cases we might expect a very modest performance
improvement, in general this is a fix that improves the overall
cleanliness and
quality of your code.

```diff
- var = f"hello"
+ var = "hello"
  ...
```

<details>
  <summary>More reading</summary>

*
[https://pylint.readthedocs.io/en/latest/user_guide/messages/warning/f-string-without-interpolation.html](https://pylint.readthedocs.io/en/latest/user_guide/messages/warning/f-string-without-interpolation.html)
*
[https://github.com/Instagram/LibCST/blob/main/libcst/codemod/commands/unnecessary_format_string.py](https://github.com/Instagram/LibCST/blob/main/libcst/codemod/commands/unnecessary_format_string.py)
</details>

Powered by: [pixeebot](https://docs.pixee.ai/) (codemod ID:
[pixee:python/remove-unnecessary-f-str](https://docs.pixee.ai/codemods/python/pixee_python_remove-unnecessary-f-str))
![](https://d1zaessa2hpsmj.cloudfront.net/pixel/v1/track?writeKey=2PI43jNm7atYvAuK7rJUz3Kcd6A&event=DRIP_PR%7CPixee-Bot-Python%2Fchronos-forecasting%7C0822cf23d3ea7d0de7d1b3685ba6e93f9e17ca0d)

<!--{"type":"DRIP","codemod":"pixee:python/remove-unnecessary-f-str"}-->

By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

Co-authored-by: pixeebot[bot] <104101892+pixeebot[bot]@users.noreply.github.com>
2024-03-31 19:04:19 +02:00
Lorenzo Stella
b4a6c0c2eb
Bump package version to 1.1 (#27)
By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
2024-03-25 13:23:08 +01:00
Abdul Fatir
0595bd872b
Add pipeline.embed (#24)
*Description of changes:* This PR adds `pipeline.embed` which extracts
encoder embeddings from the model. These embeddings may be useful for
some downstream tasks such as classification, so this is useful to have.


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

---------

Co-authored-by: Abdul Fatir Ansari <ansarnd@amazon.de>
2024-03-25 13:18:50 +01:00
Lorenzo Stella
28752931fd
Speed up inference by avoiding unnecessary padding (#25)
*Issue #, if available:* Unnecessary context padding slows down
inference. We evaluated the models from HF with this change, and found
no concerning issue with accuracy.

Test code for a context of length 200:

```python
import torch
from chronos import ChronosPipeline
import time

pipeline = ChronosPipeline.from_pretrained(
    "amazon/chronos-t5-large",
    device_map="cuda",
    torch_dtype=torch.bfloat16,
)

context = torch.ones((8, 200))
prediction_length = 24
num_runs = 10

t0 = time.time()
for _ in range(num_runs):
    forecast = pipeline.predict(
        context,
        prediction_length,
        num_samples=20,
    )
t1 = time.time()

print(f"total time: {t1 - t0}")
```

Before the change:

```
total time: 20.005481481552124
```

After the change:

```
total time: 9.82350754737854
```

*Description of changes:* Remove padding in case the provided batch is
shorter than `context_length`.


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
2024-03-25 12:39:30 +01:00
Abdul Fatir
73be25042f
Add optional inference params to example (#15)
*Description of changes:* This PR adds optional inference params such as
`num_samples`, `top_k`, etc. to the example in the README for clarity.


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
2024-03-18 13:13:06 +01:00
Michael Feil
ef786e9864
Update chronos.py - model.device (#11)
*Issue #, if available:* N/A

*Description of changes:*

Thanks for the very clean impl of the Model, Tokenizer, and Pipeline. 

I was curios about it and found a minor improvement in the API - what do
you think about it? Feel free to close. Change is untested.

By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
2024-03-15 10:30:33 +01:00
Lorenzo Stella
7ba945c995 Upload code 2024-03-13 09:58:39 +01:00
Amazon GitHub Automation
2420c10232
Initial commit 2024-02-23 02:35:45 -08:00