FullAttention#

class pytorch_forecasting.models.timexer.sub_modules.FullAttention(mask_flag=True, factor=5, scale=None, attention_dropout=0.1, output_attention=False, use_efficient_attention=False)[source]#

Bases: Module

Full attention mechanism with optional masking and dropout. :param mask_flag: Whether to apply masking. :type mask_flag: bool :param factor: Factor for scaling the attention scores. :type factor: int :param scale: Scaling factor for attention scores. :type scale: float :param attention_dropout: Dropout rate for attention scores. :type attention_dropout: float :param output_attention: Whether to output attention weights. :type output_attention: bool :param use_efficient_attention: Whether to use PyTorch’s native,

optimized Scaled Dot Product Attention implementation which can reduce computation time and memory consumption for longer sequences. PyTorch automatically selects the optimal backend (FlashAttention-2, Memory-Efficient Attention, or their own C++ implementation) based on user’s input properties, hardware capabilities, and build configuration.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

Methods

forward(queries, keys, values, attn_mask[, ...])

Define the computation performed at every call.

forward(queries, keys, values, attn_mask, tau=None, delta=None)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.