Skip to content

Commit 4909ed8

Browse files
Merge branch 'main' into dev/gokul/flmrife-cat-shape
2 parents 0cd3c80 + 53d6bdd commit 4909ed8

12 files changed

Lines changed: 115 additions & 66 deletions

File tree

.github/workflows/ci.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
push:
7+
branches: [main]
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
lint:
15+
if: github.repository == 'apple/coreai-torch'
16+
runs-on: [self-hosted, macos, tahoe, ARM64]
17+
timeout-minutes: 15
18+
steps:
19+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
20+
- name: Ensure uv
21+
run: |
22+
command -v uv >/dev/null 2>&1 || curl -LsSf https://astral.sh/uv/install.sh | sh
23+
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
24+
- run: uv run --extra dev ruff check .
25+
- run: uv run --extra dev ruff format --check .
26+
27+
python-test:
28+
if: github.repository == 'apple/coreai-torch'
29+
runs-on: [self-hosted, macos, tahoe, ARM64]
30+
timeout-minutes: 60
31+
steps:
32+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
33+
- name: Ensure uv
34+
run: |
35+
command -v uv >/dev/null 2>&1 || curl -LsSf https://astral.sh/uv/install.sh | sh
36+
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
37+
- run: uv run --extra test pytest tests/ -n auto -m "not slow"

coreai_torch/_compression/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def repeat_tensor_as(tensor: torch.Tensor, target_shape: torch.Size) -> torch.Te
9999
)
100100
return repeated_tensor
101101

102+
102103
def wrap_for_parametrization(
103104
compression_module_class: type[torch.nn.Module],
104105
) -> type[torch.nn.Module]:

docs/coreai-core/tutorials/construct-a-graph.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,10 @@
7676
"\n",
7777
"import numpy as np\n",
7878
"\n",
79-
"from coreai.authoring import AIModelAsset, AIProgram, Module, TensorSpec\n",
80-
"\n",
8179
"# Graph-building primitives — pending re-export from coreai.authoring.\n",
8280
"from coreai._compiler.dialects import coreai as ops\n",
83-
"from coreai._compiler.ir import Value"
81+
"from coreai._compiler.ir import Value\n",
82+
"from coreai.authoring import AIModelAsset, AIProgram, Module, TensorSpec"
8483
]
8584
},
8685
{
@@ -175,6 +174,7 @@
175174
" ) -> Annotated[Value, output_spec]:\n",
176175
" return ops.add(x, x)\n",
177176
"\n",
177+
"\n",
178178
"module.verify()\n",
179179
"print(\"Module verified.\")"
180180
]

docs/coreai-core/tutorials/run-an-aimodel.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
"from pathlib import Path\n",
6565
"\n",
6666
"import numpy as np\n",
67-
"\n",
6867
"from coreai.authoring import AIModelAsset\n",
6968
"from coreai.runtime import InferenceFunction, NDArray\n",
7069
"\n",
@@ -108,10 +107,10 @@
108107
"from shutil import rmtree\n",
109108
"from typing import Annotated\n",
110109
"\n",
111-
"from coreai.authoring import AIProgram, Module, TensorSpec\n",
112110
"# Pending re-export from coreai.authoring; see the previous tutorial.\n",
113111
"from coreai._compiler.dialects import coreai as ops\n",
114112
"from coreai._compiler.ir import Value\n",
113+
"from coreai.authoring import AIProgram, Module, TensorSpec\n",
115114
"\n",
116115
"# Reconstruct asset.\n",
117116
"if asset_path.exists():\n",
@@ -126,6 +125,7 @@
126125
" ) -> Annotated[Value, TensorSpec(shape=[2, 3], dtype=np.float32, name=\"y\")]:\n",
127126
" return ops.add(x, x)\n",
128127
"\n",
128+
"\n",
129129
"AIProgram(module).save_asset(asset_path)\n",
130130
"print(f\"created {asset_path}\")"
131131
]

