kylesayrs commited on
Commit
28c657a
·
verified ·
1 Parent(s): d75c148

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +109 -0
README.md ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ base_model:
4
+ - moonshotai/Kimi-K3
5
+ library_name: transformers
6
+ ---
7
+
8
+ # Kimi-K3-0.40B
9
+
10
+ This is a tiny version of [moonshotai/Kimi-K3](https://huggingface.co/moonshotai/Kimi-K3) created for testing and development.
11
+
12
+ ## Model Details
13
+
14
+ - **Base Model**: moonshotai/Kimi-K3
15
+ - **Architecture**: kimi_linear (KimiK3ForConditionalGeneration)
16
+ - **Total Parameters**: 0.40B
17
+ - **Activated Parameters**: ~0.06B (2 of 8 experts active per token)
18
+
19
+ ## Configuration Changes
20
+
21
+ The following parameters were reduced from the original model:
22
+
23
+ | Parameter | Original | Tiny |
24
+ |-----------|----------|------|
25
+ | `num_hidden_layers` | 93 | 8 |
26
+ | `hidden_size` | 7168 | 1024 |
27
+ | `intermediate_size` | 33792 | 2048 |
28
+ | `moe_intermediate_size` | 3072 | 256 |
29
+ | `num_attention_heads` | 96 | 8 |
30
+ | `num_key_value_heads` | 96 | 8 |
31
+ | `q_lora_rank` | 1536 | 256 |
32
+ | `kv_lora_rank` | 512 | 128 |
33
+ | `qk_nope_head_dim` | 128 | 64 |
34
+ | `qk_rope_head_dim` | 64 | 32 |
35
+ | `v_head_dim` | 128 | 64 |
36
+ | `num_experts` | 896 | 8 |
37
+ | `num_shared_experts` | 2 | 1 |
38
+ | `num_experts_per_token` | 16 | 2 |
39
+ | `routed_expert_hidden_size` | 3584 | 512 |
40
+ | `attn_res_block_size` | 12 | 4 |
41
+ | `linear_attn head_dim` | 74 | 32 |
42
+ | `linear_attn num_heads` | 96 | 8 |
43
+ | `vt_num_hidden_layers` | 27 | 2 |
44
+ | `vt_hidden_size` | 1024 | 256 |
45
+
46
+ ## Architecture Preserved
47
+
48
+ - **Mixed attention**: KDA (linear/delta attention) on layers 0–2, 4–6 and MLA (full multi-latent attention) on layers 3, 7 — same 3:1 KDA:MLA ratio as the original
49
+ - **Attention + MLP residuals**: `attn_res_block_size=4` enabled on all layers
50
+ - **MoE**: layers 1–7 use sparse MoE with latent expert projection; layer 0 is dense MLP
51
+ - **Vision tower**: included but reduced
52
+
53
+ ## Checkpoint Structure
54
+
55
+ Single-shard checkpoint (`model.safetensors`). Key prefix: `language_model.model.layers.{i}.*`, matching the original sharded checkpoint structure.
56
+
57
+ ## Usage
58
+
59
+ ```python
60
+ import sys
61
+ sys.path.insert(0, "/path/to/llm-compressor/src")
62
+
63
+ from transformers import AutoTokenizer
64
+ from llmcompressor.modeling.kimi_k3 import KimiK3ForConditionalGeneration
65
+
66
+ model = KimiK3ForConditionalGeneration.from_pretrained(
67
+ "inference-optimization/Kimi-K3-0.40B", device_map="auto"
68
+ )
69
+ tokenizer = AutoTokenizer.from_pretrained(
70
+ "inference-optimization/Kimi-K3-0.40B", trust_remote_code=True
71
+ )
72
+
73
+ inputs = tokenizer("According to all known laws", return_tensors="pt").to(model.device)
74
+ output = model.language_model.generate(**inputs, max_new_tokens=20)
75
+ print(tokenizer.decode(output[0], skip_special_tokens=True))
76
+ ```
77
+
78
+ ## Validation Output
79
+
80
+ ```
81
+ Total parameters: 0.396B
82
+ Number of layers: 8
83
+ Layer 0 attn type: KimiDeltaAttention (KDA/linear)
84
+ Layer 3 attn type: KimiMLAAttention (MLA/full)
85
+ Layer 7 attn type: KimiMLAAttention (MLA/full)
86
+ Layer 0 has MLP: True
87
+ Layer 1 has MoE: True
88
+ Attention residuals enabled: True
89
+ Attn res block size: 4
90
+
91
+ Forward pass loss: 0.0013
92
+ Generated: The FitnessGram Pacer Test is a multistage aerobic capacity test that progressively gets more difficult as it continues. The 20 meter pacer test will begin in 30 seconds
93
+ ```
94
+
95
+ ## Creation Process
96
+
97
+ This model was created using the llm-compressor `create-tiny-model` claude skill.
98
+
99
+ 1. Inspected the original `moonshotai/Kimi-K3` config to identify key architecture parameters
100
+ 2. Reduced layer count, hidden dimensions, and expert counts to target ~0.4B total parameters
101
+ 3. Preserved the 3:1 KDA:MLA attention pattern and attention/MLP residual connections
102
+ 4. Initialized all weights from scratch (normal distribution, std=0.02; norms → 1.0; biases → 0.0)
103
+ 5. Fine-tuned on a toy copypasta dataset until perplexity < 3.0 (achieved in ~57 epochs)
104
+
105
+ ## Notes
106
+
107
+ - The model uses custom modeling code from `llmcompressor.modeling.kimi_k3` — it cannot be loaded with `AutoModelForCausalLM` without that module on the path
108
+ - `KimiK3ForConditionalGeneration` does not inherit from `GenerationMixin`; use `model.language_model.generate(...)` for text generation
109
+ - The vision tower is present but untrained for vision tasks