﻿# Moirai-MoE causal attention: time IDs matter beyond flattened token order

Port Moirai-MoE attention masks by preserving sample isolation and temporal IDs, including same-time variates, rather than substituting a generic triangular token mask.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-moirai-moe-causal-time-id-multivariate-token-order/
Language: en

## Identify the concrete attention contract

A decoder-style forecasting model can arrange several variates in one token sequence. A standard triangular mask over array indices does not automatically reproduce its intended temporal relationships. The [Moirai-MoE implementation](https://raw.githubusercontent.com/SalesforceAIResearch/uni2ts/main/src/uni2ts/model/moirai_moe/module.py) calls a packed causal attention helper with sample and time identifiers. Preserve those explicit relations when moving the model to another attention backend or exporting its numerical execution graph.

## Follow sample isolation before temporal causality

The [mask helper](https://raw.githubusercontent.com/SalesforceAIResearch/uni2ts/main/src/uni2ts/common/torch_util.py) first restricts attention to matching sample identities, then applies a non-strict temporal comparison. Separate packed examples remain distinct even if their local times coincide. A replacement that uses only time IDs can combine unrelated examples; a replacement that uses only array positions can remove valid same-time relationships among variates. Both changes alter the model's information flow without necessarily causing a shape error.

## Preserve aligned-time variate relationships

Several channels can describe one temporal position. Non-strict time causality allows relationships that differ from a strict ordering of those channels in a flattened sequence. The [Moirai-MoE paper](https://arxiv.org/abs/2410.10469) provides architecture context, while the installed helper defines the exact implemented permission rule. Distinguish the temporal identity of a patch from the location at which an exporter happened to store it, particularly when optimizing layout or packing.

## Do not infer compatibility from an attention kernel name

An optimized kernel may expect a mask convention, packed sequence boundaries or causal orientation different from the model wrapper's representation. The [packed Moirai guide](/journal/fg2-moirai-packed-sample-variate-identity-scaling/) supplies related identity controls. Translate the permission relation explicitly rather than setting a generic causal flag and assuming equivalence. The numerical values in the network can remain unchanged while an incorrect mask silently removes context or reveals a disallowed future patch.

## Compare the permission matrix on a tiny fixture

Construct a small packed fixture with separate samples, repeated times across variates and a later time. Compare the intended allowed pairs with the reference helper before comparing model outputs. The [artifact-manifest guide](/journal/tokenizer-artifact-release-manifest/) adds release context. A port passes when sample isolation, same-time interaction and temporal direction match. Runtime acceleration is a separate measurement after that equivalence, rather than evidence that a successful optimized attention invocation preserved the original forecasting procedure.
