Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Question: Is it possible to use Moirai without GluonTS? #9

Closed
isaacmg opened this issue Mar 28, 2024 · 2 comments
Closed

Question: Is it possible to use Moirai without GluonTS? #9

isaacmg opened this issue Mar 28, 2024 · 2 comments
Labels
question Further information is requested

Comments

@isaacmg
Copy link

isaacmg commented Mar 28, 2024

Hi thanks for the repository and the example usage. However, I would like to use the model for inference (and possibly fine-tune it as well) without using GluonTS at all. Could you elaborate on what raw inputs the model takes and how to decouple it from the Gluon dependencies?

Thanks.

@gorold
Copy link
Contributor

gorold commented Mar 29, 2024

The MoiraiForecast class is a PyTorch Lightning Module, you can use it without the GluonTS components (but you'd have to rewrite the class removing the GluonTS imports). Btw, GluonTS doesn't have any Gluon dependencies.

The required inputs are:

  1. past_target, your input time series
  2. past_observed_target, a boolean tensor, True to indicate the data point is observed, False otherwise
  3. past_id_pad, a boolean tensor, True to indicate the data point is padding

You can check out the MoiraiForecast implementation to check the typehints for more information about the inputs. Here's an example:

import torch
from huggingface_hub import hf_hub_download

from uni2ts.model.moirai import MoiraiForecast


SIZE = "small"  # model size: choose from {'small', 'base', 'large'}
PDT = 20  # prediction length: any positive integer
CTX = 200  # context length: any positive integer
PSZ = "auto"  # patch size: choose from {"auto", 8, 16, 32, 64, 128}
BSZ = 32  # batch size: any positive integer
TEST = 100  # test set length: any positive integer

# Prepare pre-trained model by downloading model weights from huggingface hub
model = MoiraiForecast.load_from_checkpoint(
    checkpoint_path=hf_hub_download(
        repo_id=f"Salesforce/moirai-1.0-R-{SIZE}", filename="model.ckpt"
    ),
    prediction_length=PDT,
    context_length=CTX,
    patch_size=PSZ,
    num_samples=100,
    target_dim=1,
    feat_dynamic_real_dim=0,
    past_feat_dynamic_real_dim=0,
    map_location="cpu",
)

PAST = CTX + PDT if PSZ == 'auto' else CTX
pred = model(
    past_target=torch.randn(BSZ, PAST, 1),
    past_observed_target=torch.ones(BSZ, PAST, 1, dtype=torch.bool),
    past_is_pad=torch.zeros(BSZ, PAST, dtype=torch.bool),
)

@gorold
Copy link
Contributor

gorold commented Apr 11, 2024

Closing due to inactivity, feel free to reopen if you need any further clarifications.

@gorold gorold closed this as completed Apr 11, 2024
@gorold gorold reopened this Apr 12, 2024
@gorold gorold added the question Further information is requested label Apr 12, 2024
@gorold gorold changed the title Using model without GluonTS Question: Is it possible to use Moirai without GluonTS? Apr 12, 2024
@SalesforceAIResearch SalesforceAIResearch locked and limited conversation to collaborators May 29, 2024
@gorold gorold converted this issue into discussion #56 May 29, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants