Add model card
Browse files
README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SmolDeepSeek-V4 100M
|
| 2 |
+
|
| 3 |
+
A small ~110M parameter language model implementing the **DeepSeek-V4 architecture**, fine-tuned for chat/instruction following. Trained from scratch — no weights from DeepSeek-V4 were used.
|
| 4 |
+
|
| 5 |
+
- **Pretrained base model**: [cmpatino/smol-deepseek-v4-100m-pretrain](https://huggingface.co/cmpatino/smol-deepseek-v4-100m-pretrain)
|
| 6 |
+
- **This model**: SFT on [HuggingFaceTB/smol-smoltalk](https://huggingface.co/datasets/HuggingFaceTB/smol-smoltalk)
|
| 7 |
+
|
| 8 |
+
## Architecture
|
| 9 |
+
|
| 10 |
+
This model implements key DeepSeek-V4 innovations at a miniature scale:
|
| 11 |
+
|
| 12 |
+
| Component | Details |
|
| 13 |
+
|---|---|
|
| 14 |
+
| **Parameters** | ~110M total (41M embeddings, 69M non-embedding) |
|
| 15 |
+
| **Hidden size** | 320 |
|
| 16 |
+
| **Layers** | 8 |
|
| 17 |
+
| **Attention heads** | 8 (1 KV head — MQA-style) |
|
| 18 |
+
| **MLA** | Multi-head Latent Attention with q_lora_rank=160 |
|
| 19 |
+
| **MoE** | 4 routed experts + 1 shared, top-2 routing |
|
| 20 |
+
| **Hyper-Connections** | hc_mult=4, Sinkhorn routing (replacing residual connections) |
|
| 21 |
+
| **MTP** | 1 next-token prediction layer |
|
| 22 |
+
| **Vocab** | 129,280 (DeepSeek-V4 tokenizer) |
|
| 23 |
+
| **Context** | 2,048 tokens |
|
| 24 |
+
|
| 25 |
+
## Training
|
| 26 |
+
|
| 27 |
+
### Stage 1: Pretraining
|
| 28 |
+
- **Dataset**: [HuggingFaceFW/fineweb-edu](https://huggingface.co/datasets/HuggingFaceFW/fineweb-edu)
|
| 29 |
+
- **Steps**: 5,000 | **Tokens**: ~2.6B
|
| 30 |
+
- **Batch**: 32 effective (8 × 4 GA) | **Seq length**: 2,048
|
| 31 |
+
- **LR**: 6e-4, cosine, 3% warmup
|
| 32 |
+
- **Precision**: bf16 mixed
|
| 33 |
+
|
| 34 |
+
### Stage 2: SFT (this model)
|
| 35 |
+
- **Dataset**: [HuggingFaceTB/smol-smoltalk](https://huggingface.co/datasets/HuggingFaceTB/smol-smoltalk) (460K conversations)
|
| 36 |
+
- **Steps**: 3,000 | **Tokens**: ~72.7M
|
| 37 |
+
- **Batch**: 32 effective (8 × 4 GA) | **Seq length**: 2,048
|
| 38 |
+
- **LR**: 2e-5, cosine, 5% warmup
|
| 39 |
+
- **Precision**: fp32
|
| 40 |
+
|
| 41 |
+
### Metrics
|
| 42 |
+
|
| 43 |
+
| Metric | Pretrained | SFT |
|
| 44 |
+
|---|---|---|
|
| 45 |
+
| **Eval loss** | — | 2.607 |
|
| 46 |
+
| **Perplexity** (held-out) | 13.62 | 12.90 |
|
| 47 |
+
| **Token accuracy** | 33.8% | 48.5% |
|
| 48 |
+
|
| 49 |
+
## Usage
|
| 50 |
+
|
| 51 |
+
```python
|
| 52 |
+
import torch
|
| 53 |
+
from safetensors.torch import load_file
|
| 54 |
+
from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer
|
| 55 |
+
|
| 56 |
+
# Load model (recommended: manual load for reliability)
|
| 57 |
+
config = AutoConfig.from_pretrained("cmpatino/smol-deepseek-v4-100m", trust_remote_code=True)
|
| 58 |
+
model = AutoModelForCausalLM.from_config(config, trust_remote_code=True).float()
|
| 59 |
+
|
| 60 |
+
# Download and load weights
|
| 61 |
+
from huggingface_hub import hf_hub_download
|
| 62 |
+
weights_path = hf_hub_download("cmpatino/smol-deepseek-v4-100m", "model.safetensors")
|
| 63 |
+
state_dict = load_file(weights_path)
|
| 64 |
+
model.load_state_dict(state_dict, strict=True)
|
| 65 |
+
model = model.cuda().eval()
|
| 66 |
+
|
| 67 |
+
tokenizer = AutoTokenizer.from_pretrained("cmpatino/smol-deepseek-v4-100m")
|
| 68 |
+
|
| 69 |
+
# Chat
|
| 70 |
+
messages = [{"role": "user", "content": "What are 3 benefits of exercise?"}]
|
| 71 |
+
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 72 |
+
input_ids = tokenizer.encode(prompt, return_tensors="pt").cuda()
|
| 73 |
+
output = model.generate(input_ids, max_new_tokens=200, temperature=0.7, top_p=0.9,
|
| 74 |
+
pad_token_id=tokenizer.eos_token_id)
|
| 75 |
+
print(tokenizer.decode(output[0][input_ids.shape[1]:], skip_special_tokens=True))
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
## Limitations
|
| 79 |
+
|
| 80 |
+
- **Tiny model**: 110M params with 129K vocabulary — most capacity goes to embeddings. Generations are often incoherent or factually wrong.
|
| 81 |
+
- **Undertrained**: Only 5K pretrain + 3K SFT steps. Production models train for 100K+ steps on trillions of tokens.
|
| 82 |
+
- **Educational purpose**: This model demonstrates the DeepSeek-V4 architecture at small scale. It is **not** suitable for any production use.
|
| 83 |
+
- **Custom code**: Requires `trust_remote_code=True`.
|
| 84 |
+
|
| 85 |
+
## Hardware
|
| 86 |
+
|
| 87 |
+
Trained on 1× NVIDIA H100 80GB.
|
| 88 |
+
|
| 89 |
+
## License
|
| 90 |
+
|
| 91 |
+
Apache-2.0
|