N Neurarch Architectures Checks Docs Open the app

Architectures / NLP/LLM

๐Ÿงฌ Jamba

Hybrid SSM-Transformer-MoE โ€” interleaves Mamba, attention, and MoE blocks in one stack (AI21 2024)

Layers
53
Parameters
13.03B
Input
1 ร— 4096
Output
1 ร— 4096 ร— 65536
Verifier
1 advisory

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

Open Jamba on the canvas Free, no account needed

When to pick it

Pick to see three paradigms in one compact graph: state-space, attention, and mixture-of-experts. Good for studying hybrid long-context designs.

Structure

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

LayerTypeParametersOutput shape
1tokensInputshape=[1, 4096]1 ร— 4096
2token_embedEmbedding1 ร— 4096 ร— 4096
3mixer_norm_1RMSNormnormalizedShape=40961 ร— 4096 ร— 4096
4mamba_1Mamba (SSM)1 ร— 4096 ร— 4096
5mixer_residual_1Add1 ร— 4096 ร— 4096
6ffn_norm_1RMSNormnormalizedShape=40961 ร— 4096 ร— 4096
7mlp_1Feed ForwardembedDim=4096, ffDim=143361 ร— 4096 ร— 4096
8ffn_residual_1Add1 ร— 4096 ร— 4096
9mixer_norm_2RMSNormnormalizedShape=40961 ร— 4096 ร— 4096
10mamba_2Mamba (SSM)1 ร— 4096 ร— 4096
11mixer_residual_2Add1 ร— 4096 ร— 4096
12ffn_norm_2RMSNormnormalizedShape=40961 ร— 4096 ร— 4096
13moe_2MoE LayerembedDim=4096, numExperts=16, topK=21 ร— 4096 ร— 4096
14ffn_residual_2Add1 ร— 4096 ร— 4096
15mixer_norm_3RMSNormnormalizedShape=40961 ร— 4096 ร— 4096
16mamba_3Mamba (SSM)1 ร— 4096 ร— 4096
17mixer_residual_3Add1 ร— 4096 ร— 4096
18ffn_norm_3RMSNormnormalizedShape=40961 ร— 4096 ร— 4096
19mlp_3Feed ForwardembedDim=4096, ffDim=143361 ร— 4096 ร— 4096
20ffn_residual_3Add1 ร— 4096 ร— 4096
21mixer_norm_4RMSNormnormalizedShape=40961 ร— 4096 ร— 4096
22mamba_4Mamba (SSM)1 ร— 4096 ร— 4096
23mixer_residual_4Add1 ร— 4096 ร— 4096
24ffn_norm_4RMSNormnormalizedShape=40961 ร— 4096 ร— 4096
25moe_4MoE LayerembedDim=4096, numExperts=16, topK=21 ร— 4096 ร— 4096
26ffn_residual_4Add1 ร— 4096 ร— 4096
27mixer_norm_5RMSNormnormalizedShape=40961 ร— 4096 ร— 4096
28attn_5Grouped Query AttnembedDim=4096, numHeads=32, numKVHeads=81 ร— 4096 ร— 4096
29mixer_residual_5Add1 ร— 4096 ร— 4096
30ffn_norm_5RMSNormnormalizedShape=40961 ร— 4096 ร— 4096
31mlp_5Feed ForwardembedDim=4096, ffDim=143361 ร— 4096 ร— 4096
32ffn_residual_5Add1 ร— 4096 ร— 4096
33mixer_norm_6RMSNormnormalizedShape=40961 ร— 4096 ร— 4096
34mamba_6Mamba (SSM)1 ร— 4096 ร— 4096
35mixer_residual_6Add1 ร— 4096 ร— 4096
36ffn_norm_6RMSNormnormalizedShape=40961 ร— 4096 ร— 4096
37moe_6MoE LayerembedDim=4096, numExperts=16, topK=21 ร— 4096 ร— 4096
38ffn_residual_6Add1 ร— 4096 ร— 4096
39mixer_norm_7RMSNormnormalizedShape=40961 ร— 4096 ร— 4096
40mamba_7Mamba (SSM)1 ร— 4096 ร— 4096
41mixer_residual_7Add1 ร— 4096 ร— 4096
42ffn_norm_7RMSNormnormalizedShape=40961 ร— 4096 ร— 4096
43mlp_7Feed ForwardembedDim=4096, ffDim=143361 ร— 4096 ร— 4096
44ffn_residual_7Add1 ร— 4096 ร— 4096
45mixer_norm_8RMSNormnormalizedShape=40961 ร— 4096 ร— 4096
46mamba_8Mamba (SSM)1 ร— 4096 ร— 4096
47mixer_residual_8Add1 ร— 4096 ร— 4096
48ffn_norm_8RMSNormnormalizedShape=40961 ร— 4096 ร— 4096
49moe_8MoE LayerembedDim=4096, numExperts=16, topK=21 ร— 4096 ร— 4096
50ffn_residual_8Add1 ร— 4096 ร— 4096
51final_normRMSNormnormalizedShape=40961 ร— 4096 ร— 4096
52lm_headLinearoutFeatures=65536, inFeatures=40961 ร— 4096 ร— 65536
53logitsOutput1 ร— 4096 ร— 65536

