forked from jundot/omlx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
79 lines (66 loc) · 2.63 KB
/
Copy pathsetup.py
File metadata and controls
79 lines (66 loc) · 2.63 KB
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
import os
import sys
from setuptools import setup
CUSTOM_KERNEL_FLAG = "--with-custom-kernel"
TRUTHY = {"1", "true", "yes", "on"}
DEFAULT_CUSTOM_KERNEL_DEPLOYMENT_TARGET = "15.0"
def _with_custom_kernel() -> bool:
if CUSTOM_KERNEL_FLAG in sys.argv:
sys.argv.remove(CUSTOM_KERNEL_FLAG)
return True
return os.environ.get("OMLX_WITH_CUSTOM_KERNEL", "").strip().lower() in TRUTHY
def _custom_kernel_build_kwargs() -> dict:
if not _with_custom_kernel():
return {}
target = (
os.environ.get("OMLX_CUSTOM_KERNEL_DEPLOYMENT_TARGET")
or os.environ.get("MACOSX_DEPLOYMENT_TARGET")
or DEFAULT_CUSTOM_KERNEL_DEPLOYMENT_TARGET
)
os.environ.setdefault("MACOSX_DEPLOYMENT_TARGET", target)
cmake_args = os.environ.get("CMAKE_ARGS", "").strip()
if "CMAKE_OSX_DEPLOYMENT_TARGET" not in cmake_args:
target_arg = f"-DCMAKE_OSX_DEPLOYMENT_TARGET={target}"
os.environ["CMAKE_ARGS"] = (
f"{cmake_args} {target_arg}".strip() if cmake_args else target_arg
)
cmake_args = os.environ["CMAKE_ARGS"]
# CMake otherwise chooses the first framework Python on PATH, which can
# differ from the interpreter running pip (and lack nanobind / MLX). The
# extensions must use the active environment's ABI and CMake packages.
python_args = " ".join(
(
f"-DPython_EXECUTABLE={sys.executable}",
f"-DPython3_EXECUTABLE={sys.executable}",
)
)
if "Python_EXECUTABLE" not in cmake_args:
os.environ["CMAKE_ARGS"] = f"{cmake_args} {python_args}".strip()
from mlx import extension
return {
"ext_modules": [
extension.CMakeExtension(
"omlx.custom_kernels.bonsai._ext",
sourcedir="omlx/custom_kernels/bonsai/csrc",
),
extension.CMakeExtension(
"omlx.custom_kernels.decode_fast._ext",
sourcedir="omlx/custom_kernels/decode_fast/csrc",
),
extension.CMakeExtension(
"omlx.custom_kernels.glm_moe_dsa._ext",
sourcedir="omlx/custom_kernels/glm_moe_dsa/csrc",
),
extension.CMakeExtension(
"omlx.custom_kernels.minimax_m3._ext",
sourcedir="omlx/custom_kernels/minimax_m3/csrc",
),
extension.CMakeExtension(
"omlx.custom_kernels.qwen35_prefill._ext",
sourcedir="omlx/custom_kernels/qwen35_prefill/csrc",
),
],
"cmdclass": {"build_ext": extension.CMakeBuild},
}
if __name__ == "__main__":
setup(**_custom_kernel_build_kwargs())