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.
| Layer | Type | Parameters | Output shape | |
|---|---|---|---|---|
| 1 | tokens | Input | shape=[1, 4096] | 1 ร 4096 |
| 2 | token_embed | Embedding | 1 ร 4096 ร 4096 | |
| 3 | mixer_norm_1 | RMSNorm | normalizedShape=4096 | 1 ร 4096 ร 4096 |
| 4 | mamba_1 | Mamba (SSM) | 1 ร 4096 ร 4096 | |
| 5 | mixer_residual_1 | Add | 1 ร 4096 ร 4096 | |
| 6 | ffn_norm_1 | RMSNorm | normalizedShape=4096 | 1 ร 4096 ร 4096 |
| 7 | mlp_1 | Feed Forward | embedDim=4096, ffDim=14336 | 1 ร 4096 ร 4096 |
| 8 | ffn_residual_1 | Add | 1 ร 4096 ร 4096 | |
| 9 | mixer_norm_2 | RMSNorm | normalizedShape=4096 | 1 ร 4096 ร 4096 |
| 10 | mamba_2 | Mamba (SSM) | 1 ร 4096 ร 4096 | |
| 11 | mixer_residual_2 | Add | 1 ร 4096 ร 4096 | |
| 12 | ffn_norm_2 | RMSNorm | normalizedShape=4096 | 1 ร 4096 ร 4096 |
| 13 | moe_2 | MoE Layer | embedDim=4096, numExperts=16, topK=2 | 1 ร 4096 ร 4096 |
| 14 | ffn_residual_2 | Add | 1 ร 4096 ร 4096 | |
| 15 | mixer_norm_3 | RMSNorm | normalizedShape=4096 | 1 ร 4096 ร 4096 |
| 16 | mamba_3 | Mamba (SSM) | 1 ร 4096 ร 4096 | |
| 17 | mixer_residual_3 | Add | 1 ร 4096 ร 4096 | |
| 18 | ffn_norm_3 | RMSNorm | normalizedShape=4096 | 1 ร 4096 ร 4096 |
| 19 | mlp_3 | Feed Forward | embedDim=4096, ffDim=14336 | 1 ร 4096 ร 4096 |
| 20 | ffn_residual_3 | Add | 1 ร 4096 ร 4096 | |
| 21 | mixer_norm_4 | RMSNorm | normalizedShape=4096 | 1 ร 4096 ร 4096 |
| 22 | mamba_4 | Mamba (SSM) | 1 ร 4096 ร 4096 | |
| 23 | mixer_residual_4 | Add | 1 ร 4096 ร 4096 | |
| 24 | ffn_norm_4 | RMSNorm | normalizedShape=4096 | 1 ร 4096 ร 4096 |
| 25 | moe_4 | MoE Layer | embedDim=4096, numExperts=16, topK=2 | 1 ร 4096 ร 4096 |
| 26 | ffn_residual_4 | Add | 1 ร 4096 ร 4096 | |
| 27 | mixer_norm_5 | RMSNorm | normalizedShape=4096 | 1 ร 4096 ร 4096 |
| 28 | attn_5 | Grouped Query Attn | embedDim=4096, numHeads=32, numKVHeads=8 | 1 ร 4096 ร 4096 |
| 29 | mixer_residual_5 | Add | 1 ร 4096 ร 4096 | |
| 30 | ffn_norm_5 | RMSNorm | normalizedShape=4096 | 1 ร 4096 ร 4096 |
| 31 | mlp_5 | Feed Forward | embedDim=4096, ffDim=14336 | 1 ร 4096 ร 4096 |
| 32 | ffn_residual_5 | Add | 1 ร 4096 ร 4096 | |
| 33 | mixer_norm_6 | RMSNorm | normalizedShape=4096 | 1 ร 4096 ร 4096 |
| 34 | mamba_6 | Mamba (SSM) | 1 ร 4096 ร 4096 | |
| 35 | mixer_residual_6 | Add | 1 ร 4096 ร 4096 | |
| 36 | ffn_norm_6 | RMSNorm | normalizedShape=4096 | 1 ร 4096 ร 4096 |
| 37 | moe_6 | MoE Layer | embedDim=4096, numExperts=16, topK=2 | 1 ร 4096 ร 4096 |
| 38 | ffn_residual_6 | Add | 1 ร 4096 ร 4096 | |
| 39 | mixer_norm_7 | RMSNorm | normalizedShape=4096 | 1 ร 4096 ร 4096 |
| 40 | mamba_7 | Mamba (SSM) | 1 ร 4096 ร 4096 | |
| 41 | mixer_residual_7 | Add | 1 ร 4096 ร 4096 | |
| 42 | ffn_norm_7 | RMSNorm | normalizedShape=4096 | 1 ร 4096 ร 4096 |
| 43 | mlp_7 | Feed Forward | embedDim=4096, ffDim=14336 | 1 ร 4096 ร 4096 |
| 44 | ffn_residual_7 | Add | 1 ร 4096 ร 4096 | |
| 45 | mixer_norm_8 | RMSNorm | normalizedShape=4096 | 1 ร 4096 ร 4096 |
| 46 | mamba_8 | Mamba (SSM) | 1 ร 4096 ร 4096 | |
| 47 | mixer_residual_8 | Add | 1 ร 4096 ร 4096 | |
| 48 | ffn_norm_8 | RMSNorm | normalizedShape=4096 | 1 ร 4096 ร 4096 |
| 49 | moe_8 | MoE Layer | embedDim=4096, numExperts=16, topK=2 | 1 ร 4096 ร 4096 |
| 50 | ffn_residual_8 | Add | 1 ร 4096 ร 4096 | |
| 51 | final_norm | RMSNorm | normalizedShape=4096 | 1 ร 4096 ร 4096 |
| 52 | lm_head | Linear | outFeatures=65536, inFeatures=4096 | 1 ร 4096 ร 65536 |
| 53 | logits | Output | 1 ร 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
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. Applies to all 4: moe_2, moe_4, moe_6, moe_8. Fix: Add a note on these layers. Typical aux_loss coefficient: 1e-2 (Mixtral/Switch Transformer). (moe_2)
moe-no-aux-loss
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.