--- language: en pipeline_tag: text-generation datasets: - HuggingFaceFW/fineweb-edu - HuggingFaceTB/smol-smoltalk tags: - deepseek-v3 - mixture-of-experts - from-scratch --- # Mini DeepSeek-V3 A 212.6M-parameter DeepSeek-V3-style language model (multi-head latent attention, DeepSeekMoE, multi-token prediction) written from scratch in PyTorch. About 108.2M parameters are active per token at inference as each MoE layer runs its shared expert and 2 of its 8 routed experts, and the MTP module is dropped. - Code: https://github.com/willcagas/mini-deepseek - Pretraining: 10B tokens of FineWeb-Edu (`sample-10BT`), 38,147 steps, validation loss 3.03 - Fine-tuning: two passes over smol-smoltalk, 3,124 steps, validation loss 1.55 - Tokenizer: SmolLM2-135M's, 49,152 tokens - Context: 2,048 tokens Read more about the implementation here: https://www.wcagas.com/writings/deepseek-v3-from-scratch ## Loading The architecture is custom so loading needs the model code from the GitHub repo. ```python import json from safetensors.torch import load_file from src.model import DeepSeekV3 config = json.load(open("config.json")) model = DeepSeekV3(config=config) model.load_state_dict(load_file("model.safetensors")) model.eval() ``` The weights include the MTP module, which is only used in training. ## Chat format The model was fine-tuned on ChatML. Put the end-of-text token in front, and stop at `<|im_end|>`: ``` <|endoftext|><|im_start|>user What is photosynthesis?<|im_end|> <|im_start|>assistant ``` ## Limitations It writes fluent English and answers in the right shape but its facts are somewhat inaccurate. It is a learning project and not a model for practical use.