N Neurarch Architectures Checks Docs Open the app

Architectures / NLP/LLM

๐Ÿ Mamba SSM Block

Mamba State Space Model โ€” selective SSM + causal conv gating, no attention (O(T) complexity)

Layers
18
Parameters
168.27M
Input
1 ร— 1024
Output
1 ร— 1024 ร— 50280
Verifier
Clean

Every number on this page is computed from the graph by the same functions the app runs, not written by hand.

Open Mamba SSM Block on the canvas Free, no account needed

When to pick it

Pick for very long sequences where attention's O(Tยฒ) cost is the bottleneck (DNA, audio, long-context LM). Tuning is trickier than transformers.

Structure

18 layers. Output shapes are propagated from the input shape, batch dimension excluded.

LayerTypeParametersOutput shape
1tokensInputshape=[1, 1024]1 ร— 1024
2embedEmbedding1 ร— 1024 ร— 1024
3norm_ssmRMSNormnormalizedShape=10241 ร— 1024 ร— 1024
4in_projLinearoutFeatures=40961 ร— 1024 ร— 4096
5to_channelsPermute1 ร— 4096 ร— 1024
6causal_convConv1DoutChannels=4096, kernelSize=3, stride=11 ร— 4096 ร— 1024
7to_tokensPermute1 ร— 1024 ร— 4096
8silu_xSwish1 ร— 1024 ร— 4096
9ssm_scanMamba (SSM)1 ร— 1024 ร— 4096
10z_gateSwish1 ร— 1024 ร— 4096
11gate_outMultiply1 ร— 1024 ร— 4096
12out_projLinearoutFeatures=10241 ร— 1024 ร— 1024
13residual_1Add1 ร— 1024 ร— 1024
14norm_ffnRMSNormnormalizedShape=10241 ร— 1024 ร— 1024
15ffnSwiGLUembedDim=1024, intermediateSize=20481 ร— 1024 ร— 1024
16residual_2Add1 ร— 1024 ร— 1024
17lm_headLinearoutFeatures=502801 ร— 1024 ร— 50280
18outputOutput1 ร— 1024 ร— 50280

What the verifier says

The same 41 structural checks that run on every edit in the app, on this graph.

No finding. Shapes propagate end to end, every divisibility condition holds, and no advisory rule fires. See the checks.

The PyTorch it exports

Generated from the graph above. First 46 lines; the app exports the whole file, plus the training loop, the data contract and a deploy bundle.

# Architecture designed with Neurarch: https://neurarch.com
# PyTorch: compatible with Python 3.8+ and torch>=1.12
# Colab: pip install torch torchvision  (usually pre-installed)
#
# WARNING: 2 layer(s) below are not yet supported by the PyTorch
# exporter and pass their input through UNCHANGED in forward():
#   - to_channels (permute)
#   - to_tokens (permute)

import torch
import torch.nn as nn
import torch.nn.functional as F
from typing import Tuple

class MambaSSMBlock(nn.Module):
    def __init__(self):
        super().__init__()

        self.embedding_1 = nn.Embedding(50280, 1024)
        self.rmsNorm_1 = nn.RMSNorm(1024)
        self.linear_1 = nn.Linear(1048576, 4096)
        self.conv1d_1 = nn.Conv1d(4096, 4096, kernel_size=3, stride=1, padding=1)
        self.swish_1 = nn.SiLU()
        self.mamba_1 = nn.Identity()  # Mamba(d_model=4096, d_state=16, d_conv=4, expand=1), pip install mamba-ssm and swap in
        self.swish_2 = nn.SiLU()
        self.linear_2 = nn.Linear(4194304, 1024)
        self.rmsNorm_2 = nn.RMSNorm(1024)
        self.swiglu_1 = nn.ModuleDict({
            'gate_proj': nn.Linear(1024, 2048, bias=False),
            'up_proj':   nn.Linear(1024, 2048, bias=False),
            'down_proj': nn.Linear(2048, 1024, bias=False),
        })  # SwiGLU FFN (LLaMA-style)
        self.linear_3 = nn.Linear(1048576, 50280)

    def forward(self, x):
        # tokens shape: [1,1024]
        embedding_embed = self.embedding_1(x)
        rms_norm_norm1 = self.rmsNorm_1(embedding_embed)
        linear_n_proj = self.linear_1(rms_norm_norm1)
        # TODO: layer 'to_channels' (permute) is not yet supported by the exporter; passing through unchanged
        conv1d_l_conv = self.conv1d_1(linear_n_proj)
        # TODO: layer 'to_tokens' (permute) is not yet supported by the exporter; passing through unchanged
        swish_silu_x = self.swish_1(conv1d_l_conv)
        mamba_m_proj = self.mamba_1(swish_silu_x)
        swish_z_gate = self.swish_2(linear_n_proj)
        multiply_ltiply = mamba_m_proj * swish_z_gate

For agents

This architecture is machine-readable end to end. An agent can list the set, fetch this graph, edit it, and have the edit verified before any GPU time is spent.

Also in NLP/LLM

๐Ÿค– Transformer Block
Transformer encoder block
8 layers ยท 7.09M
๐Ÿ“– BERT Base
BERT-Base encoder โ€” bidirectional MHA
11 layers ยท 31.12M
๐Ÿง  GPT-2
GPT-2 Small โ€” causal transformer block
12 layers ยท 84.33M
๐Ÿฆ™ LLaMA-3 Block
LLaMA-3 decoder block โ€” GQA
10 layers ยท 702.55M