HawkLabofficial commited on
Commit
f1c3365
·
verified ·
1 Parent(s): 338132d

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +141 -0
README.md ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: ru
3
+ license: mit
4
+ library_name: keras
5
+ tags:
6
+ - gpt
7
+ - russian
8
+ - transformer
9
+ - gqa
10
+ - alibi
11
+ - rmsnorm
12
+ pipeline_tag: text-generation
13
+ datasets:
14
+ - HawkLabofficial/HawkGPT-v0.5 # synthetic
15
+ metrics:
16
+ - accuracy
17
+ ---
18
+
19
+ # HawkGPT v0.5
20
+
21
+ Russian-language GPT-style transformer language model (24M params) trained from scratch on synthetic Q&A data.
22
+
23
+ ## Architecture
24
+
25
+ | Param | Value |
26
+ |-------|-------|
27
+ | Embed dim | 512 |
28
+ | Layers | 8 |
29
+ | Query heads | 8 |
30
+ | KV heads (GQA) | 2 |
31
+ | FF dim | 2048 |
32
+ | Vocab size | ~3200 (BPE) |
33
+ | Max seq len | 256 |
34
+ | Parameters | 24,384,000 |
35
+
36
+ **Key design choices:**
37
+ - **Grouped Query Attention (GQA)** — 8 query / 2 KV heads for faster inference
38
+ - **ALiBi** — position biases instead of learned embeddings (extrapolates to longer sequences)
39
+ - **RMSNorm** — faster normalization without mean computation
40
+ - **No bias terms** — in all Linear layers
41
+ - **Weight tying** — embedding and output projection share weights
42
+ - **BPE tokenizer** — digit-aware (individual digit tokens), vocab ~3200
43
+
44
+ ## Training
45
+
46
+ - Mixed precision (bfloat16) with XLA JIT compilation
47
+ - AdamW optimizer, cosine LR schedule with 1000-step warmup
48
+ - EMA (exponential moving average) of weights
49
+ - Batch size 96, max 30 epochs (early stopping patience 10)
50
+ - Trained on NVIDIA RTX 4070 12GB
51
+
52
+ ### Training history
53
+
54
+ | Epoch | Loss | Throughput |
55
+ |-------|------|------------|
56
+ | 1 | 0.0663 | 57K t/s |
57
+ | 5 | 0.0520 | 157K t/s |
58
+ | 10 | 0.0512 | 360K t/s |
59
+ | 13 (best) | **0.0479** | 153K t/s |
60
+
61
+ ## Benchmark
62
+
63
+ **Overall: 40/72 (55.6%)**
64
+
65
+ | Category | Score |
66
+ |----------|-------|
67
+ | Division | 90% |
68
+ | Knowledge | 80% |
69
+ | Algebra | 75% |
70
+ | Addition | 60% |
71
+ | Multiplication | 60% |
72
+ | Multi-step | 50% |
73
+ | Subtraction | 40% |
74
+ | Word problems | 33% |
75
+ | Sequences | 20% |
76
+
77
+ ## Dataset
78
+
79
+ Synthetic Russian Q&A corpus (~200K+ pairs, ~80M+ characters) covering:
80
+ - Arithmetic (add, sub, mul, div, multi-step)
81
+ - Algebra (linear, quadratic, systems)
82
+ - Sequences, geometry, physics
83
+ - Python code tracing
84
+ - General knowledge (science, history, geography)
85
+ - Dialogue & conversations
86
+
87
+ ## Usage
88
+
89
+ ```python
90
+ import tensorflow as tf
91
+ from tokenizers import Tokenizer
92
+
93
+ # Load tokenizer
94
+ tokenizer = Tokenizer.from_file("tokenizer.json")
95
+ tokenizer.no_padding()
96
+ tokenizer.no_truncation()
97
+
98
+ # Build & load model
99
+ from model import build_model
100
+ model = build_model(vocab_size=tokenizer.get_vocab_size())
101
+ model.load_weights("model_best.weights.h5")
102
+
103
+ # Generate
104
+ def generate(prompt, temperature=0.7, top_k=50, max_new=200):
105
+ bos_id = tokenizer.token_to_id("[BOS]")
106
+ eos_id = tokenizer.token_to_id("[EOS]")
107
+ enc = tokenizer.encode(prompt)
108
+ ids = [bos_id] + enc.ids
109
+ for _ in range(max_new):
110
+ ctx = tf.constant([ids[-256:]], dtype=tf.int32)
111
+ logits = model(ctx, training=False)[0, -1, :] / temperature
112
+ if top_k:
113
+ vals, _ = tf.math.top_k(logits, k=top_k)
114
+ logits = tf.where(logits < vals[-1], -1e9, logits)
115
+ next_id = int(tf.random.categorical(tf.nn.softmax(logits)[None], 1)[0, 0])
116
+ if next_id in (eos_id, tokenizer.token_to_id("[PAD]")):
117
+ break
118
+ ids.append(next_id)
119
+ return tokenizer.decode(ids[len([bos_id] + enc.ids):])
120
+
121
+ print(generate("Вопрос: 2 + 2 ="))
122
+ ```
123
+
124
+ ### CLI
125
+ ```bash
126
+ python3 generate.py --prompt "Вопрос: Сколько будет 5 * 7?" --temperature 0.3 --top_k 20
127
+ ```
128
+
129
+ ## Files
130
+
131
+ | File | Description |
132
+ |------|-------------|
133
+ | `model_best.weights.h5` | Best checkpoint weights (94 MB) |
134
+ | `tokenizer.json` | BPE tokenizer |
135
+ | `config.py` | Full model & training config |
136
+ | `model.py` | Model definition (GQA, RMSNorm, ALiBi) |
137
+ | `generate.py` | Inference script |
138
+
139
+ ## License
140
+
141
+ MIT