What the verifier says

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

warn1 attention layer(s) present but no positional encoding found. Attention is permutation-invariant, without position information the model cannot distinguish token order. Fix: Add a PositionalEncoding (sinusoidal) or RoPE layer before the first attention layer. (attn_5)
attention-no-pe
infoMoE layers require an auxiliary router z-loss + load-balance loss during training to prevent expert collapse. This is not visible in the architecture diagram but must be in the training loop. Fix: Add a note on this layer. Typical aux_loss coefficient: 1e-2 (Mixtral/Switch Transformer). (moe_2)
moe-no-aux-loss
infoMoE layers require an auxiliary router z-loss + load-balance loss during training to prevent expert collapse. This is not visible in the architecture diagram but must be in the training loop. Fix: Add a note on this layer. Typical aux_loss coefficient: 1e-2 (Mixtral/Switch Transformer). (moe_4)
moe-no-aux-loss
infoMoE layers require an auxiliary router z-loss + load-balance loss during training to prevent expert collapse. This is not visible in the architecture diagram but must be in the training loop. Fix: Add a note on this layer. Typical aux_loss coefficient: 1e-2 (Mixtral/Switch Transformer). (moe_6)
moe-no-aux-loss
infoMoE layers require an auxiliary router z-loss + load-balance loss during training to prevent expert collapse. This is not visible in the architecture diagram but must be in the training loop. Fix: Add a note on this layer. Typical aux_loss coefficient: 1e-2 (Mixtral/Switch Transformer). (moe_8)
moe-no-aux-loss

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)

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

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

        self.embedding_1 = nn.Embedding(65536, 4096)
        self.rmsNorm_1 = nn.RMSNorm(4096)
        self.mamba_1 = nn.Identity()  # Mamba(d_model=4096, d_state=16, d_conv=4, expand=2), pip install mamba-ssm and swap in
        self.rmsNorm_2 = nn.RMSNorm(4096)
        self.feedForward_1 = nn.Sequential(
            nn.Linear(4096, 14336),
            nn.ReLU(),
            nn.Linear(14336, 4096)
        )
        self.rmsNorm_3 = nn.RMSNorm(4096)
        self.mamba_2 = nn.Identity()  # Mamba(d_model=4096, d_state=16, d_conv=4, expand=2), pip install mamba-ssm and swap in
        self.rmsNorm_4 = nn.RMSNorm(4096)
        self.moeLayer_1 = nn.ModuleDict({
            'router': nn.Linear(4096, 16, bias=False),
            'experts': nn.ModuleList([
                nn.Sequential(
                    nn.Linear(4096, 14336, bias=False), nn.SiLU(),
                    nn.Linear(14336, 4096, bias=False),
                ) for _ in range(16)
            ]),
        })  # MoE top-2
        self.rmsNorm_5 = nn.RMSNorm(4096)
        self.mamba_3 = nn.Identity()  # Mamba(d_model=4096, d_state=16, d_conv=4, expand=2), pip install mamba-ssm and swap in
        self.rmsNorm_6 = nn.RMSNorm(4096)
        self.feedForward_2 = nn.Sequential(
            nn.Linear(4096, 14336),
            nn.ReLU(),
            nn.Linear(14336, 4096)
        )
        self.rmsNorm_7 = nn.RMSNorm(4096)
        self.mamba_4 = nn.Identity()  # Mamba(d_model=4096, d_state=16, d_conv=4, expand=2), pip install mamba-ssm and swap in
        self.rmsNorm_8 = nn.RMSNorm(4096)
        self.moeLayer_2 = nn.ModuleDict({

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