fishy.models.deep.augformer_v2¶
AugFormerV2: Enhanced version of AugFormer with advancements from Parameter Golf.
Features implemented: - QK-Gain: Learnable per-head query scaling. - Parallel Residuals: Attention and MLP branches in parallel (GPT-J style). - Depth Recurrence: Selective looping of transformer blocks. - LeakyReLU(0.5)^2 Activation: Non-monotonic activation for efficiency. - TTT Support: forward_ttt method for entropy minimization at test-time.
Classes
- class fishy.models.deep.augformer_v2.AugFormerV2(input_dim: int, output_dim: int, hidden_dim: int = 512, num_layers: int = 4, num_heads: int = 8, dropout: float = 0.3, num_views: int = 6, use_xsa: bool = False, use_qk_gain: bool = False, use_parallel_residuals: bool = False, recurrence_layers: List[int] | None = None, use_leaky_sq: bool = False, **kwargs)[source]¶
Bases:
AugFormerEnhanced Augmentation-as-Sequence Transformer. Allows toggling Parameter Golf advancements for benchmarking.
- __init__(input_dim: int, output_dim: int, hidden_dim: int = 512, num_layers: int = 4, num_heads: int = 8, dropout: float = 0.3, num_views: int = 6, use_xsa: bool = False, use_qk_gain: bool = False, use_parallel_residuals: bool = False, recurrence_layers: List[int] | None = None, use_leaky_sq: bool = False, **kwargs) None[source]¶
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(x: Tensor, return_attention: bool = False, *args, **kwargs) Tensor | Tuple[Tensor, List][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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class fishy.models.deep.augformer_v2.LeakyReluSq(neg_slope: float = 0.5)[source]¶
Bases:
ModuleNon-monotonic activation used in high-performing Golf models.
- __init__(neg_slope: float = 0.5)[source]¶
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(x: Tensor) Tensor[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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class fishy.models.deep.augformer_v2.MultiHeadAttentionV2(embed_dim: int, num_heads: int, use_xsa: bool = False, use_qk_gain: bool = False)[source]¶
Bases:
MultiHeadAttention- __init__(embed_dim: int, num_heads: int, use_xsa: bool = False, use_qk_gain: bool = False)[source]¶
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(x: Tensor) Tensor[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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class fishy.models.deep.augformer_v2.TransformerBlockV2(embed_dim: int, num_heads: int, mlp_ratio: int = 2, dropout: float = 0.1, use_xsa: bool = False, use_qk_gain: bool = False, use_parallel_residuals: bool = False, use_leaky_sq: bool = False)[source]¶
Bases:
TransformerBlock- __init__(embed_dim: int, num_heads: int, mlp_ratio: int = 2, dropout: float = 0.1, use_xsa: bool = False, use_qk_gain: bool = False, use_parallel_residuals: bool = False, use_leaky_sq: bool = False)[source]¶
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(x: Tensor) Tensor[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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
s