mlx 0.32.0__cp313-cp313-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/__main__.py +27 -0
- mlx/_distributed_utils/common.py +135 -0
- mlx/_distributed_utils/config.py +639 -0
- mlx/_distributed_utils/launch.py +562 -0
- mlx/_reprlib_fix.py +16 -0
- mlx/core.cp313-win_amd64.pyd +0 -0
- mlx/extension.py +88 -0
- mlx/nn/__init__.py +9 -0
- mlx/nn/init.py +451 -0
- mlx/nn/layers/__init__.py +105 -0
- mlx/nn/layers/activations.py +667 -0
- mlx/nn/layers/base.py +689 -0
- mlx/nn/layers/containers.py +24 -0
- mlx/nn/layers/convolution.py +235 -0
- mlx/nn/layers/convolution_transpose.py +245 -0
- mlx/nn/layers/distributed.py +619 -0
- mlx/nn/layers/dropout.py +137 -0
- mlx/nn/layers/embedding.py +53 -0
- mlx/nn/layers/linear.py +180 -0
- mlx/nn/layers/normalization.py +381 -0
- mlx/nn/layers/pooling.py +398 -0
- mlx/nn/layers/positional_encoding.py +174 -0
- mlx/nn/layers/quantized.py +426 -0
- mlx/nn/layers/recurrent.py +291 -0
- mlx/nn/layers/transformer.py +354 -0
- mlx/nn/layers/upsample.py +277 -0
- mlx/nn/losses.py +614 -0
- mlx/nn/utils.py +321 -0
- mlx/optimizers/__init__.py +4 -0
- mlx/optimizers/optimizers.py +974 -0
- mlx/optimizers/schedulers.py +158 -0
- mlx/py.typed +1 -0
- mlx/utils.py +326 -0
- mlx-0.32.0.dist-info/METADATA +159 -0
- mlx-0.32.0.dist-info/RECORD +39 -0
- mlx-0.32.0.dist-info/WHEEL +5 -0
- mlx-0.32.0.dist-info/entry_points.txt +3 -0
- mlx-0.32.0.dist-info/licenses/LICENSE +21 -0
- mlx-0.32.0.dist-info/top_level.txt +1 -0
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,135 @@
|
|
|
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"], "rdma": [null, "rdma_en2", "rdma_en3"]},
|
|
52
|
+
{"ssh": "hostname2", "ips": ["123.123.123.2"], "rdma": ["rdma_en2", null, "rdma_en3"]},
|
|
53
|
+
...
|
|
54
|
+
{"ssh": "hostnameN", "ips": ["123.123.123.N"], "rdma": ["rdma_en2", "rdma_en3", null]},
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
hostfile (str): The path to the json file containing the host
|
|
60
|
+
information
|
|
61
|
+
"""
|
|
62
|
+
hostfile = Path(hostfile)
|
|
63
|
+
if not hostfile.exists():
|
|
64
|
+
raise ValueError(f"Hostfile {str(hostfile)} doesn't exist")
|
|
65
|
+
|
|
66
|
+
try:
|
|
67
|
+
data = json.load(open(hostfile))
|
|
68
|
+
backend = ""
|
|
69
|
+
envs = []
|
|
70
|
+
hosts = []
|
|
71
|
+
if isinstance(data, dict):
|
|
72
|
+
backend = data["backend"]
|
|
73
|
+
envs = data["envs"]
|
|
74
|
+
hosts = data["hosts"]
|
|
75
|
+
elif isinstance(data, list):
|
|
76
|
+
hosts = data
|
|
77
|
+
|
|
78
|
+
hosts = [
|
|
79
|
+
Host(i, h["ssh"], h.get("ips", []), h.get("rdma", []))
|
|
80
|
+
for i, h in enumerate(hosts)
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
return cls(hosts, backend, envs)
|
|
84
|
+
|
|
85
|
+
except Exception as e:
|
|
86
|
+
raise ValueError(
|
|
87
|
+
f"Failed to parse hostfile {str(hostfile)} ({str(e)})"
|
|
88
|
+
) from e
|
|
89
|
+
|
|
90
|
+
@classmethod
|
|
91
|
+
def from_list(cls, hostlist, repeats=1):
|
|
92
|
+
hosts = []
|
|
93
|
+
for i, h in enumerate(hostlist.split(",")):
|
|
94
|
+
if h == "":
|
|
95
|
+
raise ValueError("Hostname cannot be empty")
|
|
96
|
+
try:
|
|
97
|
+
ipaddress.ip_address(h)
|
|
98
|
+
ips = [h]
|
|
99
|
+
except ValueError:
|
|
100
|
+
ips = []
|
|
101
|
+
for i in range(repeats):
|
|
102
|
+
hosts.append(Host(i, h, ips, []))
|
|
103
|
+
return cls(hosts)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
class OptionalBoolAction(argparse.Action):
|
|
107
|
+
def __call__(self, parser, namespace, values, option_string=None):
|
|
108
|
+
if option_string.startswith("--no-"):
|
|
109
|
+
setattr(namespace, self.dest, False)
|
|
110
|
+
else:
|
|
111
|
+
setattr(namespace, self.dest, True)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def positive_number(x):
|
|
115
|
+
x = int(x)
|
|
116
|
+
if x <= 0:
|
|
117
|
+
raise ValueError("Number should be positive")
|
|
118
|
+
return x
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def log(verbose, *args, **kwargs):
|
|
122
|
+
if not verbose:
|
|
123
|
+
return
|
|
124
|
+
kwargs["file"] = sys.stderr
|
|
125
|
+
print("\033[32m[INFO]", *args, "\033[0m", **kwargs)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def log_warning(*args, **kwargs):
|
|
129
|
+
kwargs["file"] = sys.stderr
|
|
130
|
+
print("\033[33m[WARN]", *args, "\033[0m", **kwargs)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def log_error(*args, **kwargs):
|
|
134
|
+
kwargs["file"] = sys.stderr
|
|
135
|
+
print("\033[31m[ERROR]", *args, "\033[0m", **kwargs)
|