Skip to content

Chronos2 forecasting model#112

Open
topepo wants to merge 20 commits into
mainfrom
chronos
Open

Chronos2 forecasting model#112
topepo wants to merge 20 commits into
mainfrom
chronos

Conversation

@topepo
Copy link
Copy Markdown
Member

@topepo topepo commented May 20, 2026

This is a pure R torch version of Chronos version 2. It is a pre-trained model; weights are downloaded and cached on first use.

A GPU is not required, but extremely helpful at prediction time. Unlike most other models, this implementation appears to achieve good speedups on Apple GPUs (aka MPS devices).

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

air

[air] reported by reviewdog 🐶

d_model = 32L, d_ff = 64L, d_kv = 16L, num_heads = 2L,
num_layers = 1L, dropout_rate = 0.0, layer_norm_epsilon = 1e-6,
rope_theta = 10000, vocab_size = 2L, pad_token_id = 0L,
reg_token_id = 1L, context_length = 64L, input_patch_size = 4L,
input_patch_stride = 4L, output_patch_size = 4L,
max_output_patches = 4L, quantiles = c(0.1, 0.5, 0.9),
use_arcsinh = FALSE, use_reg_token = TRUE,


[air] reported by reviewdog 🐶

d_model = 32L, d_ff = 64L, d_kv = 16L, num_heads = 2L,
num_layers = 1L, dropout_rate = 0.0, layer_norm_epsilon = 1e-6,
rope_theta = 10000, vocab_size = 2L, pad_token_id = 0L,
reg_token_id = 1L, context_length = 64L, input_patch_size = 4L,
input_patch_stride = 4L, output_patch_size = 4L,
max_output_patches = 4L, quantiles = c(0.1, 0.5, 0.9),
use_arcsinh = FALSE, use_reg_token = TRUE,


[air] reported by reviewdog 🐶

d_model = 32L, d_ff = 64L, d_kv = 16L, num_heads = 2L,
num_layers = 1L, dropout_rate = 0.0, layer_norm_epsilon = 1e-6,
rope_theta = 10000, vocab_size = 2L, pad_token_id = 0L,
reg_token_id = 1L, context_length = 64L, input_patch_size = 4L,
input_patch_stride = 4L, output_patch_size = 4L,
max_output_patches = 4L, quantiles = c(0.1, 0.5, 0.9),
use_arcsinh = FALSE, use_reg_token = TRUE,


[air] reported by reviewdog 🐶

d_model = 32L, d_ff = 64L, d_kv = 16L, num_heads = 2L,
num_layers = 1L, dropout_rate = 0.0, layer_norm_epsilon = 1e-6,
rope_theta = 10000, vocab_size = 2L, pad_token_id = 0L,
reg_token_id = 1L, context_length = 64L, input_patch_size = 4L,
input_patch_stride = 4L, output_patch_size = 4L,
max_output_patches = 4L, quantiles = c(0.1, 0.5, 0.9),
use_arcsinh = FALSE, use_reg_token = TRUE,


[air] reported by reviewdog 🐶

d_model = 32L, d_ff = 64L, d_kv = 16L, num_heads = 2L,
num_layers = 1L, dropout_rate = 0.0, layer_norm_epsilon = 1e-6,
rope_theta = 10000, vocab_size = 2L, pad_token_id = 0L,
reg_token_id = 1L, context_length = 64L, input_patch_size = 4L,
input_patch_stride = 4L, output_patch_size = 4L,
max_output_patches = 4L, quantiles = c(0.1, 0.5, 0.9),
use_arcsinh = FALSE, use_reg_token = TRUE,


[air] reported by reviewdog 🐶

ctx_list <- list(torch::torch_tensor(rnorm(16), dtype = torch::torch_float32()))


[air] reported by reviewdog 🐶

d_model = 32L, d_ff = 64L, d_kv = 16L, num_heads = 2L,
num_layers = 1L, dropout_rate = 0.0, layer_norm_epsilon = 1e-6,
rope_theta = 10000, vocab_size = 2L, pad_token_id = 0L,
reg_token_id = 1L, context_length = 64L, input_patch_size = 4L,
input_patch_stride = 4L, output_patch_size = 4L,
max_output_patches = 4L, quantiles = c(0.1, 0.5, 0.9),
use_arcsinh = FALSE, use_reg_token = TRUE,


[air] reported by reviewdog 🐶

d_model = 32L, d_ff = 64L, d_kv = 16L, num_heads = 2L,
num_layers = 1L, dropout_rate = 0.0, layer_norm_epsilon = 1e-6,
rope_theta = 10000, vocab_size = 2L, pad_token_id = 0L,
reg_token_id = 1L, context_length = 64L, input_patch_size = 4L,
input_patch_stride = 4L, output_patch_size = 4L,
max_output_patches = 4L, quantiles = c(0.1, 0.5, 0.9),
use_arcsinh = FALSE, use_reg_token = TRUE,


[air] reported by reviewdog 🐶

tiny_model, tiny_config, torch::torch_device("cpu"),
inputs, prediction_length = 4L, num_output_patches = 1L


[air] reported by reviewdog 🐶

d_model = 32L, d_ff = 64L, d_kv = 16L, num_heads = 2L,
num_layers = 1L, dropout_rate = 0.0, layer_norm_epsilon = 1e-6,
rope_theta = 10000, vocab_size = 2L, pad_token_id = 0L,
reg_token_id = 1L, context_length = 64L, input_patch_size = 4L,
input_patch_stride = 4L, output_patch_size = 4L,
max_output_patches = 4L, quantiles = c(0.1, 0.5, 0.9),
use_arcsinh = FALSE, use_reg_token = TRUE,

Comment thread R/chronos2-misc.R
# Pinned default revision for `amazon/chronos-2`. Bump this deliberately
# when we're ready to ship a new set of weights -- never let users silently
# track a moving HuggingFace branch.
chronos2_default_revision <- function() {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Maybe we change this along the way as more versions are populated. For now, it's keyed to this particular version.

Comment thread R/chronos2-misc.R
cli::cli_progress_step("Downloading {.url {url}}")
err <- tryCatch(
{
curl::curl_download(url, dest, mode = "wb", quiet = TRUE)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

R's internal file.download() had a lot of issues with downloading this file, so we went with curl.

Comment thread R/chronos2-misc.R
chronos2_download <- function(
model_id = "amazon/chronos-2",
revision = chronos2_default_revision(),
cache_dir = file.path(Sys.getenv("HOME"), ".cache", "chronos-r")
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This seems like a good place to put the weights. I'm not aware of there is a canonical location for cached objects related to R.

@topepo topepo marked this pull request as ready for review May 20, 2026 12:47
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