A small English→Russian Transformer with Llama's changes
Built in lesson 5 of the course "Transformers: from scratch to production": https://github.com/xmarva/transformers-from-scratch
- lesson 3's encoder-decoder (3 + 3 layers, d_model 256, 4 heads) and its recipe
- pre-norm with RMSNorm, SwiGLU feed-forward layers, rotary position embeddings
- best validation cross-entropy: 1.028
# pip install git+https://github.com/xmarva/transformers-from-scratch
import json
from huggingface_hub import hf_hub_download
from safetensors.torch import load_file
from tfs.modern import Seq2Seq
repo = "xmarva/tfs-transformer-en-ru-llama"
with open(hf_hub_download(repo, "config.json")) as f:
config = json.load(f)
model = Seq2Seq(**config)
model.load_state_dict(load_file(hf_hub_download(repo, "model.safetensors")))