Repository navigation
Architecture
The project implements a decoder-only causal Transformer in mixtral_lab/model.py. It is architecturally inspired by Mixtral; it is not a weights-compatible reimplementation of the released pretrained Mixtral models.
Token IDs → Token embedding → N × TransformerBlock → RMSNorm → LM head
│
├─ RMSNorm → GQA causal attention + RoPE → Residual
└─ RMSNorm → Top-k sparse SwiGLU experts → Residual
- Grouped-query attention (GQA): query heads may outnumber KV heads. K/V states are repeated across query groups in this reference implementation.
- Rotary position embeddings (RoPE): applied to projected queries and keys based on explicit position offsets.
-
Causal attention: uses PyTorch scaled dot-product attention, with configurable
globalor boundedslidingmode. - KV cache: supported for autoregressive generation; context and attention semantics depend on the selected mode.
The router scores each token against num_experts, selects the highest-probability top_k experts, normalizes selected weights, and combines expert outputs. Experts use SwiGLU MLPs. The loss contains next-token cross-entropy plus a configurable auxiliary load-balancing term.
Because routing and expert computation are implemented as a research reference path, the code does not implement a dedicated fused expert kernel or expert-parallel dispatch.
For Stage 1, the model optimizes a causal language-model objective with an auxiliary routing regularizer:
L_total = L_next_token_CE + aux_loss_coef × L_router_balance
For Stage 2, prompt tokens are masked from the causal-LM labels, and only the completion portion is supervised, while the model still computes its routing auxiliary loss.
- model.py — model, attention, router, experts and losses.
- config.py — architecture parameters and validation.
- train_utils.py — model creation, initialization, optimization and checkpoint utilities.
See Model Configuration for reproducible parameter selection.
Foundations
Data and Training
Operation and Quality
- Checkpoints and Resume
- Evaluation and Validation
- Testing and Reproducibility
- Troubleshooting
- Long Context and Limitations
Architecture diagrams