Text Generation
Transformers
Safetensors
English
deepseek-v3
multi-head-latent-attention
mixture-of-experts
Mixture of Experts
tinystories
tiny-model
validation
debug-model
Instructions to use shibatch/tinydeepseekv3-3m with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use shibatch/tinydeepseekv3-3m with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="shibatch/tinydeepseekv3-3m")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("shibatch/tinydeepseekv3-3m", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use shibatch/tinydeepseekv3-3m with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "shibatch/tinydeepseekv3-3m" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "shibatch/tinydeepseekv3-3m", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/shibatch/tinydeepseekv3-3m
- SGLang
How to use shibatch/tinydeepseekv3-3m with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "shibatch/tinydeepseekv3-3m" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "shibatch/tinydeepseekv3-3m", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "shibatch/tinydeepseekv3-3m" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "shibatch/tinydeepseekv3-3m", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use shibatch/tinydeepseekv3-3m with Docker Model Runner:
docker model run hf.co/shibatch/tinydeepseekv3-3m
File size: 11,265 Bytes
6036082 27745bb 6036082 27745bb 6036082 27745bb 6036082 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | ---
library_name: transformers
pipeline_tag: text-generation
language:
- en
license: mit
datasets:
- roneneldan/TinyStories
tags:
- deepseek-v3
- multi-head-latent-attention
- mixture-of-experts
- moe
- tinystories
- tiny-model
- text-generation
- validation
- debug-model
---
# Tiny DeepSeek-V3 3M
This repository contains a tiny `DeepseekV3ForCausalLM` Mixture-of-Experts
language model trained from scratch on the full TinyStories training corpus.
The model has **2,803,272 total parameters** and approximately **1,807,944
parameters active per token**. It retains the main DeepSeek-V3 inference
building blocks at a deliberately small scale: Multi-Head Latent Attention
(MLA), Q and KV low-rank compression, interleaved RoPE, routed and shared
experts, sigmoid top-k routing, and correction-bias-based load balancing.
This is an independently trained synthetic tiny checkpoint. It is not an
official DeepSeek model, contains no weights from an original DeepSeek
checkpoint, and should not be expected to match the capabilities of production
DeepSeek models.
## Repository contents
- `hf/`: the final Hugging Face checkpoint and tokenizer
- `example_generate.py`: a minimal local generation example
- `eval_text_generation.json`: generations from the final training evaluation
- `artifact_metadata.json`: training arguments, metrics, router usage, and the
expanded configuration
- `deepseek_v3_config_dump.json`: a standalone configuration dump
Optimizer checkpoints, packed training data, and the full training log are
intentionally omitted from the distribution package.
## Architecture identity
This checkpoint loads through the standard Transformers classes:
```text
DeepseekV3Config
DeepseekV3ForCausalLM
model_type: deepseek_v3
```
It does not use `DeepseekV2ForCausalLM` with a renamed model card. Important
V3-specific behavior includes sigmoid routing, normalized selected routing
weights, interleaved RoPE, Q LoRA compression, and an expert correction bias.
## Model architecture
```yaml
architecture: DeepseekV3ForCausalLM
model_type: deepseek_v3
total_parameter_count: 2,803,272
active_parameters_per_token: 1,807,944
model_vocab_size: 1,024
tokenizer_size: 1,003
hidden_size: 216
intermediate_size: 432
num_hidden_layers: 5
first_dense_layers: 1
moe_layers: 4
num_attention_heads: 8
num_key_value_heads: 8
q_lora_rank: 64
kv_lora_rank: 64
qk_nope_head_dim: 16
qk_rope_head_dim: 16
qk_head_dim: 32
v_head_dim: 32
rope_interleave: true
rope_theta: 10,000
routed_experts_per_moe_layer: 4
shared_experts_per_moe_layer: 1
experts_selected_per_token: 1
moe_intermediate_size: 128
n_group: 1
topk_group: 1
norm_topk_prob: true
routed_scaling_factor: 2.5
tie_word_embeddings: true
rms_norm_eps: 1.0e-6
max_position_embeddings: 2,048
```
### Multi-Head Latent Attention
Every layer uses DeepSeek MLA rather than conventional GQA. Queries are
compressed through a rank-64 Q projection, while keys and values share a
rank-64 latent representation before expansion to eight attention heads.
Each query/key head combines a 16-dimensional non-positional component and a
16-dimensional rotary component. Values use 32 dimensions per head.
`num_key_value_heads` equals `num_attention_heads` because MLA compresses the
shared KV latent state before expanding it to the attention heads. Setting a
smaller KV-head count would describe GQA, not this MLA implementation.
### DeepSeekMoE routing
The first decoder layer is dense. Each of the remaining four layers contains
four routed experts and one always-active shared expert. One routed expert is
selected for each token.
The V3 router computes sigmoid affinity scores. Selection uses the affinity
score plus a non-gradient correction bias, while the routed expert weight uses
the original affinity score. During training, the correction bias was adjusted
after every batch: overloaded experts were decreased and underloaded experts
were increased. A very small complementary sequence-wise balance objective was
also used.
```yaml
v3_bias_update_speed: 0.01
sequence_aux_loss_alpha: 0.0001
no_token_dropping: true
```
All routed experts received traffic. Aggregate fractions across the complete
training run ranged from approximately 0.140 to 0.496 depending on layer and
expert. These aggregate values reflect learned routing specialization and are
not expected to be exactly uniform.
## MTP scope
The checkpoint contains the standard Transformers DeepSeek-V3 causal language
model used for inference. It does **not** contain a training-only Multi-Token
Prediction (MTP) draft module:
```yaml
num_nextn_predict_layers: 0
training_objective: next-token prediction
```
Transformers 5.14.1 exposes the V3 MTP count in configuration but does not
instantiate or train the original DeepSeek-V3 MTP module in
`DeepseekV3ForCausalLM`. The checkpoint therefore preserves the V3 main-model
inference graph and V3 routing behavior, but does not claim to reproduce the
complete original V3 pretraining recipe.
## Training data
The model was trained on the full TinyStories training corpus using an
independent 1% validation split:
```yaml
selected_stories: 2,119,489
training_stories: 2,098,294
validation_stories: 21,195
validation_fraction: 0.01
training_blocks: 2,441,053
validation_blocks: 24,607
block_size: 256
```
Stories were joined into a continuous packed stream:
```text
BOS + story 1 + EOS + BOS + story 2 + EOS + ...
```
The stream was split into fixed 256-token blocks without per-story padding.
Only the final incomplete block was discarded.
## Tokenizer
The checkpoint uses a custom byte-level BPE tokenizer. The base vocabulary was
trained on the 5% TinyStories experiment and frozen for the full run:
```text
BPE()
ByteLevel(add_prefix_space=False)
base_vocab_size: 1,000
min_frequency: 2
normalizer: None
```
Special tokens use fixed IDs:
```text
<s> -> 1000
</s> -> 1001
<|im_start|> -> 1002
```
`<s>` is both BOS and padding, while `</s>` is EOS. The model reserves 1,024
embedding rows and the tokenizer exposes 1,003 tokens.
The presence of `<|im_start|>` does not make this a chat model. The checkpoint
is pretrained only and has no chat template or instruction tuning.
## Training setup
The checkpoint was trained from scratch in float32 on an NVIDIA GeForce RTX
5060 Ti:
```yaml
dtype: float32
batch_size: 16
block_size: 256
training_steps: 152,565
epochs: 1.0
tokens_processed: 624,906,240
optimizer: AdamW
learning_rate: 2.0e-4
warmup_steps: 2,000
scheduler: warmup + cosine decay
minimum_learning_rate: 2.0e-5
weight_decay: 0.0
grad_clip: 1.0
optimizer_loop_time: approximately 1h 03m 36s
```
## Evaluation
The final checkpoint produced:
```yaml
final_train_loss: 1.5201
validation_loss: 1.5254
validation_perplexity: 4.5972
```
Validation loss was computed over 32 batches, or 131,072 tokens, from the
independent packed validation split. These values are compact checkpoint
diagnostics, not general language-model benchmark results.
## Example generation
A representative final sampled generation begins:
```text
Once upon a time, there was a little girl named Lily. She had long black,
white hair that she loved to play with every day. One day, Lily's mom asked
her to clean up her bedroom. Lily didn't want to clean up, so she started to
pick up her toys and put them away in the closet.
```
An independent greedy reload test produced:
```text
Once upon a time, there was a little girl named Lily. She loved to play
outside in the sunshine and pick flowers. One day, she saw a big, scary dog
running towards her. The dog ran away and Lily was sad.
```
Sampling is stochastic. The model produces recognizable TinyStories-style
English, but contradictions, incorrect pronouns, invented words, repetition,
and unfinished stories remain possible at this size.
## Usage
Install the requirements:
```bash
pip install -r requirements.txt
```
Run the included example from the repository root:
```bash
python example_generate.py
```
Local loading:
```python
from pathlib import Path
import torch
from huggingface_hub import snapshot_download
from transformers import AutoModelForCausalLM, AutoTokenizer
repo = "shibatch/tinydeepseekv3-3m"
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model_dir = Path(snapshot_download(
repo_id=repo,
allow_patterns=["hf/*"],
)) / "hf"
tokenizer = AutoTokenizer.from_pretrained(model_dir)
model = AutoModelForCausalLM.from_pretrained(
model_dir,
dtype=torch.float32,
).to(device).eval()
input_ids = torch.tensor(
[[tokenizer.bos_token_id] + tokenizer.encode(
"Once upon",
add_special_tokens=False,
)],
dtype=torch.long,
device=device,
)
with torch.inference_mode():
output = model.generate(
input_ids=input_ids,
max_new_tokens=100,
do_sample=True,
temperature=0.8,
top_p=0.95,
top_k=40,
repetition_penalty=1.1,
use_cache=True,
pad_token_id=tokenizer.pad_token_id,
eos_token_id=tokenizer.eos_token_id,
)
print(tokenizer.decode(output[0], skip_special_tokens=True))
```
Loading the `hf` subdirectory from Hugging Face Hub:
```python
from pathlib import Path
from huggingface_hub import snapshot_download
repo_dir = Path(snapshot_download(
repo_id="shibatch/tinydeepseekv3-3m",
allow_patterns=["hf/*"],
))
model_dir = repo_dir / "hf"
```
Use `model_dir` with the local loading example above.
## Loading requirements
The model was trained, saved, and independently reloaded with:
```text
transformers 5.14.1
torch 2.12.0+cu130
```
It requires a Transformers release containing `DeepseekV3ForCausalLM`. No
custom model code or `trust_remote_code=True` is required.
## Intended uses
This model is intended for:
- testing `DeepseekV3Config` and `DeepseekV3ForCausalLM`
- testing Multi-Head Latent Attention and compressed KV caching
- testing Q and KV low-rank projections
- testing V3 sigmoid MoE routing and shared experts
- testing correction-bias-based expert load balancing
- compact inference-engine and architecture experiments
- testing `generate()`, `save_pretrained()`, and `from_pretrained()`
It is not intended for:
- instruction following or chat
- factual question answering
- reasoning benchmarks
- production deployment
- safety-critical use
- comparison with full-size DeepSeek models
## Limitations
- only 2.80 million total parameters
- small 1,003-token tokenizer
- English TinyStories-only pretraining
- no instruction tuning and no chat template
- no MTP training module or MTP objective
- weak factual knowledge and reasoning
- occasional grammatical and semantic errors
- possible mojibake inherited from training-text byte sequences
- no capability-equivalence claim with official DeepSeek models
## Citation and references
This is a synthetic tiny DeepSeek-V3-compatible MoE checkpoint trained from
scratch on TinyStories. It is intended for implementation validation,
debugging, education, and small-scale architecture experiments.
- [DeepSeek-V3 Technical Report](https://arxiv.org/abs/2412.19437)
- [Official DeepSeek-V3 repository](https://github.com/deepseek-ai/DeepSeek-V3)
- [TinyStories](https://huggingface.co/datasets/roneneldan/TinyStories)
|