A from-scratch Mixture-of-Experts language model — reference implementation
pip install "git+https://github.com/Frankenstein-Labs/mega-moe.git"
from mega.hub.serialization import from_pretrained
from mega.tokenizer.tokenizer import MegaTokenizer
import torch
model = from_pretrained("Frankenstein-Labs/mega-small")
tok = MegaTokenizer.from_pretrained("Frankenstein-Labs/mega-small")
ids = [tok.bos_token_id, *tok.encode("17 + 16 =")]
out = model(torch.tensor([ids]))
print("17 + 16 =", tok.decode([int(out.logits[0, -1].argmax())]))
| metric | value |
|---|---|
| perplexity (structured corpus) | 3.07 |
| next-token accuracy | 0.667 |
arithmetic accuracy (a op b =) | 0.35 |
| parameters | 31.53M total / 16.7M active |
| training loss | 6.72 → 1.02 over 1,500 steps |