N Neurarch Architectures Checks Docs Open the app

Architectures / NLP/LLM

๐Ÿ”€ Mixtral MoE Block

Mixtral decoder block โ€” GQA + Sparse MoE (8 experts, top-2) + RMSNorm + RoPE

Layers
9
Parameters
1.45B
Input
1 ร— 4096 ร— 4096
Output
1 ร— 4096 ร— 4096
Verifier
Clean

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

Open Mixtral MoE Block on the canvas Free, no account needed

When to pick it

Pick when you have MoE training infra and want best quality per active param. Routing instability and memory cost (still scales with total params) are the trade-off.

Structure

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

LayerTypeParametersOutput shape
1hidden_statesInputshape=[1, 4096, 4096]1 ร— 4096 ร— 4096
2input_normRMSNormnormalizedShape=40961 ร— 4096 ร— 4096
3self_attnGrouped Query AttnembedDim=4096, numHeads=32, numKVHeads=81 ร— 4096 ร— 4096
4rotary_embRoPE
5attn_residualAdd1 ร— 4096 ร— 4096
6post_attn_normRMSNormnormalizedShape=40961 ร— 4096 ร— 4096
7block_sparse_moeMoE LayerembedDim=4096, numExperts=8, topK=21 ร— 4096 ร— 4096
8moe_residualAdd1 ร— 4096 ร— 4096
9hidden_outOutput1 ร— 4096 ร— 4096

What the verifier says

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

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). (block_sparse_moe)
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 MixtralMoEBlock(nn.Module):
    def __init__(self):
        super().__init__()

        self.rmsNorm_1 = nn.RMSNorm(4096)
        self.groupedQueryAttention_1 = nn.ModuleDict({
            'q_proj': nn.Linear(4096, 4096,        bias=False),   # 32 heads ร— 128
            'k_proj': nn.Linear(4096, 1024, bias=False),   # 8 KV heads ร— 128
            'v_proj': nn.Linear(4096, 1024, bias=False),
            'o_proj': nn.Linear(4096, 4096,        bias=False),
        })  # GQA: 32Q / 8KV heads (requires F.scaled_dot_product_attention)
        self.rmsNorm_2 = nn.RMSNorm(4096)
        self.moeLayer_1 = nn.ModuleDict({
            'router': nn.Linear(4096, 8, bias=False),
            'experts': nn.ModuleList([
                nn.Sequential(
                    nn.Linear(4096, 14336, bias=False), nn.SiLU(),
                    nn.Linear(14336, 4096, bias=False),
                ) for _ in range(8)
            ]),
        })  # MoE top-2

    @staticmethod
    def _moe_forward(moe, x, top_k=2):
        """Top-k routed MoE forward over a {'router', 'experts'} ModuleDict."""
        scores = moe['router'](x).softmax(dim=-1)
        top_w, top_i = scores.topk(top_k, dim=-1)
        top_w = top_w / top_w.sum(dim=-1, keepdim=True)
        flat_x = x.reshape(-1, x.size(-1))
        flat_i = top_i.reshape(-1, top_k)
        flat_w = top_w.reshape(-1, top_k)
        out = torch.zeros_like(flat_x)
        for e_idx in flat_i.unique():
            hit = flat_i == e_idx
            rows = hit.any(dim=-1)
            w = (flat_w * hit).sum(dim=-1)[rows].unsqueeze(-1)
            out[rows] += w * moe['experts'][int(e_idx)](flat_x[rows])

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