|
2 | 2 | "cells": [ |
3 | 3 | { |
4 | 4 | "cell_type": "markdown", |
5 | | - "id": "intro", |
| 5 | + "id": "0", |
6 | 6 | "metadata": {}, |
7 | 7 | "source": [ |
8 | 8 | "# Constructing a CoreAI Graph\n", |
|
25 | 25 | }, |
26 | 26 | { |
27 | 27 | "cell_type": "markdown", |
28 | | - "id": "warning", |
| 28 | + "id": "1", |
29 | 29 | "metadata": {}, |
30 | 30 | "source": [ |
31 | 31 | ":::{warning}\n", |
|
39 | 39 | }, |
40 | 40 | { |
41 | 41 | "cell_type": "markdown", |
42 | | - "id": "setup-md", |
| 42 | + "id": "2", |
43 | 43 | "metadata": {}, |
44 | 44 | "source": [ |
45 | 45 | "## Setup\n", |
|
50 | 50 | }, |
51 | 51 | { |
52 | 52 | "cell_type": "code", |
53 | | - "execution_count": 1, |
54 | | - "id": "imports", |
55 | | - "metadata": { |
56 | | - "execution": { |
57 | | - "iopub.execute_input": "2026-06-04T23:13:09.232797Z", |
58 | | - "iopub.status.busy": "2026-06-04T23:13:09.232330Z", |
59 | | - "iopub.status.idle": "2026-06-04T23:13:12.445622Z", |
60 | | - "shell.execute_reply": "2026-06-04T23:13:12.444678Z" |
61 | | - } |
62 | | - }, |
63 | | - "outputs": [ |
64 | | - { |
65 | | - "name": "stderr", |
66 | | - "output_type": "stream", |
67 | | - "text": [ |
68 | | - "Dev installation detected. Using local Core AI Framework.\n" |
69 | | - ] |
70 | | - } |
71 | | - ], |
| 53 | + "execution_count": null, |
| 54 | + "id": "3", |
| 55 | + "metadata": {}, |
| 56 | + "outputs": [], |
72 | 57 | "source": [ |
73 | 58 | "import shutil\n", |
74 | 59 | "from pathlib import Path\n", |
|
84 | 69 | }, |
85 | 70 | { |
86 | 71 | "cell_type": "markdown", |
87 | | - "id": "specs-md", |
| 72 | + "id": "4", |
88 | 73 | "metadata": {}, |
89 | 74 | "source": [ |
90 | 75 | "## Describe the inputs and outputs\n", |
|
99 | 84 | }, |
100 | 85 | { |
101 | 86 | "cell_type": "code", |
102 | | - "execution_count": 2, |
103 | | - "id": "specs", |
104 | | - "metadata": { |
105 | | - "execution": { |
106 | | - "iopub.execute_input": "2026-06-04T23:13:12.447443Z", |
107 | | - "iopub.status.busy": "2026-06-04T23:13:12.447294Z", |
108 | | - "iopub.status.idle": "2026-06-04T23:13:12.451834Z", |
109 | | - "shell.execute_reply": "2026-06-04T23:13:12.451081Z" |
110 | | - } |
111 | | - }, |
112 | | - "outputs": [ |
113 | | - { |
114 | | - "name": "stdout", |
115 | | - "output_type": "stream", |
116 | | - "text": [ |
117 | | - "input: tensor<2x3xf32>\n", |
118 | | - "output: tensor<2x3xf32>\n" |
119 | | - ] |
120 | | - } |
121 | | - ], |
| 87 | + "execution_count": null, |
| 88 | + "id": "5", |
| 89 | + "metadata": {}, |
| 90 | + "outputs": [], |
122 | 91 | "source": [ |
123 | 92 | "input_spec = TensorSpec(shape=[2, 3], dtype=np.float32)\n", |
124 | 93 | "output_spec = TensorSpec(shape=[2, 3], dtype=np.float32, name=\"y\")\n", |
|
129 | 98 | }, |
130 | 99 | { |
131 | 100 | "cell_type": "markdown", |
132 | | - "id": "build-md", |
| 101 | + "id": "6", |
133 | 102 | "metadata": {}, |
134 | 103 | "source": [ |
135 | 104 | "## Build the graph\n", |
|
145 | 114 | }, |
146 | 115 | { |
147 | 116 | "cell_type": "code", |
148 | | - "execution_count": 3, |
149 | | - "id": "build", |
150 | | - "metadata": { |
151 | | - "execution": { |
152 | | - "iopub.execute_input": "2026-06-04T23:13:12.453228Z", |
153 | | - "iopub.status.busy": "2026-06-04T23:13:12.453111Z", |
154 | | - "iopub.status.idle": "2026-06-04T23:13:12.470623Z", |
155 | | - "shell.execute_reply": "2026-06-04T23:13:12.470201Z" |
156 | | - } |
157 | | - }, |
158 | | - "outputs": [ |
159 | | - { |
160 | | - "name": "stdout", |
161 | | - "output_type": "stream", |
162 | | - "text": [ |
163 | | - "Module verified.\n" |
164 | | - ] |
165 | | - } |
166 | | - ], |
| 117 | + "execution_count": null, |
| 118 | + "id": "7", |
| 119 | + "metadata": {}, |
| 120 | + "outputs": [], |
167 | 121 | "source": [ |
168 | 122 | "module = Module.create()\n", |
169 | 123 | "with module:\n", |
|
181 | 135 | }, |
182 | 136 | { |
183 | 137 | "cell_type": "markdown", |
184 | | - "id": "program-md", |
| 138 | + "id": "8", |
185 | 139 | "metadata": {}, |
186 | 140 | "source": [ |
187 | 141 | "## Wrap in an `AIProgram`\n", |
|
192 | 146 | }, |
193 | 147 | { |
194 | 148 | "cell_type": "code", |
195 | | - "execution_count": 4, |
196 | | - "id": "program", |
197 | | - "metadata": { |
198 | | - "execution": { |
199 | | - "iopub.execute_input": "2026-06-04T23:13:12.472009Z", |
200 | | - "iopub.status.busy": "2026-06-04T23:13:12.471916Z", |
201 | | - "iopub.status.idle": "2026-06-04T23:13:12.474216Z", |
202 | | - "shell.execute_reply": "2026-06-04T23:13:12.473635Z" |
203 | | - } |
204 | | - }, |
| 149 | + "execution_count": null, |
| 150 | + "id": "9", |
| 151 | + "metadata": {}, |
205 | 152 | "outputs": [], |
206 | 153 | "source": [ |
207 | 154 | "program = AIProgram(module)" |
208 | 155 | ] |
209 | 156 | }, |
210 | 157 | { |
211 | 158 | "cell_type": "markdown", |
212 | | - "id": "save-md", |
| 159 | + "id": "10", |
213 | 160 | "metadata": {}, |
214 | 161 | "source": [ |
215 | 162 | "## Save as an `.aimodel`\n", |
|
222 | 169 | }, |
223 | 170 | { |
224 | 171 | "cell_type": "code", |
225 | | - "execution_count": 5, |
226 | | - "id": "save", |
227 | | - "metadata": { |
228 | | - "execution": { |
229 | | - "iopub.execute_input": "2026-06-04T23:13:12.475505Z", |
230 | | - "iopub.status.busy": "2026-06-04T23:13:12.475388Z", |
231 | | - "iopub.status.idle": "2026-06-04T23:13:12.479489Z", |
232 | | - "shell.execute_reply": "2026-06-04T23:13:12.479034Z" |
233 | | - } |
234 | | - }, |
235 | | - "outputs": [ |
236 | | - { |
237 | | - "name": "stdout", |
238 | | - "output_type": "stream", |
239 | | - "text": [ |
240 | | - "saved to: hello-graph.aimodel\n" |
241 | | - ] |
242 | | - } |
243 | | - ], |
| 172 | + "execution_count": null, |
| 173 | + "id": "11", |
| 174 | + "metadata": {}, |
| 175 | + "outputs": [], |
244 | 176 | "source": [ |
245 | 177 | "asset_path = Path(\"./hello-graph.aimodel\")\n", |
246 | 178 | "if asset_path.exists():\n", |
|
252 | 184 | }, |
253 | 185 | { |
254 | 186 | "cell_type": "markdown", |
255 | | - "id": "inspect-md", |
| 187 | + "id": "12", |
256 | 188 | "metadata": {}, |
257 | 189 | "source": [ |
258 | 190 | "## Inspect the saved asset\n", |
|
263 | 195 | }, |
264 | 196 | { |
265 | 197 | "cell_type": "code", |
266 | | - "execution_count": 6, |
267 | | - "id": "inspect", |
268 | | - "metadata": { |
269 | | - "execution": { |
270 | | - "iopub.execute_input": "2026-06-04T23:13:12.480788Z", |
271 | | - "iopub.status.busy": "2026-06-04T23:13:12.480705Z", |
272 | | - "iopub.status.idle": "2026-06-04T23:13:12.483398Z", |
273 | | - "shell.execute_reply": "2026-06-04T23:13:12.483007Z" |
274 | | - } |
275 | | - }, |
276 | | - "outputs": [ |
277 | | - { |
278 | | - "name": "stdout", |
279 | | - "output_type": "stream", |
280 | | - "text": [ |
281 | | - "contents: ['main.hash', 'main.mlirb', 'metadata.json']\n", |
282 | | - "total size: 446 bytes\n" |
283 | | - ] |
284 | | - } |
285 | | - ], |
| 198 | + "execution_count": null, |
| 199 | + "id": "13", |
| 200 | + "metadata": {}, |
| 201 | + "outputs": [], |
286 | 202 | "source": [ |
287 | 203 | "files = sorted(p.name for p in asset_path.iterdir())\n", |
288 | 204 | "total_bytes = sum(p.stat().st_size for p in asset_path.rglob(\"*\") if p.is_file())\n", |
|
293 | 209 | }, |
294 | 210 | { |
295 | 211 | "cell_type": "markdown", |
296 | | - "id": "validate-md", |
| 212 | + "id": "14", |
297 | 213 | "metadata": {}, |
298 | 214 | "source": [ |
299 | 215 | "## Validate that the asset is loadable\n", |
|
305 | 221 | }, |
306 | 222 | { |
307 | 223 | "cell_type": "code", |
308 | | - "execution_count": 7, |
309 | | - "id": "validate", |
310 | | - "metadata": { |
311 | | - "execution": { |
312 | | - "iopub.execute_input": "2026-06-04T23:13:12.484574Z", |
313 | | - "iopub.status.busy": "2026-06-04T23:13:12.484499Z", |
314 | | - "iopub.status.idle": "2026-06-04T23:13:12.498350Z", |
315 | | - "shell.execute_reply": "2026-06-04T23:13:12.497839Z" |
316 | | - } |
317 | | - }, |
318 | | - "outputs": [ |
319 | | - { |
320 | | - "name": "stdout", |
321 | | - "output_type": "stream", |
322 | | - "text": [ |
323 | | - "OK\n" |
324 | | - ] |
325 | | - } |
326 | | - ], |
| 224 | + "execution_count": null, |
| 225 | + "id": "15", |
| 226 | + "metadata": {}, |
| 227 | + "outputs": [], |
327 | 228 | "source": [ |
328 | 229 | "reloaded = AIModelAsset.load(asset_path)\n", |
329 | 230 | "async with reloaded.executable() as model:\n", |
|
0 commit comments