Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion coreai_torch/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1573,7 +1573,7 @@ def _dynamic_shapes_from_node(node: fx.Node) -> tuple[dict[int, Dim] | None, ...
dims = {
j: _dim_for_sym(s, cache)
for j, s in enumerate(val.shape)
if isinstance(s, torch.SymInt)
if isinstance(s, torch.SymInt) and not s.node.expr.is_number
}
result.append(dims or None)
return tuple(result)
Expand Down
171 changes: 36 additions & 135 deletions docs/coreai-core/tutorials/construct-a-graph.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"id": "intro",
"id": "0",
"metadata": {},
"source": [
"# Constructing a CoreAI Graph\n",
Expand All @@ -25,7 +25,7 @@
},
{
"cell_type": "markdown",
"id": "warning",
"id": "1",
"metadata": {},
"source": [
":::{warning}\n",
Expand All @@ -39,7 +39,7 @@
},
{
"cell_type": "markdown",
"id": "setup-md",
"id": "2",
"metadata": {},
"source": [
"## Setup\n",
Expand All @@ -50,25 +50,10 @@
},
{
"cell_type": "code",
"execution_count": 1,
"id": "imports",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-04T23:13:09.232797Z",
"iopub.status.busy": "2026-06-04T23:13:09.232330Z",
"iopub.status.idle": "2026-06-04T23:13:12.445622Z",
"shell.execute_reply": "2026-06-04T23:13:12.444678Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Dev installation detected. Using local Core AI Framework.\n"
]
}
],
"execution_count": null,
"id": "3",
"metadata": {},
"outputs": [],
"source": [
"import shutil\n",
"from pathlib import Path\n",
Expand All @@ -84,7 +69,7 @@
},
{
"cell_type": "markdown",
"id": "specs-md",
"id": "4",
"metadata": {},
"source": [
"## Describe the inputs and outputs\n",
Expand All @@ -99,26 +84,10 @@
},
{
"cell_type": "code",
"execution_count": 2,
"id": "specs",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-04T23:13:12.447443Z",
"iopub.status.busy": "2026-06-04T23:13:12.447294Z",
"iopub.status.idle": "2026-06-04T23:13:12.451834Z",
"shell.execute_reply": "2026-06-04T23:13:12.451081Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"input: tensor<2x3xf32>\n",
"output: tensor<2x3xf32>\n"
]
}
],
"execution_count": null,
"id": "5",
"metadata": {},
"outputs": [],
"source": [
"input_spec = TensorSpec(shape=[2, 3], dtype=np.float32)\n",
"output_spec = TensorSpec(shape=[2, 3], dtype=np.float32, name=\"y\")\n",
Expand All @@ -129,7 +98,7 @@
},
{
"cell_type": "markdown",
"id": "build-md",
"id": "6",
"metadata": {},
"source": [
"## Build the graph\n",
Expand All @@ -145,25 +114,10 @@
},
{
"cell_type": "code",
"execution_count": 3,
"id": "build",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-04T23:13:12.453228Z",
"iopub.status.busy": "2026-06-04T23:13:12.453111Z",
"iopub.status.idle": "2026-06-04T23:13:12.470623Z",
"shell.execute_reply": "2026-06-04T23:13:12.470201Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Module verified.\n"
]
}
],
"execution_count": null,
"id": "7",
"metadata": {},
"outputs": [],
"source": [
"module = Module.create()\n",
"with module:\n",
Expand All @@ -181,7 +135,7 @@
},
{
"cell_type": "markdown",
"id": "program-md",
"id": "8",
"metadata": {},
"source": [
"## Wrap in an `AIProgram`\n",
Expand All @@ -192,24 +146,17 @@
},
{
"cell_type": "code",
"execution_count": 4,
"id": "program",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-04T23:13:12.472009Z",
"iopub.status.busy": "2026-06-04T23:13:12.471916Z",
"iopub.status.idle": "2026-06-04T23:13:12.474216Z",
"shell.execute_reply": "2026-06-04T23:13:12.473635Z"
}
},
"execution_count": null,
"id": "9",
"metadata": {},
"outputs": [],
"source": [
"program = AIProgram(module)"
]
},
{
"cell_type": "markdown",
"id": "save-md",
"id": "10",
"metadata": {},
"source": [
"## Save as an `.aimodel`\n",
Expand All @@ -222,25 +169,10 @@
},
{
"cell_type": "code",
"execution_count": 5,
"id": "save",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-04T23:13:12.475505Z",
"iopub.status.busy": "2026-06-04T23:13:12.475388Z",
"iopub.status.idle": "2026-06-04T23:13:12.479489Z",
"shell.execute_reply": "2026-06-04T23:13:12.479034Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"saved to: hello-graph.aimodel\n"
]
}
],
"execution_count": null,
"id": "11",
"metadata": {},
"outputs": [],
"source": [
"asset_path = Path(\"./hello-graph.aimodel\")\n",
"if asset_path.exists():\n",
Expand All @@ -252,7 +184,7 @@
},
{
"cell_type": "markdown",
"id": "inspect-md",
"id": "12",
"metadata": {},
"source": [
"## Inspect the saved asset\n",
Expand All @@ -263,26 +195,10 @@
},
{
"cell_type": "code",
"execution_count": 6,
"id": "inspect",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-04T23:13:12.480788Z",
"iopub.status.busy": "2026-06-04T23:13:12.480705Z",
"iopub.status.idle": "2026-06-04T23:13:12.483398Z",
"shell.execute_reply": "2026-06-04T23:13:12.483007Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"contents: ['main.hash', 'main.mlirb', 'metadata.json']\n",
"total size: 446 bytes\n"
]
}
],
"execution_count": null,
"id": "13",
"metadata": {},
"outputs": [],
"source": [
"files = sorted(p.name for p in asset_path.iterdir())\n",
"total_bytes = sum(p.stat().st_size for p in asset_path.rglob(\"*\") if p.is_file())\n",
Expand All @@ -293,7 +209,7 @@
},
{
"cell_type": "markdown",
"id": "validate-md",
"id": "14",
"metadata": {},
"source": [
"## Validate that the asset is loadable\n",
Expand All @@ -305,25 +221,10 @@
},
{
"cell_type": "code",
"execution_count": 7,
"id": "validate",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-04T23:13:12.484574Z",
"iopub.status.busy": "2026-06-04T23:13:12.484499Z",
"iopub.status.idle": "2026-06-04T23:13:12.498350Z",
"shell.execute_reply": "2026-06-04T23:13:12.497839Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"OK\n"
]
}
],
"execution_count": null,
"id": "15",
"metadata": {},
"outputs": [],
"source": [
"reloaded = AIModelAsset.load(asset_path)\n",
"async with reloaded.executable() as model:\n",
Expand Down
Loading
Loading