dsipts.models.grouped_transformer package

Submodules

dsipts.models.grouped_transformer.layers module

class dsipts.models.grouped_transformer.layers.MLP(embed_dim: int, hidden_dim: int | None = None, n_layers: int = 2, bias: bool = True, dropout: float = 0.0)

Bases: Module

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

forward(x)

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.

class dsipts.models.grouped_transformer.layers.PatchDecoder(latent_dim: int, out_emb: int, patch_size: int)

Bases: Module

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

forward(x)

(B, N, D) -> (B, N*patch_size, out_emb)

class dsipts.models.grouped_transformer.layers.RotaryPositionalEmbedding(dim: int, max_seq_len: int = 4096, base: int = 10000)

Bases: Module

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

forward(x)

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.

class dsipts.models.grouped_transformer.layers.SelfAttention(latent_dim: int, n_heads: int, bias: bool = True, dropout: float = 0.0, is_causal: bool = False, rope: Module | None = None)

Bases: Module

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

forward(x, key_present: Tensor | None = None)

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.

class dsipts.models.grouped_transformer.layers.SeriesPatchEncoder(latent_dim: int, patch_size: int)

Bases: Module

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

forward(x, xm)

(B, T, F), (B, T, F) -> (B, F, N, D)

class dsipts.models.grouped_transformer.layers.TransformerLayer(latent_dim: int, n_heads: int, n_patches: int, dropout: float = 0.0, attn_bias: bool = True, mlp_layers: int = 2, norm_eps: float = 1e-05, group_gate_init: float = -3.0, causal: bool = False)

Bases: Module

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

forward(x, key_present)

x: (B, F, N, D); key_present: (B*N, F) bool, True where the series has an observed value in the patch.

dsipts.models.grouped_transformer.layers.masked_norm(x: Tensor, xm: Tensor, eps: float = 1e-05, clamp: float | None = 10.0)

Per-sample, per-feature instance norm over time using only the observed values (xm=1).

Parameters:
  • x – (B, T, F)

  • xm – (B, T, F) 1 where observed

  • eps – added to the std

  • clamp – clamp of the normalized values (None = no clamp)

Returns:

x normalized (masked entries set to 0), mean (B, 1, F), std (B, 1, F). A feature without observed values gets mean 0, std 1.

Module contents