File size: 8,492 Bytes
20865d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "52b890f4",
   "metadata": {
    "papermill": {
     "duration": 0.002262,
     "end_time": "2023-08-23T10:53:59.090685",
     "exception": false,
     "start_time": "2023-08-23T10:53:59.088423",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "# Model Init\n",
    "\n",
    "Test that the model init code, runs without issues\n",
    "\n",
    "**L6-D512 model with**\n",
    "- Layer count: 6\n",
    "- Embed size: 512"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "f89c248f",
   "metadata": {
    "notebookRunGroups": {
     "groupValue": ""
    },
    "papermill": {
     "duration": 0.001598,
     "end_time": "2023-08-23T10:53:59.094424",
     "exception": false,
     "start_time": "2023-08-23T10:53:59.092826",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Preparing the init model and test dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "65ffd8d5",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-08-23T10:53:59.099519Z",
     "iopub.status.busy": "2023-08-23T10:53:59.099000Z",
     "iopub.status.idle": "2023-08-23T10:53:59.849771Z",
     "shell.execute_reply": "2023-08-23T10:53:59.848760Z"
    },
    "papermill": {
     "duration": 0.756019,
     "end_time": "2023-08-23T10:53:59.852126",
     "exception": false,
     "start_time": "2023-08-23T10:53:59.096107",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "# First lets setup the various directories\n",
    "!mkdir -p ../../model/\n",
    "!mkdir -p ../../datapath/\n",
    "!mkdir -p ../../checkpoint/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c3b4c1b4",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-08-23T10:53:59.858552Z",
     "iopub.status.busy": "2023-08-23T10:53:59.858038Z",
     "iopub.status.idle": "2023-08-23T10:54:08.846245Z",
     "shell.execute_reply": "2023-08-23T10:54:08.844779Z"
    },
    "papermill": {
     "duration": 8.994708,
     "end_time": "2023-08-23T10:54:08.848911",
     "exception": false,
     "start_time": "2023-08-23T10:53:59.854203",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2023-08-23 10:54:04,147] [INFO] [real_accelerator.py:133:get_accelerator] Setting ds_accelerator to cuda (auto detect)\r\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[RWKV.model] Running RWKV model using 'torch-jit' with torch '2.0.1+cu118'\r\n",
      "---- Initializing model ----\r\n",
      "No of layers: 6\r\n",
      "Embedding size: 512\r\n",
      "Output model path: ../model/L6-D512-neox-init.pth\r\n",
      "Vocab size: 50277\r\n",
      "Note: this process takes a significant time (and ram) for large models\r\n",
      "---- ----- ----\r\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Using /root/.cache/torch_extensions/py310_cu118 as PyTorch extensions root...\r\n",
      "Detected CUDA files, patching ldflags\r\n",
      "Emitting ninja build file /root/.cache/torch_extensions/py310_cu118/wkv_1_bf16/build.ninja...\r\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Building extension module wkv_1_bf16...\r\n",
      "Allowing ninja to set a default number of workers... (overridable by setting the environment variable MAX_JOBS=N)\r\n",
      "ninja: no work to do.\r\n",
      "Loading extension module wkv_1_bf16...\r\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[RWKV.model]: Finished initial model load\r\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "50277 512   -0.0001 emb.weight\r\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "512   512   0    blocks.0.att.key.weight\r\n",
      "512   512   1.0  blocks.0.att.value.weight\r\n",
      "512   512   0    blocks.0.att.receptance.weight\r\n",
      "512   512   0    blocks.0.att.output.weight\r\n",
      "2048  512   1.0  blocks.0.ffn.key.weight\r\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "512   512   0    blocks.0.ffn.receptance.weight\r\n",
      "512   2048  0    blocks.0.ffn.value.weight\r\n",
      "512   512   0    blocks.1.att.key.weight\r\n",
      "512   512   1.0  blocks.1.att.value.weight\r\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "512   512   0    blocks.1.att.receptance.weight\r\n",
      "512   512   0    blocks.1.att.output.weight\r\n",
      "2048  512   1.0  blocks.1.ffn.key.weight\r\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "512   512   0    blocks.1.ffn.receptance.weight\r\n",
      "512   2048  0    blocks.1.ffn.value.weight\r\n",
      "512   512   0    blocks.2.att.key.weight\r\n",
      "512   512   1.0  blocks.2.att.value.weight\r\n",
      "512   512   0    blocks.2.att.receptance.weight\r\n",
      "512   512   0    blocks.2.att.output.weight\r\n",
      "2048  512   1.0  blocks.2.ffn.key.weight\r\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "512   512   0    blocks.2.ffn.receptance.weight\r\n",
      "512   2048  0    blocks.2.ffn.value.weight\r\n",
      "512   512   0    blocks.3.att.key.weight\r\n",
      "512   512   1.0  blocks.3.att.value.weight\r\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "512   512   0    blocks.3.att.receptance.weight\r\n",
      "512   512   0    blocks.3.att.output.weight\r\n",
      "2048  512   1.0  blocks.3.ffn.key.weight\r\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "512   512   0    blocks.3.ffn.receptance.weight\r\n",
      "512   2048  0    blocks.3.ffn.value.weight\r\n",
      "512   512   0    blocks.4.att.key.weight\r\n",
      "512   512   1.0  blocks.4.att.value.weight\r\n",
      "512   512   0    blocks.4.att.receptance.weight\r\n",
      "512   512   0    blocks.4.att.output.weight\r\n",
      "2048  512   1.0  blocks.4.ffn.key.weight\r\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "512   512   0    blocks.4.ffn.receptance.weight\r\n",
      "512   2048  0    blocks.4.ffn.value.weight\r\n",
      "512   512   0    blocks.5.att.key.weight\r\n",
      "512   512   1.0  blocks.5.att.value.weight\r\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "512   512   0    blocks.5.att.receptance.weight\r\n",
      "512   512   0    blocks.5.att.output.weight\r\n",
      "2048  512   1.0  blocks.5.ffn.key.weight\r\n",
      "512   512   0    blocks.5.ffn.receptance.weight\r\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "512   2048  0    blocks.5.ffn.value.weight\r\n",
      "50277 512   0.5  head.weight\r\n"
     ]
    }
   ],
   "source": [
    "# Lets initialized the L6-D512 model with the init_model.py code\n",
    "!cd ../../RWKV-v4neo/ && python3 init_model.py --n_layer 6 --n_embd 512 --vocab_size neox ../model/L6-D512-neox-init.pth"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "rwkv-exp",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  },
  "papermill": {
   "default_parameters": {},
   "duration": 11.521627,
   "end_time": "2023-08-23T10:54:09.274570",
   "environment_variables": {},
   "exception": null,
   "input_path": "/actions-runner/_work/RWKV-infctx-trainer/RWKV-infctx-trainer/notebook/trainer-v4-unit-test/model-init.ipynb",
   "output_path": "/actions-runner/_work/RWKV-infctx-trainer/RWKV-infctx-trainer/output/trainer-v4-unit-test/model-init.ipynb",
   "parameters": {},
   "start_time": "2023-08-23T10:53:57.752943",
   "version": "2.4.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}