xoscar 0.9.0__cp312-cp312-macosx_10_13_x86_64.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.
- xoscar/__init__.py +61 -0
- xoscar/_utils.cpython-312-darwin.so +0 -0
- xoscar/_utils.pxd +36 -0
- xoscar/_utils.pyx +246 -0
- xoscar/_version.py +693 -0
- xoscar/aio/__init__.py +16 -0
- xoscar/aio/base.py +86 -0
- xoscar/aio/file.py +59 -0
- xoscar/aio/lru.py +228 -0
- xoscar/aio/parallelism.py +39 -0
- xoscar/api.py +527 -0
- xoscar/backend.py +67 -0
- xoscar/backends/__init__.py +14 -0
- xoscar/backends/allocate_strategy.py +160 -0
- xoscar/backends/communication/__init__.py +30 -0
- xoscar/backends/communication/base.py +315 -0
- xoscar/backends/communication/core.py +69 -0
- xoscar/backends/communication/dummy.py +253 -0
- xoscar/backends/communication/errors.py +20 -0
- xoscar/backends/communication/socket.py +444 -0
- xoscar/backends/communication/ucx.py +538 -0
- xoscar/backends/communication/utils.py +97 -0
- xoscar/backends/config.py +157 -0
- xoscar/backends/context.py +437 -0
- xoscar/backends/core.py +352 -0
- xoscar/backends/indigen/__init__.py +16 -0
- xoscar/backends/indigen/__main__.py +19 -0
- xoscar/backends/indigen/backend.py +51 -0
- xoscar/backends/indigen/driver.py +26 -0
- xoscar/backends/indigen/fate_sharing.py +221 -0
- xoscar/backends/indigen/pool.py +515 -0
- xoscar/backends/indigen/shared_memory.py +548 -0
- xoscar/backends/message.cpython-312-darwin.so +0 -0
- xoscar/backends/message.pyi +255 -0
- xoscar/backends/message.pyx +646 -0
- xoscar/backends/pool.py +1630 -0
- xoscar/backends/router.py +285 -0
- xoscar/backends/test/__init__.py +16 -0
- xoscar/backends/test/backend.py +38 -0
- xoscar/backends/test/pool.py +233 -0
- xoscar/batch.py +256 -0
- xoscar/collective/__init__.py +27 -0
- xoscar/collective/backend/__init__.py +13 -0
- xoscar/collective/backend/nccl_backend.py +160 -0
- xoscar/collective/common.py +102 -0
- xoscar/collective/core.py +737 -0
- xoscar/collective/process_group.py +687 -0
- xoscar/collective/utils.py +41 -0
- xoscar/collective/xoscar_pygloo.cpython-312-darwin.so +0 -0
- xoscar/collective/xoscar_pygloo.pyi +239 -0
- xoscar/constants.py +23 -0
- xoscar/context.cpython-312-darwin.so +0 -0
- xoscar/context.pxd +21 -0
- xoscar/context.pyx +368 -0
- xoscar/core.cpython-312-darwin.so +0 -0
- xoscar/core.pxd +51 -0
- xoscar/core.pyx +664 -0
- xoscar/debug.py +188 -0
- xoscar/driver.py +42 -0
- xoscar/errors.py +63 -0
- xoscar/libcpp.pxd +31 -0
- xoscar/metrics/__init__.py +21 -0
- xoscar/metrics/api.py +288 -0
- xoscar/metrics/backends/__init__.py +13 -0
- xoscar/metrics/backends/console/__init__.py +13 -0
- xoscar/metrics/backends/console/console_metric.py +82 -0
- xoscar/metrics/backends/metric.py +149 -0
- xoscar/metrics/backends/prometheus/__init__.py +13 -0
- xoscar/metrics/backends/prometheus/prometheus_metric.py +70 -0
- xoscar/nvutils.py +717 -0
- xoscar/profiling.py +260 -0
- xoscar/serialization/__init__.py +20 -0
- xoscar/serialization/aio.py +141 -0
- xoscar/serialization/core.cpython-312-darwin.so +0 -0
- xoscar/serialization/core.pxd +28 -0
- xoscar/serialization/core.pyi +57 -0
- xoscar/serialization/core.pyx +944 -0
- xoscar/serialization/cuda.py +111 -0
- xoscar/serialization/exception.py +48 -0
- xoscar/serialization/mlx.py +67 -0
- xoscar/serialization/numpy.py +82 -0
- xoscar/serialization/pyfury.py +37 -0
- xoscar/serialization/scipy.py +72 -0
- xoscar/serialization/torch.py +180 -0
- xoscar/utils.py +522 -0
- xoscar/virtualenv/__init__.py +34 -0
- xoscar/virtualenv/core.py +268 -0
- xoscar/virtualenv/platform.py +56 -0
- xoscar/virtualenv/utils.py +100 -0
- xoscar/virtualenv/uv.py +321 -0
- xoscar-0.9.0.dist-info/METADATA +230 -0
- xoscar-0.9.0.dist-info/RECORD +94 -0
- xoscar-0.9.0.dist-info/WHEEL +6 -0
- xoscar-0.9.0.dist-info/top_level.txt +2 -0
xoscar/__init__.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# isort: skip_file
|
|
2
|
+
# Copyright 2022-2023 XProbe Inc.
|
|
3
|
+
# derived from copyright 1999-2021 Alibaba Group Holding Ltd.
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
|
|
17
|
+
from typing import TypeVar, Union
|
|
18
|
+
|
|
19
|
+
from . import debug
|
|
20
|
+
from .api import (
|
|
21
|
+
actor_ref,
|
|
22
|
+
create_actor,
|
|
23
|
+
has_actor,
|
|
24
|
+
destroy_actor,
|
|
25
|
+
kill_actor,
|
|
26
|
+
buffer_ref,
|
|
27
|
+
file_object_ref,
|
|
28
|
+
copy_to,
|
|
29
|
+
Actor,
|
|
30
|
+
StatelessActor,
|
|
31
|
+
create_actor_pool,
|
|
32
|
+
setup_cluster,
|
|
33
|
+
wait_actor_pool_recovered,
|
|
34
|
+
get_pool_config,
|
|
35
|
+
generator,
|
|
36
|
+
wait_for,
|
|
37
|
+
)
|
|
38
|
+
from .backends import allocate_strategy
|
|
39
|
+
from .backends.pool import MainActorPoolType
|
|
40
|
+
from .batch import extensible
|
|
41
|
+
from .core import ActorRef, no_lock
|
|
42
|
+
from .debug import set_debug_options, get_debug_options, DebugOptions
|
|
43
|
+
from .errors import (
|
|
44
|
+
ActorNotExist,
|
|
45
|
+
ActorAlreadyExist,
|
|
46
|
+
ServerClosed,
|
|
47
|
+
SendMessageFailed,
|
|
48
|
+
Return,
|
|
49
|
+
)
|
|
50
|
+
from ._utils import create_actor_ref
|
|
51
|
+
|
|
52
|
+
# make sure methods are registered
|
|
53
|
+
from .backends import indigen, test
|
|
54
|
+
from . import _version
|
|
55
|
+
|
|
56
|
+
del indigen, test
|
|
57
|
+
|
|
58
|
+
_T = TypeVar("_T")
|
|
59
|
+
ActorRefType = Union[ActorRef, _T]
|
|
60
|
+
|
|
61
|
+
__version__ = _version.get_versions()["version"]
|
|
Binary file
|
xoscar/_utils.pxd
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Copyright 2022-2023 XProbe Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
cdef class TypeDispatcher:
|
|
17
|
+
cdef dict _handlers
|
|
18
|
+
cdef dict _lazy_handlers
|
|
19
|
+
cdef dict _inherit_handlers
|
|
20
|
+
cdef object __weakref__
|
|
21
|
+
|
|
22
|
+
cpdef void register(self, object type_, object handler)
|
|
23
|
+
cpdef void unregister(self, object type_)
|
|
24
|
+
cdef _reload_lazy_handlers(self)
|
|
25
|
+
cpdef get_handler(self, object type_)
|
|
26
|
+
|
|
27
|
+
cpdef str to_str(s, encoding=*)
|
|
28
|
+
cpdef bytes to_binary(s, encoding=*)
|
|
29
|
+
cpdef bytes new_random_id(int byte_len)
|
|
30
|
+
cpdef bytes new_actor_id()
|
|
31
|
+
cdef bint is_async_generator(obj)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
cdef class Timer:
|
|
35
|
+
cdef object _start
|
|
36
|
+
cdef readonly object duration
|
xoscar/_utils.pyx
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# distutils: language = c++
|
|
2
|
+
# Copyright 2022-2023 XProbe Inc.
|
|
3
|
+
# derived from copyright 1999-2021 Alibaba Group Holding Ltd.
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
|
|
17
|
+
import collections
|
|
18
|
+
import importlib
|
|
19
|
+
import itertools
|
|
20
|
+
import time
|
|
21
|
+
import warnings
|
|
22
|
+
from functools import partial
|
|
23
|
+
from random import getrandbits
|
|
24
|
+
from typing import AsyncGenerator
|
|
25
|
+
from weakref import WeakSet
|
|
26
|
+
|
|
27
|
+
from libc.stdint cimport uint_fast64_t
|
|
28
|
+
from libc.stdlib cimport free, malloc
|
|
29
|
+
|
|
30
|
+
from .core cimport ActorRef, LocalActorRef
|
|
31
|
+
from .libcpp cimport mt19937_64
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
cdef mt19937_64 _rnd_gen
|
|
35
|
+
cdef bint _rnd_is_seed_set = False
|
|
36
|
+
NamedType = collections.namedtuple("NamedType", ["name", "type_"])
|
|
37
|
+
_type_dispatchers = WeakSet()
|
|
38
|
+
|
|
39
|
+
cdef class TypeDispatcher:
|
|
40
|
+
def __init__(self):
|
|
41
|
+
self._handlers = dict()
|
|
42
|
+
self._lazy_handlers = dict()
|
|
43
|
+
# store inherited handlers to facilitate unregistering
|
|
44
|
+
self._inherit_handlers = dict()
|
|
45
|
+
|
|
46
|
+
_type_dispatchers.add(self)
|
|
47
|
+
|
|
48
|
+
cpdef void register(self, object type_, object handler):
|
|
49
|
+
if isinstance(type_, str):
|
|
50
|
+
self._lazy_handlers[type_] = handler
|
|
51
|
+
elif type(type_) is not NamedType and isinstance(type_, tuple):
|
|
52
|
+
for t in type_:
|
|
53
|
+
self.register(t, handler)
|
|
54
|
+
else:
|
|
55
|
+
self._handlers[type_] = handler
|
|
56
|
+
|
|
57
|
+
cpdef void unregister(self, object type_):
|
|
58
|
+
if type(type_) is not NamedType and isinstance(type_, tuple):
|
|
59
|
+
for t in type_:
|
|
60
|
+
self.unregister(t)
|
|
61
|
+
else:
|
|
62
|
+
self._lazy_handlers.pop(type_, None)
|
|
63
|
+
self._handlers.pop(type_, None)
|
|
64
|
+
self._inherit_handlers.clear()
|
|
65
|
+
|
|
66
|
+
cdef _reload_lazy_handlers(self):
|
|
67
|
+
for k, v in self._lazy_handlers.items():
|
|
68
|
+
mod_name, obj_name = k.rsplit('.', 1)
|
|
69
|
+
with warnings.catch_warnings():
|
|
70
|
+
# the lazy imported cudf will warn no device found,
|
|
71
|
+
# when we set visible device to -1 for CPU processes,
|
|
72
|
+
# ignore the warning to not distract users
|
|
73
|
+
warnings.simplefilter("ignore")
|
|
74
|
+
mod = importlib.import_module(mod_name, __name__)
|
|
75
|
+
self.register(getattr(mod, obj_name), v)
|
|
76
|
+
self._lazy_handlers = dict()
|
|
77
|
+
|
|
78
|
+
cpdef get_handler(self, object type_):
|
|
79
|
+
try:
|
|
80
|
+
return self._handlers[type_]
|
|
81
|
+
except KeyError:
|
|
82
|
+
pass
|
|
83
|
+
|
|
84
|
+
try:
|
|
85
|
+
return self._inherit_handlers[type_]
|
|
86
|
+
except KeyError:
|
|
87
|
+
self._reload_lazy_handlers()
|
|
88
|
+
if type(type_) is NamedType:
|
|
89
|
+
named_type = partial(NamedType, type_.name)
|
|
90
|
+
mro = itertools.chain(
|
|
91
|
+
*zip(map(named_type, type_.type_.__mro__),
|
|
92
|
+
type_.type_.__mro__)
|
|
93
|
+
)
|
|
94
|
+
else:
|
|
95
|
+
mro = type_.__mro__
|
|
96
|
+
for clz in mro:
|
|
97
|
+
# only lookup self._handlers for mro clz
|
|
98
|
+
handler = self._handlers.get(clz)
|
|
99
|
+
if handler is not None:
|
|
100
|
+
self._inherit_handlers[type_] = handler
|
|
101
|
+
return handler
|
|
102
|
+
raise KeyError(f'Cannot dispatch type {type_}')
|
|
103
|
+
|
|
104
|
+
def __call__(self, object obj, *args, **kwargs):
|
|
105
|
+
return self.get_handler(type(obj))(obj, *args, **kwargs)
|
|
106
|
+
|
|
107
|
+
@staticmethod
|
|
108
|
+
def reload_all_lazy_handlers():
|
|
109
|
+
for dispatcher in _type_dispatchers:
|
|
110
|
+
(<TypeDispatcher>dispatcher)._reload_lazy_handlers()
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
cpdef str to_str(s, encoding='utf-8'):
|
|
114
|
+
if type(s) is str:
|
|
115
|
+
return <str>s
|
|
116
|
+
elif isinstance(s, bytes):
|
|
117
|
+
return (<bytes>s).decode(encoding)
|
|
118
|
+
elif isinstance(s, str):
|
|
119
|
+
return str(s)
|
|
120
|
+
elif s is None:
|
|
121
|
+
return s
|
|
122
|
+
else:
|
|
123
|
+
raise TypeError(f"Could not convert from {s} to str.")
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
cpdef bytes to_binary(s, encoding='utf-8'):
|
|
127
|
+
if type(s) is bytes:
|
|
128
|
+
return <bytes>s
|
|
129
|
+
elif isinstance(s, unicode):
|
|
130
|
+
return (<unicode>s).encode(encoding)
|
|
131
|
+
elif isinstance(s, bytes):
|
|
132
|
+
return bytes(s)
|
|
133
|
+
elif s is None:
|
|
134
|
+
return None
|
|
135
|
+
else:
|
|
136
|
+
raise TypeError(f"Could not convert from {s} to bytes.")
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
cpdef void reset_id_random_seed() except *:
|
|
140
|
+
cdef bytes seed_bytes
|
|
141
|
+
global _rnd_is_seed_set
|
|
142
|
+
|
|
143
|
+
seed_bytes = getrandbits(64).to_bytes(8, "little")
|
|
144
|
+
_rnd_gen.seed((<uint_fast64_t *><char *>seed_bytes)[0])
|
|
145
|
+
_rnd_is_seed_set = True
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
cpdef bytes new_random_id(int byte_len):
|
|
149
|
+
cdef uint_fast64_t *res_ptr
|
|
150
|
+
cdef uint_fast64_t res_data[4]
|
|
151
|
+
cdef int i, qw_num = byte_len >> 3
|
|
152
|
+
cdef bytes res
|
|
153
|
+
|
|
154
|
+
if not _rnd_is_seed_set:
|
|
155
|
+
reset_id_random_seed()
|
|
156
|
+
|
|
157
|
+
if (qw_num << 3) < byte_len:
|
|
158
|
+
qw_num += 1
|
|
159
|
+
|
|
160
|
+
if qw_num <= 4:
|
|
161
|
+
# use stack memory to accelerate
|
|
162
|
+
res_ptr = res_data
|
|
163
|
+
else:
|
|
164
|
+
res_ptr = <uint_fast64_t *>malloc(qw_num << 3)
|
|
165
|
+
|
|
166
|
+
try:
|
|
167
|
+
for i in range(qw_num):
|
|
168
|
+
res_ptr[i] = _rnd_gen()
|
|
169
|
+
return <bytes>((<char *>&(res_ptr[0]))[:byte_len])
|
|
170
|
+
finally:
|
|
171
|
+
# free memory if allocated by malloc
|
|
172
|
+
if res_ptr != res_data:
|
|
173
|
+
free(res_ptr)
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
cpdef bytes new_actor_id():
|
|
177
|
+
return new_random_id(32)
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
cdef set _is_async_generator_typecache = set()
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
cdef bint is_async_generator(obj):
|
|
184
|
+
cdef type tp = type(obj)
|
|
185
|
+
if tp in _is_async_generator_typecache:
|
|
186
|
+
return True
|
|
187
|
+
|
|
188
|
+
if isinstance(obj, AsyncGenerator):
|
|
189
|
+
if len(_is_async_generator_typecache) < 100:
|
|
190
|
+
_is_async_generator_typecache.add(tp)
|
|
191
|
+
return True
|
|
192
|
+
else:
|
|
193
|
+
return False
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def create_actor_ref(*args, **kwargs):
|
|
197
|
+
"""
|
|
198
|
+
Create an actor reference.
|
|
199
|
+
|
|
200
|
+
Returns
|
|
201
|
+
-------
|
|
202
|
+
ActorRef
|
|
203
|
+
"""
|
|
204
|
+
|
|
205
|
+
cdef str address
|
|
206
|
+
cdef object uid
|
|
207
|
+
cdef ActorRef existing_ref
|
|
208
|
+
|
|
209
|
+
address = to_str(kwargs.pop('address', None))
|
|
210
|
+
uid = kwargs.pop('uid', None)
|
|
211
|
+
proxy_addresses = kwargs.pop("proxy_addresses", None)
|
|
212
|
+
|
|
213
|
+
if kwargs:
|
|
214
|
+
raise ValueError('Only `address` or `uid` keywords are supported')
|
|
215
|
+
|
|
216
|
+
# args: [address, uid], or [address, uid, proxy_addresses]
|
|
217
|
+
if 2 <= len(args) <= 3 and isinstance(args[0], (str, bytes)):
|
|
218
|
+
if address:
|
|
219
|
+
raise ValueError('address has been specified')
|
|
220
|
+
address = to_str(args[0])
|
|
221
|
+
uid = args[1]
|
|
222
|
+
if len(args) == 3:
|
|
223
|
+
proxy_addresses = args[2]
|
|
224
|
+
elif len(args) == 1:
|
|
225
|
+
tp0 = type(args[0])
|
|
226
|
+
if tp0 is ActorRef or tp0 is LocalActorRef:
|
|
227
|
+
existing_ref = <ActorRef>(args[0])
|
|
228
|
+
uid = existing_ref.uid
|
|
229
|
+
address = to_str(address or existing_ref.address)
|
|
230
|
+
proxy_addresses = existing_ref.proxy_addresses
|
|
231
|
+
else:
|
|
232
|
+
uid = args[0]
|
|
233
|
+
|
|
234
|
+
if uid is None:
|
|
235
|
+
raise ValueError('Actor uid should be provided')
|
|
236
|
+
|
|
237
|
+
return ActorRef(address, uid, proxy_addresses=proxy_addresses)
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
cdef class Timer:
|
|
241
|
+
def __enter__(self):
|
|
242
|
+
self._start = time.time()
|
|
243
|
+
return self
|
|
244
|
+
|
|
245
|
+
def __exit__(self, *_):
|
|
246
|
+
self.duration = time.time() - self._start
|