docs/getting-started/quickstart.ipynb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@
6868
"metadata": {},
6969
"outputs": [],
7070
"source": [
71-
"import torch\n",
72-
"\n",
7371
"example_input = (torch.randn(1, 10),)\n",
7472
"exported = torch.export.export(model, args=example_input)"
7573
]
@@ -145,10 +143,10 @@
145143
"outputs": [],
146144
"source": [
147145
"import tempfile\n",
148-
"import torch\n",
149146
"from pathlib import Path\n",
150147
"\n",
151148
"import numpy as np\n",
149+
"import torch\n",
152150
"from coreai.runtime import NDArray\n",
153151
"\n",
154152
"\n",
@@ -240,9 +238,6 @@
240238
"metadata": {},
241239
"outputs": [],
242240
"source": [
243-
"import tempfile\n",
244-
"\n",
245-
"\n",
246241
"async def run():\n",
247242
" with tempfile.TemporaryDirectory() as tmpdir:\n",
248243
" asset = coreai_program.save_asset(Path(tmpdir) / \"mobilenet_v2_example.aimodel\")\n",
@@ -274,6 +269,7 @@
274269
"outputs": [],
275270
"source": [
276271
"import torch\n",
272+
"\n",
277273
"import coreai_torch\n",
278274
"\n",
279275
"model = SimpleModel().eval()\n",

docs/guides/composite-ops.ipynb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,6 @@
9797
"metadata": {},
9898
"outputs": [],
9999
"source": [
100-
"import torch\n",
101-
"import torch.nn as nn\n",
102-
"from coreai_torch.composite_ops import RMSNormImpl\n",
103-
"\n",
104-
"\n",
105100
"class RMSNorm(nn.Module):\n",
106101
" \"\"\"Convenience wrapper that owns the learnable scale parameter.\"\"\"\n",
107102
"\n",
@@ -149,7 +144,6 @@
149144
"outputs": [],
150145
"source": [
151146
"import torch\n",
152-
"import coreai_torch\n",
153147
"\n",
154148
"coreai_program = (\n",
155149
" TorchConverter()\n",
@@ -185,10 +179,10 @@
185179
"outputs": [],
186180
"source": [
187181
"import tempfile\n",
188-
"import torch\n",
189182
"from pathlib import Path\n",
190183
"\n",
191184
"import numpy as np\n",
185+
"import torch\n",
192186
"from coreai.runtime import NDArray\n",
193187
"\n",
194188
"\n",

docs/guides/conversion-workflows.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
"outputs": [],
8787
"source": [
8888
"import torch\n",
89+
"\n",
8990
"import coreai_torch\n",
9091
"\n",
9192
"model = MyModel().eval()\n",
@@ -133,7 +134,7 @@
133134
"source": [
134135
"import torch\n",
135136
"import torch.nn as nn\n",
136-
"import coreai_torch\n",
137+
"\n",
137138
"from coreai_torch import ExternalizeSpec, TorchConverter\n",
138139
"from coreai_torch.composite_ops import RMSNormImpl\n",
139140
"\n",

docs/guides/custom-metal-kernels.ipynb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
"outputs": [],
123123
"source": [
124124
"import torch\n",
125+
"\n",
125126
"from coreai_torch import get_decomp_table\n",
126127
"\n",
127128
"model = AddModel().eval()\n",
@@ -182,6 +183,7 @@
182183
"source": [
183184
"import torch\n",
184185
"\n",
186+
"\n",
185187
"def torch_matmul(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:\n",
186188
" return torch.matmul(x, y)\n",
187189
"\n",
@@ -222,6 +224,7 @@
222224
"import torch\n",
223225
"import torch.nn as nn\n",
224226
"\n",
227+
"\n",
225228
"def torch_sincos(x: torch.Tensor) -> list[torch.Tensor]:\n",
226229
" return [torch.sin(x), torch.cos(x)]\n",
227230
"\n",

docs/guides/custom-op-lowering.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
"outputs": [],
9393
"source": [
9494
"import torch\n",
95+
"\n",
9596
"from coreai_torch import get_decomp_table\n",
9697
"\n",
9798
"model = ScaledAddModel().eval()\n",
@@ -198,9 +199,9 @@
198199
"metadata": {},
199200
"outputs": [],
200201
"source": [
202+
"import numpy as np\n",
201203
"import torch\n",
202204
"import torch.nn as nn\n",
203-
"import numpy as np\n",
204205
"\n",
205206
"from coreai_torch._utils import get_operand\n",
206207
"\n",

docs/guides/externalization.ipynb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@
8686
"import torch\n",
8787
"import torch.nn as nn\n",
8888
"\n",
89-
"from coreai_torch import ExternalizeSpec\n",
90-
"\n",
9189
"\n",
9290
"class RMSNormComposite(nn.Module):\n",
9391
" def __init__(self, axes=-1, eps=1e-5, version=1):\n",
@@ -101,6 +99,7 @@
10199
" inv_rms = torch.rsqrt((x_f32 * x_f32).mean(self.axes, keepdim=True) + self.eps)\n",
102100
" return (input * inv_rms).to(input.dtype) * scale\n",
103101
"\n",
102+
"\n",
104103
"model = RMSNormComposite().eval()\n",
105104
"sample = (torch.randn(10), torch.randn(10))"
106105
]

0 commit comments

Comments
 (0)