SalesforceAIResearch / uni2ts

[ICML2024] Unified Training of Universal Time Series Forecasting Transformers
Apache License 2.0
796 stars 80 forks source link

Clarification on prediction_mask in MoiraiFinetune #29

Closed zqiao11 closed 4 months ago

zqiao11 commented 5 months ago

Hi @gorold. May I clarify the setup of the prediction mask in validation dataset in MoiraiFinetune?

            + EvalMaskedPrediction(
                mask_length=-prediction_length % patch_size,  # num of patches for prediction?
                target_field="target",
                truncate_fields=("variate_id", "time_id", "observed_mask"),
                optional_truncate_fields=("past_feat_dynamic_real",),
                prediction_mask_field="prediction_mask",
                expected_ndim=3,
            )

Now mask_length is computed as -prediction_length % patch_size. Shouldn't the mask_length be computed as prediction_length // patch_size? As the logic here seems to mask the patches in the prediction range.

    def _generate_prediction_mask(
        self, target: Float[np.ndarray, "var time *feat"]
    ) -> Bool[np.ndarray, "var time"]:
        self.check_ndim("target", target, self.expected_ndim)
        var, time = target.shape[:2]
        prediction_mask = np.zeros((var, time), dtype=bool)
        prediction_mask[:, -self.mask_length :] = True
        return prediction_mask

Please correct me if my understanding is incorrect. Look forward to your reply.

gorold commented 5 months ago

Hey, thanks for catching this. I think you're right, it should be prediction_length // patch_size, will look into this.

zqiao11 commented 4 months ago

Hi, it should be math.ceil(prediction_length / patch_size) since the prediction range has been padded.

gorold commented 4 months ago

I think there wouldn't be a difference if the prediction range is already padded?

zqiao11 commented 4 months ago

Let's say if prediction length is 96 and patch size is 64, the prediction range will be padded to 128 to make sure there are multiple patches. So, the last 2 patches should be masked as True in prediction_mask.

If we use prediction_length // patch_size, then only the last patch is masked as True.

gorold commented 4 months ago

Right... this makes sense. Thanks a lot!