Skip to content

Commit 2f25ba6

Browse files
committed
Refactor: remove numpy and ml_dtypes dependencies
Project now uses torch exclusively for tensor operations. numpy was only used as a fallback conversion path and isinstance check; ml_dtypes had no remaining call sites. - Remove numpy fallback in _to_torch() and isinstance checks in code_runner.py and ci.py - Ensure _to_torch() always returns cpu+contiguous tensors; remove redundant .cpu().contiguous() at call sites - Remove pip install numpy/ml_dtypes from all CI workflow jobs; sim jobs now use pip install '.[test]' instead of separate installs - Add Dependencies section to python-packaging.md documenting the simpler vs simpler_setup dependency split - Update getting-started.md install commands and docstrings
1 parent 131de2a commit 2f25ba6

7 files changed

Lines changed: 31 additions & 52 deletions

File tree

.github/workflows/ci.yml

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
python-version: '3.10'
3131

3232
- name: Install Python dependencies
33-
run: pip install numpy ml_dtypes
33+
run: pip install torch --index-url https://download.pytorch.org/whl/cpu
3434

3535
- name: Install package (for pyright C extension symbol resolution)
3636
run: pip install .
@@ -90,8 +90,7 @@ jobs:
9090
python3 -m venv .venv
9191
. .venv/bin/activate
9292
pip install --upgrade pip
93-
pip install scikit-build-core nanobind cmake
94-
pip install numpy ml_dtypes pytest
93+
pip install scikit-build-core nanobind cmake pytest
9594
pip install torch --index-url https://download.pytorch.org/whl/cpu
9695
9796
- name: Run packaging matrix (5 modes × 4 entry points, fully isolated)
@@ -126,13 +125,8 @@ jobs:
126125
127126
- name: Install dependencies
128127
run: |
129-
pip install numpy
130-
pip install ml_dtypes
131-
pip install pytest
132128
pip install torch --index-url https://download.pytorch.org/whl/cpu
133-
134-
- name: Build nanobind extension
135-
run: pip install .
129+
pip install '.[test]'
136130
137131
- name: Run unit tests
138132
run: pytest tests -m "not requires_hardware" -v
@@ -210,13 +204,8 @@ jobs:
210204
211205
- name: Install dependencies
212206
run: |
213-
pip install numpy
214-
pip install ml_dtypes
215-
pip install pytest
216207
pip install torch --index-url https://download.pytorch.org/whl/cpu
217-
218-
- name: Build nanobind extension
219-
run: pip install .
208+
pip install '.[test]'
220209
221210
- name: Run simulation examples (a2a3sim)
222211
run: python ci.py -p a2a3sim -c d96c8784 -t 600 --clone-protocol https
@@ -274,13 +263,8 @@ jobs:
274263
275264
- name: Install dependencies
276265
run: |
277-
pip install numpy
278-
pip install ml_dtypes
279-
pip install pytest
280266
pip install torch --index-url https://download.pytorch.org/whl/cpu
281-
282-
- name: Build nanobind extension
283-
run: pip install .
267+
pip install '.[test]'
284268
285269
- name: Run simulation examples (a5sim)
286270
run: python ci.py -p a5sim -c d96c8784 -t 600 --clone-protocol https

