Repository navigation
Low Level Design
Sudhanshu Shukla edited this page Nov 23, 2026
·
2 revisions
Model internals: embeddings, decoder blocks, RMSNorm, grouped-query attention, RoPE, sparse top-2 MoE, SwiGLU experts, and training losses.
This diagram is rendered directly by GitHub Wiki Mermaid, not as a link to a raw .mmd file. It describes the implemented training pipeline and architecture; it is not clinical validation.
flowchart TB
IDS["Input token IDs · sequence length 128"]
EMB["Token embedding<br/>vocabulary 30,001 · hidden size 384"]
IDS --> EMB
subgraph DECODER["Mixtral-style Transformer decoder · 4 sequential blocks"]
direction TB
X["Block input · hidden states"]
RN1["RMSNorm"]
X --> RN1
subgraph GQA["Causal grouped-query self-attention"]
direction TB
Q["Q projection · 6 attention heads"]
K["K projection · 2 KV heads"]
V["V projection · 2 KV heads"]
QR["RoPE on queries"]
KR["RoPE on keys"]
ATTN["Grouped-query causal SDPA"]
PROJ["Attention output projection"]
Q --> QR --> ATTN
K --> KR --> ATTN
V --> ATTN
ATTN --> PROJ
end
RN1 --> Q
RN1 --> K
RN1 --> V
R1["Residual addition"]
X --> R1
PROJ --> R1
RN2["RMSNorm"]
R1 --> RN2
subgraph MOE["Sparse Mixture-of-Experts feed-forward module"]
direction TB
ROUTER["Router linear projection<br/>softmax over 4 experts"]
TOP["Top-2 experts chosen per token<br/>normalized routing weights"]
E0["Expert 0 · SwiGLU"]
E1["Expert 1 · SwiGLU"]
E2["Expert 2 · SwiGLU"]
E3["Expert 3 · SwiGLU"]
AGG["Weighted sum of selected experts"]
AUX["Auxiliary load-balancing term"]
ROUTER --> TOP
TOP --> E0 & E1 & E2 & E3
E0 & E1 & E2 & E3 --> AGG
ROUTER --> AUX
end
RN2 --> ROUTER
R2["Residual addition"]
R1 --> R2
AGG --> R2
BLOCK_OUT["Block output<br/>applied sequentially across 4 blocks"]
R2 --> BLOCK_OUT
end
EMB --> X
BLOCK_OUT --> FINAL["Final RMSNorm"]
FINAL --> HEAD["LM head · 30,001 vocabulary logits"]
HEAD --> CELOSS["Causal cross-entropy<br/>pretraining: next-token targets<br/>SFT: answer and EOS targets only"]
AUX --> LOSS["Total objective = CE + 0.02 × MoE auxiliary"]
CELOSS --> LOSS
LOSS --> GRAD["Backpropagation and AdamW<br/>full-parameter updates"]
classDef train fill:#e5f2ff,stroke:#477eaa,color:#163f65
classDef loss fill:#ecf8ef,stroke:#58a576,color:#275b3d
class Q,K,V,QR,KR,ATTN,PROJ train
class AUX,LOSS,GRAD loss
Interactive architecture site · Source repository · Architecture · Home
Foundations
Data and Training
Operation and Quality
- Checkpoints and Resume
- Evaluation and Validation
- Testing and Reproducibility
- Troubleshooting
- Long Context and Limitations
Architecture diagrams