mlx 0.32.4__cp315-cp315-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mlx/__array_api_info.py +82 -0
- mlx/__main__.py +27 -0
- mlx/_distributed_utils/common.py +138 -0
- mlx/_distributed_utils/config.py +647 -0
- mlx/_distributed_utils/launch.py +610 -0
- mlx/_reprlib_fix.py +16 -0
- mlx/core/__init__.pyi +5061 -0
- mlx/core/cuda.pyi +6 -0
- mlx/core/distributed.pyi +234 -0
- mlx/core/fast.pyi +330 -0
- mlx/core/fft.pyi +375 -0
- mlx/core/linalg.pyi +547 -0
- mlx/core/metal.pyi +36 -0
- mlx/core/random.pyi +248 -0
- mlx/core.cp315-win_amd64.pyd +0 -0
- mlx/extension.py +669 -0
- mlx/nn/__init__.py +8 -0
- mlx/nn/init.py +453 -0
- mlx/nn/layers/__init__.py +107 -0
- mlx/nn/layers/activations.py +675 -0
- mlx/nn/layers/base.py +713 -0
- mlx/nn/layers/containers.py +24 -0
- mlx/nn/layers/convolution.py +235 -0
- mlx/nn/layers/convolution_transpose.py +248 -0
- mlx/nn/layers/distributed.py +762 -0
- mlx/nn/layers/dropout.py +139 -0
- mlx/nn/layers/embedding.py +55 -0
- mlx/nn/layers/linear.py +187 -0
- mlx/nn/layers/normalization.py +415 -0
- mlx/nn/layers/pooling.py +411 -0
- mlx/nn/layers/positional_encoding.py +224 -0
- mlx/nn/layers/quantized.py +434 -0
- mlx/nn/layers/recurrent.py +291 -0
- mlx/nn/layers/transformer.py +360 -0
- mlx/nn/layers/upsample.py +489 -0
- mlx/nn/losses.py +639 -0
- mlx/nn/utils.py +210 -0
- mlx/optimizers/__init__.py +4 -0
- mlx/optimizers/optimizers.py +1009 -0
- mlx/optimizers/schedulers.py +161 -0
- mlx/py.typed +1 -0
- mlx/utils.py +345 -0
- mlx-0.32.4.dist-info/METADATA +159 -0
- mlx-0.32.4.dist-info/RECORD +48 -0
- mlx-0.32.4.dist-info/WHEEL +5 -0
- mlx-0.32.4.dist-info/entry_points.txt +3 -0
- mlx-0.32.4.dist-info/licenses/LICENSE +21 -0
- mlx-0.32.4.dist-info/top_level.txt +2 -0
mlx/__array_api_info.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
class ArrayNamespaceInfo:
|
|
2
|
+
def capabilities(self):
|
|
3
|
+
return {
|
|
4
|
+
"boolean indexing": False,
|
|
5
|
+
"data-dependent shapes": False,
|
|
6
|
+
"max dimensions": 10,
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
def default_device(self):
|
|
10
|
+
import mlx.core as mx
|
|
11
|
+
|
|
12
|
+
return mx.default_device()
|
|
13
|
+
|
|
14
|
+
def default_dtypes(self, *, device=None):
|
|
15
|
+
import mlx.core as mx
|
|
16
|
+
|
|
17
|
+
if device is not None and not isinstance(device, mx.Device):
|
|
18
|
+
raise TypeError("Expected a mlx Device")
|
|
19
|
+
return {
|
|
20
|
+
"real floating": mx.float32,
|
|
21
|
+
"complex floating": mx.complex64,
|
|
22
|
+
"integral": mx.int32,
|
|
23
|
+
"indexing": mx.int32,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
def devices(self):
|
|
27
|
+
import mlx.core as mx
|
|
28
|
+
|
|
29
|
+
devices = [
|
|
30
|
+
mx.Device(dev_type, i)
|
|
31
|
+
for dev_type in (mx.cpu, mx.gpu)
|
|
32
|
+
for i in range(mx.device_count(dev_type))
|
|
33
|
+
]
|
|
34
|
+
return tuple(devices)
|
|
35
|
+
|
|
36
|
+
def dtypes(self, *, device=None, kind=None):
|
|
37
|
+
import mlx.core as mx
|
|
38
|
+
|
|
39
|
+
if device is not None and not isinstance(device, mx.Device):
|
|
40
|
+
raise TypeError("Expected a mlx Device")
|
|
41
|
+
device = device if device is not None else self.default_device()
|
|
42
|
+
|
|
43
|
+
dtypes = {
|
|
44
|
+
"bool": mx.bool_,
|
|
45
|
+
"int8": mx.int8,
|
|
46
|
+
"int16": mx.int16,
|
|
47
|
+
"int32": mx.int32,
|
|
48
|
+
"int64": mx.int64,
|
|
49
|
+
"uint8": mx.uint8,
|
|
50
|
+
"uint16": mx.uint16,
|
|
51
|
+
"uint32": mx.uint32,
|
|
52
|
+
"uint64": mx.uint64,
|
|
53
|
+
"float32": mx.float32,
|
|
54
|
+
"complex64": mx.complex64,
|
|
55
|
+
}
|
|
56
|
+
if device.type == mx.cpu:
|
|
57
|
+
dtypes["float64"] = mx.float64
|
|
58
|
+
if kind is None:
|
|
59
|
+
return dtypes
|
|
60
|
+
|
|
61
|
+
signed = {"int8", "int16", "int32", "int64"}
|
|
62
|
+
unsigned = {"uint8", "uint16", "uint32", "uint64"}
|
|
63
|
+
real = {"float32", "float64"}
|
|
64
|
+
complex_ = {"complex64"}
|
|
65
|
+
kinds = {
|
|
66
|
+
"bool": {"bool"},
|
|
67
|
+
"signed integer": signed,
|
|
68
|
+
"unsigned integer": unsigned,
|
|
69
|
+
"integral": signed | unsigned,
|
|
70
|
+
"real floating": real,
|
|
71
|
+
"complex floating": complex_,
|
|
72
|
+
"numeric": signed | unsigned | real | complex_,
|
|
73
|
+
}
|
|
74
|
+
kind = (kind,) if isinstance(kind, str) else kind
|
|
75
|
+
if not isinstance(kind, tuple) or any(k not in kinds for k in kind):
|
|
76
|
+
raise ValueError(f"Unsupported dtype kind: {kind!r}")
|
|
77
|
+
names = {name for k in kind for name in kinds[k]}
|
|
78
|
+
return {name: dtype for name, dtype in dtypes.items() if name in names}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def __array_namespace_info__():
|
|
82
|
+
return ArrayNamespaceInfo()
|
mlx/__main__.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def main() -> None:
|
|
5
|
+
from mlx.core import __version__
|
|
6
|
+
|
|
7
|
+
parser = argparse.ArgumentParser()
|
|
8
|
+
parser.add_argument(
|
|
9
|
+
"--version",
|
|
10
|
+
action="version",
|
|
11
|
+
version=__version__,
|
|
12
|
+
help="Print the version number.",
|
|
13
|
+
)
|
|
14
|
+
parser.add_argument(
|
|
15
|
+
"--cmake-dir",
|
|
16
|
+
action="store_true",
|
|
17
|
+
help="Print the path to the MLX CMake module directory.",
|
|
18
|
+
)
|
|
19
|
+
args = parser.parse_args()
|
|
20
|
+
if args.cmake_dir:
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
|
|
23
|
+
print(Path(__file__).parent)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
if __name__ == "__main__":
|
|
27
|
+
main()
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# Copyright © 2025 Apple Inc.
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import ipaddress
|
|
5
|
+
import json
|
|
6
|
+
import sys
|
|
7
|
+
from dataclasses import dataclass, field
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Optional, Union
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass
|
|
13
|
+
class Host:
|
|
14
|
+
rank: int
|
|
15
|
+
ssh_hostname: str
|
|
16
|
+
ips: list[str]
|
|
17
|
+
rdma: list[Optional[Union[str, list[str]]]]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass
|
|
21
|
+
class Hostfile:
|
|
22
|
+
hosts: list[Host]
|
|
23
|
+
backend: str = ""
|
|
24
|
+
envs: list[str] = field(default_factory=list)
|
|
25
|
+
|
|
26
|
+
def to_json(self):
|
|
27
|
+
return {
|
|
28
|
+
"backend": self.backend,
|
|
29
|
+
"envs": self.envs,
|
|
30
|
+
"hosts": [
|
|
31
|
+
{"ssh": h.ssh_hostname, "ips": h.ips, "rdma": h.rdma}
|
|
32
|
+
for h in self.hosts
|
|
33
|
+
],
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@classmethod
|
|
37
|
+
def from_file(cls, hostfile):
|
|
38
|
+
"""Parse the json hostfile that contains both the hostnames to ssh into and
|
|
39
|
+
the ips to communicate over when using the ring backend. It can also
|
|
40
|
+
contain the backend to be used and environment variables to set when
|
|
41
|
+
launching a distributed job.
|
|
42
|
+
|
|
43
|
+
Example:
|
|
44
|
+
|
|
45
|
+
{
|
|
46
|
+
"backend": "jaccl",
|
|
47
|
+
"envs": [
|
|
48
|
+
"MLX_METAL_FAST_SYNCH=1"
|
|
49
|
+
],
|
|
50
|
+
"hosts": [
|
|
51
|
+
{"ssh": "hostname1", "ips": ["123.123.123.1"],
|
|
52
|
+
"rdma": [null, "rdma_en2", "rdma_en3"]},
|
|
53
|
+
{"ssh": "hostname2", "ips": ["123.123.123.2"],
|
|
54
|
+
"rdma": ["rdma_en2", null, "rdma_en3"]},
|
|
55
|
+
...
|
|
56
|
+
{"ssh": "hostnameN", "ips": ["123.123.123.N"],
|
|
57
|
+
"rdma": ["rdma_en2", "rdma_en3", null]},
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
hostfile (str): The path to the json file containing the host
|
|
63
|
+
information
|
|
64
|
+
"""
|
|
65
|
+
hostfile = Path(hostfile)
|
|
66
|
+
if not hostfile.exists():
|
|
67
|
+
raise ValueError(f"Hostfile {str(hostfile)} doesn't exist")
|
|
68
|
+
|
|
69
|
+
try:
|
|
70
|
+
data = json.load(open(hostfile))
|
|
71
|
+
backend = ""
|
|
72
|
+
envs = []
|
|
73
|
+
hosts = []
|
|
74
|
+
if isinstance(data, dict):
|
|
75
|
+
backend = data.get("backend", backend)
|
|
76
|
+
envs = data.get("envs", envs)
|
|
77
|
+
hosts = data["hosts"]
|
|
78
|
+
elif isinstance(data, list):
|
|
79
|
+
hosts = data
|
|
80
|
+
|
|
81
|
+
hosts = [
|
|
82
|
+
Host(i, h["ssh"], h.get("ips", []), h.get("rdma", []))
|
|
83
|
+
for i, h in enumerate(hosts)
|
|
84
|
+
]
|
|
85
|
+
|
|
86
|
+
return cls(hosts, backend, envs)
|
|
87
|
+
|
|
88
|
+
except Exception as e:
|
|
89
|
+
raise ValueError(
|
|
90
|
+
f"Failed to parse hostfile {str(hostfile)} ({str(e)})"
|
|
91
|
+
) from e
|
|
92
|
+
|
|
93
|
+
@classmethod
|
|
94
|
+
def from_list(cls, hostlist, repeats=1):
|
|
95
|
+
hosts = []
|
|
96
|
+
for h in hostlist.split(","):
|
|
97
|
+
if h == "":
|
|
98
|
+
raise ValueError("Hostname cannot be empty")
|
|
99
|
+
try:
|
|
100
|
+
ipaddress.ip_address(h)
|
|
101
|
+
ips = [h]
|
|
102
|
+
except ValueError:
|
|
103
|
+
ips = []
|
|
104
|
+
for _ in range(repeats):
|
|
105
|
+
hosts.append(Host(len(hosts), h, ips, []))
|
|
106
|
+
return cls(hosts)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class OptionalBoolAction(argparse.Action):
|
|
110
|
+
def __call__(self, parser, namespace, values, option_string=None):
|
|
111
|
+
if option_string.startswith("--no-"):
|
|
112
|
+
setattr(namespace, self.dest, False)
|
|
113
|
+
else:
|
|
114
|
+
setattr(namespace, self.dest, True)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def positive_number(x):
|
|
118
|
+
x = int(x)
|
|
119
|
+
if x <= 0:
|
|
120
|
+
raise ValueError("Number should be positive")
|
|
121
|
+
return x
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def log(verbose, *args, **kwargs):
|
|
125
|
+
if not verbose:
|
|
126
|
+
return
|
|
127
|
+
kwargs["file"] = sys.stderr
|
|
128
|
+
print("\033[32m[INFO]", *args, "\033[0m", **kwargs)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def log_warning(*args, **kwargs):
|
|
132
|
+
kwargs["file"] = sys.stderr
|
|
133
|
+
print("\033[33m[WARN]", *args, "\033[0m", **kwargs)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def log_error(*args, **kwargs):
|
|
137
|
+
kwargs["file"] = sys.stderr
|
|
138
|
+
print("\033[31m[ERROR]", *args, "\033[0m", **kwargs)
|