ci.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,6 @@ def run_single_task(
425425
"""Run all cases in a compiled task on a given worker. Returns True if all pass."""
426426
import ctypes # noqa: PLC0415
427427

428-
import numpy as np # noqa: PLC0415
429428
import torch # noqa: PLC0415
430429

431430
from simpler_setup.code_runner import _kernel_config_runtime_env, _temporary_env # noqa: PLC0415
@@ -449,12 +448,8 @@ def run_single_task(
449448

450449
for item in result:
451450
name, value = item
452-
if isinstance(value, (torch.Tensor, np.ndarray)):
453-
tensor = (
454-
torch.as_tensor(value).cpu().contiguous()
455-
if not isinstance(value, torch.Tensor)
456-
else value.cpu().contiguous()
457-
)
451+
if isinstance(value, torch.Tensor):
452+
tensor = value.cpu().contiguous()
458453
args[name] = tensor
459454
orch_args.add_tensor(make_tensor_arg(tensor))
460455
if name in output_set:

docs/getting-started.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ All workflows assume an activated project-local venv (see [`.claude/rules/venv-i
8888
```bash
8989
python3 -m venv --system-site-packages .venv
9090
source .venv/bin/activate
91-
pip install --no-build-isolation scikit-build-core nanobind cmake pytest numpy ml_dtypes torch
91+
pip install --no-build-isolation scikit-build-core nanobind cmake pytest torch
9292
pip install --no-build-isolation -e .
9393
```
9494

@@ -217,7 +217,7 @@ python examples/scripts/run_example.py -k <kernels> -g <golden.py> -p a2a3 --dev
217217
- **Handshake cores**: Usually 3 (1c2v configuration: 1 core, 2 vector units)
218218
- **Kernel compilation**: Requires `ASCEND_HOME_PATH` environment variable
219219
- **Memory management**: MemoryAllocator automatically tracks allocations
220-
- **Python requirement**: NumPy for efficient array operations
220+
- **Python requirement**: PyTorch for tensor operations in golden scripts
221221

222222
## Logging
223223

docs/python-packaging.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ _task_interface.*.so nanobind extension at site-packages root
4747

4848
Internal coupling: `simpler_setup.toolchain`, `simpler_setup.kernel_compiler`, and `simpler_setup.runtime_compiler` import `simpler.env_manager`. This is the only direction allowed (`simpler_setup → simpler`); never the reverse. `simpler` must not depend on `simpler_setup`.
4949

50+
### Dependencies
51+
52+
| Category | Packages |
53+
| -------- | -------- |
54+
| `simpler` runtime | No third-party Python deps. Requires platform backend: simulation (`a*sim`) or NPU hardware (`a2a3`/`a5` with CANN toolkit) |
55+
| `simpler_setup` runtime | `torch` (tensor operations in golden scripts, test comparison) |
56+
| Build | `scikit-build-core`, `nanobind`, `cmake` |
57+
| Test | `pytest` (ut-py, st), `googletest` + `ctest` (ut-cpp) |
58+
59+
`pyproject.toml` declares no `[project.dependencies]` — both `torch` and `pytest` are environment prerequisites, not pip-installed transitively. This is intentional: torch's index URL (`--index-url https://download.pytorch.org/whl/cpu`) and hardware-specific builds make automatic resolution impractical.
60+
5061
### `PROJECT_ROOT` resolution
5162

5263
`simpler_setup.environment.PROJECT_ROOT` auto-detects between:
@@ -107,7 +118,7 @@ For developers who don't want to use pip at all:
107118

108119
```bash
109120
. .venv/bin/activate
110-
pip install scikit-build-core nanobind cmake pytest numpy ml_dtypes torch # one-time
121+
pip install scikit-build-core nanobind cmake pytest torch # one-time
111122
cmake -S . -B build/cmake_only -Dnanobind_DIR=$(python -c 'import nanobind; print(nanobind.cmake_dir())')
112123
cmake --build build/cmake_only
113124
export PYTHONPATH=$(pwd):$(pwd)/python
@@ -125,7 +136,7 @@ The cmake build places `_task_interface.cpython-XYZ.so` directly into `python/`
125136
| `python ci.py` ||||||
126137
| `python examples/scripts/run_example.py` ||||||
127138

128-
On macOS, set `KMP_DUPLICATE_LIB_OK=TRUE` to silence the homebrew-numpy + pip-torch libomp collision (also documented in `ci.py`).
139+
On macOS with `--system-site-packages`, set `KMP_DUPLICATE_LIB_OK=TRUE` if the system numpy is present and its libomp collides with torch's (see `docs/macos-libomp-collision.md`).
129140

130141
## Verification protocol when changing package structure
131142

@@ -144,7 +155,7 @@ Any change that touches:
144155
```bash
145156
# Locally — same script CI runs.
146157
source .venv/bin/activate
147-
pip install scikit-build-core nanobind cmake pytest numpy ml_dtypes torch # one-time
158+
pip install scikit-build-core nanobind cmake pytest torch # one-time
148159
bash tools/verify_packaging.sh
149160
```
150161

examples/scripts/run_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ def main(): # noqa: PLR0912
9595
9696
Golden.py interface:
9797
def generate_inputs(params: dict) -> dict:
98-
'''Return dict of numpy arrays (inputs + outputs)'''
99-
return {"a": np.array(...), "out_f": np.zeros(...)}
98+
'''Return dict of torch tensors (inputs + outputs)'''
99+
return {"a": torch.tensor(...), "out_f": torch.zeros(...)}
100100
101101
def compute_golden(tensors: dict, params: dict) -> None:
102102
'''Compute expected outputs in-place'''

simpler_setup/code_runner.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,8 @@ def _to_torch(tensor) -> torch.Tensor:
100100
# Already a torch tensor, ensure it's on CPU and contiguous
101101
return tensor.cpu().contiguous()
102102

103-
# For any non-torch tensor, try direct torch conversion first
104-
# This handles most array-like objects including numpy arrays
105-
try:
106-
return torch.as_tensor(tensor)
107-
except (TypeError, RuntimeError):
108-
# If direct conversion fails, fall back to numpy path
109-
import numpy as np # noqa: PLC0415 # type: ignore[import-not-found]
110-
111-
arr = np.asarray(tensor)
112-
return torch.from_numpy(arr)
103+
# For any non-torch tensor, convert directly
104+
return torch.as_tensor(tensor).cpu().contiguous()
113105

114106

115107
def _load_module_from_path(module_path: Path, module_name: str):
@@ -307,7 +299,7 @@ def _build_func_args_from_list(
307299
Build ChipStorageTaskArgs from an explicit argument list returned by generate_inputs.
308300
309301
Every element must be a (name, value) pair where value is either:
310-
- torch.Tensor / numpy array: a tensor argument
302+
- torch.Tensor: a tensor argument
311303
- ctypes scalar (ctypes.c_int64, ctypes.c_float, etc.): a scalar argument
312304
313305
All named items (tensors and scalars) are collected into the args dict
@@ -317,8 +309,6 @@ def _build_func_args_from_list(
317309
Tuple of (orch_args, args, inputs, outputs)
318310
where args contains all named items, inputs/outputs contain tensor-only subsets.
319311
"""
320-
import numpy as np # noqa: PLC0415 # type: ignore[import-not-found]
321-
322312
if not self.output_names:
323313
raise ValueError("No output tensors identified. Define __outputs__ = ['tensor_name'] in golden.py")
324314
output_set = set(self.output_names)
@@ -338,9 +328,8 @@ def _build_func_args_from_list(
338328

339329
name, value = item
340330

341-
if isinstance(value, (torch.Tensor, np.ndarray)):
331+
if isinstance(value, torch.Tensor):
342332
tensor = _to_torch(value)
343-
tensor = tensor.cpu().contiguous()
344333
args[name] = tensor
345334

346335
orch_args.add_tensor(make_tensor_arg(tensor))
@@ -357,7 +346,7 @@ def _build_func_args_from_list(
357346
else:
358347
raise TypeError(
359348
f"Unsupported value type for arg '{name}': {type(value)}\n"
360-
f"Expected torch.Tensor, numpy array, or ctypes scalar (ctypes.c_int64, ctypes.c_float, etc.)"
349+
f"Expected torch.Tensor or ctypes scalar (ctypes.c_int64, ctypes.c_float, etc.)"
361350
)
362351

363352
if not outputs:

tools/verify_packaging.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ print('simpler_setup:', simpler_setup.__file__)
8080
# ---------------------------------------------------------------------------
8181
python -c "import scikit_build_core, nanobind, cmake, torch, pytest" 2>/dev/null || {
8282
echo "ERROR: venv missing required deps. Install with:" >&2
83-
echo " pip install scikit-build-core nanobind cmake pytest numpy ml_dtypes torch" >&2
83+
echo " pip install scikit-build-core nanobind cmake pytest torch" >&2
8484
exit 1
8585
}
8686

0 commit comments

Comments
 (0)