torchmonarch-nightly 2025.7.26__cp312-cp312-manylinux2014_x86_64.whl → 2025.7.27__cp312-cp312-manylinux2014_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.
monarch/_rust_bindings.so CHANGED
Binary file
@@ -29,8 +29,10 @@ from typing import (
29
29
  Iterable,
30
30
  Iterator,
31
31
  List,
32
+ Literal,
32
33
  NamedTuple,
33
34
  Optional,
35
+ overload,
34
36
  ParamSpec,
35
37
  Tuple,
36
38
  Type,
@@ -39,6 +41,7 @@ from typing import (
39
41
  )
40
42
 
41
43
  from monarch._rust_bindings.monarch_hyperactor.actor import (
44
+ MethodSpecifier,
42
45
  PanicFlag,
43
46
  PythonMessage,
44
47
  PythonMessageKind,
@@ -282,16 +285,18 @@ class ActorEndpoint(Endpoint[P, R]):
282
285
  def __init__(
283
286
  self,
284
287
  actor_mesh_ref: _ActorMeshRefImpl,
285
- name: str,
288
+ name: MethodSpecifier,
286
289
  impl: Callable[Concatenate[Any, P], Awaitable[R]],
287
290
  mailbox: Mailbox,
288
- propagator: Propagator = None,
291
+ propagator: Propagator,
292
+ explicit_response_port: bool,
289
293
  ) -> None:
290
294
  super().__init__(propagator)
291
295
  self._actor_mesh = actor_mesh_ref
292
296
  self._name = name
293
297
  self._signature: inspect.Signature = inspect.signature(impl)
294
298
  self._mailbox = mailbox
299
+ self._explicit_response_port = explicit_response_port
295
300
 
296
301
  def _supervise(self, r: HyPortReceiver | OncePortReceiver) -> Any:
297
302
  mesh = self._actor_mesh._actor_mesh
@@ -300,6 +305,12 @@ class ActorEndpoint(Endpoint[P, R]):
300
305
  def _call_name(self) -> Any:
301
306
  return self._name
302
307
 
308
+ def _check_arguments(self, args, kwargs):
309
+ if self._explicit_response_port:
310
+ self._signature.bind(None, None, *args, **kwargs)
311
+ else:
312
+ self._signature.bind(None, *args, **kwargs)
313
+
303
314
  def _send(
304
315
  self,
305
316
  args: Tuple[Any, ...],
@@ -312,7 +323,7 @@ class ActorEndpoint(Endpoint[P, R]):
312
323
 
313
324
  This sends the message to all actors but does not wait for any result.
314
325
  """
315
- self._signature.bind(None, *args, **kwargs)
326
+ self._check_arguments(args, kwargs)
316
327
  objects, bytes = flatten((args, kwargs), _is_ref_or_mailbox)
317
328
  if all(not hasattr(obj, "__monarch_ref__") for obj in objects):
318
329
  message = PythonMessage(
@@ -336,23 +347,50 @@ class ActorEndpoint(Endpoint[P, R]):
336
347
  return PortTuple(p, PortReceiver(self._mailbox, self._supervise(r._receiver)))
337
348
 
338
349
  def _rref(self, args, kwargs):
339
- self._signature.bind(None, *args, **kwargs)
350
+ self._check_arguments(args, kwargs)
340
351
  refs, bytes = flatten((args, kwargs), _is_ref_or_mailbox)
341
352
 
342
353
  return actor_rref(self, bytes, refs)
343
354
 
344
355
 
356
+ @overload
357
+ def as_endpoint(
358
+ not_an_endpoint: Callable[P, R],
359
+ *,
360
+ propagate: Propagator = None,
361
+ explicit_response_port: Literal[False] = False,
362
+ ) -> Endpoint[P, R]: ...
363
+
364
+
365
+ @overload
366
+ def as_endpoint(
367
+ not_an_endpoint: Callable[Concatenate["PortProtocol[R]", P], None],
368
+ *,
369
+ propagate: Propagator = None,
370
+ explicit_response_port: Literal[True],
371
+ ) -> Endpoint[P, R]: ...
372
+
373
+
345
374
  def as_endpoint(
346
- not_an_endpoint: Callable[P, R], *, propagate: Propagator = None
347
- ) -> Endpoint[P, R]:
375
+ not_an_endpoint: Any,
376
+ *,
377
+ propagate: Propagator = None,
378
+ explicit_response_port: bool = False,
379
+ ):
348
380
  if not isinstance(not_an_endpoint, NotAnEndpoint):
349
381
  raise ValueError("expected an method of a spawned actor")
382
+ kind = (
383
+ MethodSpecifier.ExplicitPort
384
+ if explicit_response_port
385
+ else MethodSpecifier.ReturnsResponse
386
+ )
350
387
  return ActorEndpoint(
351
388
  not_an_endpoint._ref._actor_mesh_ref,
352
- not_an_endpoint._name,
389
+ kind(not_an_endpoint._name),
353
390
  getattr(not_an_endpoint._ref, not_an_endpoint._name),
354
391
  not_an_endpoint._ref._mailbox,
355
392
  propagate,
393
+ explicit_response_port,
356
394
  )
357
395
 
358
396
 
@@ -598,7 +636,7 @@ class _Actor:
598
636
  mailbox: Mailbox,
599
637
  rank: int,
600
638
  shape: Shape,
601
- method: str,
639
+ method_spec: MethodSpecifier,
602
640
  message: bytes,
603
641
  panic_flag: PanicFlag,
604
642
  local_state: Iterable[Any],
@@ -616,17 +654,23 @@ class _Actor:
616
654
 
617
655
  args, kwargs = unflatten(message, local_state)
618
656
 
619
- if method == "__init__":
620
- Class, *args = args
621
- try:
622
- self.instance = Class(*args, **kwargs)
623
- except Exception as e:
624
- self._saved_error = ActorError(
625
- e, f"Remote actor {Class}.__init__ call failed."
626
- )
627
- raise e
628
- port.send(None)
629
- return None
657
+ match method_spec:
658
+ case MethodSpecifier.Init():
659
+ Class, *args = args
660
+ try:
661
+ self.instance = Class(*args, **kwargs)
662
+ except Exception as e:
663
+ self._saved_error = ActorError(
664
+ e, f"Remote actor {Class}.__init__ call failed."
665
+ )
666
+ raise e
667
+ port.send(None)
668
+ return None
669
+ case MethodSpecifier.ReturnsResponse(name=method):
670
+ pass
671
+ case MethodSpecifier.ExplicitPort(name=method):
672
+ args = (port, *args)
673
+ port = DroppingPort()
630
674
 
631
675
  if self.instance is None:
632
676
  # This could happen because of the following reasons. Both
@@ -775,15 +819,22 @@ class ActorMeshRef(MeshTrait):
775
819
  for attr_name in dir(self._class):
776
820
  attr_value = getattr(self._class, attr_name, None)
777
821
  if isinstance(attr_value, EndpointProperty):
822
+ # Convert string method name to appropriate MethodSpecifier
823
+ kind = (
824
+ MethodSpecifier.ExplicitPort
825
+ if attr_value._explicit_response_port
826
+ else MethodSpecifier.ReturnsResponse
827
+ )
778
828
  setattr(
779
829
  self,
780
830
  attr_name,
781
831
  ActorEndpoint(
782
832
  self._actor_mesh_ref,
783
- attr_name,
833
+ kind(attr_name),
784
834
  attr_value._method,
785
835
  self._mailbox,
786
836
  attr_value._propagator,
837
+ attr_value._explicit_response_port,
787
838
  ),
788
839
  )
789
840
 
@@ -802,9 +853,11 @@ class ActorMeshRef(MeshTrait):
802
853
 
803
854
  ep = ActorEndpoint(
804
855
  self._actor_mesh_ref,
805
- "__init__",
856
+ MethodSpecifier.Init(),
806
857
  null_func,
807
858
  self._mailbox,
859
+ None,
860
+ False,
808
861
  )
809
862
  send(ep, (self._class, *args), kwargs)
810
863
 
@@ -223,16 +223,23 @@ class EndpointProperty(Generic[P, R]):
223
223
  self,
224
224
  method: Callable[Concatenate[Any, P], Awaitable[R]],
225
225
  propagator: Propagator,
226
+ explicit_response_port: bool,
226
227
  ) -> None: ...
227
228
 
228
229
  @overload
229
230
  def __init__(
230
- self, method: Callable[Concatenate[Any, P], R], propagator: Propagator
231
+ self,
232
+ method: Callable[Concatenate[Any, P], R],
233
+ propagator: Propagator,
234
+ explicit_response_port: bool,
231
235
  ) -> None: ...
232
236
 
233
- def __init__(self, method: Any, propagator: Propagator) -> None:
237
+ def __init__(
238
+ self, method: Any, propagator: Propagator, explicit_response_port: bool
239
+ ) -> None:
234
240
  self._method = method
235
241
  self._propagator = propagator
242
+ self._explicit_response_port = explicit_response_port
236
243
 
237
244
  def __get__(self, instance, owner) -> Endpoint[P, R]:
238
245
  # this is a total lie, but we have to actually
@@ -274,11 +281,28 @@ class EndpointIfy:
274
281
  pass
275
282
 
276
283
 
284
+ class PortedEndpointIfy:
285
+ @overload
286
+ def __call__(
287
+ self,
288
+ function: Callable[Concatenate[Any, "Port[R]", P], Awaitable[None]],
289
+ ) -> Endpoint[P, R]: ...
290
+
291
+ @overload
292
+ def __call__(
293
+ self, function: Callable[Concatenate[Any, "Port[R]", P], None]
294
+ ) -> Endpoint[P, R]: ...
295
+
296
+ def __call__(self, function: Any):
297
+ pass
298
+
299
+
277
300
  @overload
278
301
  def endpoint(
279
302
  method: Callable[Concatenate[Any, P], Awaitable[R]],
280
303
  *,
281
304
  propagate: Propagator = None,
305
+ explicit_response_port: Literal[False] = False,
282
306
  ) -> EndpointProperty[P, R]: ...
283
307
 
284
308
 
@@ -287,6 +311,7 @@ def endpoint(
287
311
  method: Callable[Concatenate[Any, P], R],
288
312
  *,
289
313
  propagate: Propagator = None,
314
+ explicit_response_port: Literal[False] = False,
290
315
  ) -> EndpointProperty[P, R]: ...
291
316
 
292
317
 
@@ -294,10 +319,43 @@ def endpoint(
294
319
  def endpoint(
295
320
  *,
296
321
  propagate: Propagator = None,
322
+ explicit_response_port: Literal[False] = False,
297
323
  ) -> EndpointIfy: ...
298
324
 
299
325
 
300
- def endpoint(method=None, *, propagate=None):
326
+ @overload
327
+ def endpoint(
328
+ method: Callable[Concatenate[Any, "Port[R]", P], Awaitable[None]],
329
+ *,
330
+ propagate: Propagator = None,
331
+ explicit_response_port: Literal[True],
332
+ ) -> EndpointProperty[P, R]: ...
333
+
334
+
335
+ @overload
336
+ def endpoint(
337
+ method: Callable[Concatenate[Any, "Port[R]", P], None],
338
+ *,
339
+ propagate: Propagator = None,
340
+ explicit_response_port: Literal[True],
341
+ ) -> EndpointProperty[P, R]: ...
342
+
343
+
344
+ @overload
345
+ def endpoint(
346
+ *,
347
+ propagate: Propagator = None,
348
+ explicit_response_port: Literal[True],
349
+ ) -> PortedEndpointIfy: ...
350
+
351
+
352
+ def endpoint(method=None, *, propagate=None, explicit_response_port: bool = False):
301
353
  if method is None:
302
- return functools.partial(endpoint, propagate=propagate)
303
- return EndpointProperty(method, propagator=propagate)
354
+ return functools.partial(
355
+ endpoint,
356
+ propagate=propagate,
357
+ explicit_response_port=explicit_response_port,
358
+ )
359
+ return EndpointProperty(
360
+ method, propagator=propagate, explicit_response_port=explicit_response_port
361
+ )
Binary file
Binary file
@@ -586,3 +586,15 @@ class TestActorMeshStop(unittest.IsolatedAsyncioTestCase):
586
586
 
587
587
  await am_2.print.call("hello 3")
588
588
  await am_2.log.call("hello 4")
589
+
590
+
591
+ class PortedActor(Actor):
592
+ @endpoint(explicit_response_port=True)
593
+ def add(self, port: "Port[int]", b: int) -> None:
594
+ port.send(3 + b)
595
+
596
+
597
+ def test_ported_actor():
598
+ proc_mesh = local_proc_mesh(gpus=1).get()
599
+ a = proc_mesh.spawn("port_actor", PortedActor).get()
600
+ assert 5 == a.add.call_one(2).get()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: torchmonarch-nightly
3
- Version: 2025.7.26
3
+ Version: 2025.7.27
4
4
  Summary: Monarch: Single controller library
5
5
  Author: Meta
6
6
  Author-email: oncall+monarch@xmail.facebook.com
@@ -1,5 +1,5 @@
1
1
  monarch/__init__.py,sha256=mgKiyD1kxky-1pvhMlNfF4VmxWnhi-FSYZNFzkW1BEM,7052
2
- monarch/_rust_bindings.so,sha256=g6Qn8KSeX9x-QBtLRLDqPXjDIqsdVXDdNSAMhG-Ftos,47707960
2
+ monarch/_rust_bindings.so,sha256=filbdFHFT-QNjj9LGmVtVozr3_xlfFRF8Ryd9ldnccQ,47743632
3
3
  monarch/_testing.py,sha256=_3MYNMq-_0T1qXCj2vxrW13GlWGdUuVFMskQF2Gsw_o,7877
4
4
  monarch/actor_mesh.py,sha256=VtPU9syi_vUdwDSJJ639Z4Y_EcWZUScyoj0lQ88RQPs,421
5
5
  monarch/bootstrap_main.py,sha256=39OZpNMrfvvNJf-iwuNzgslzYA_ItaRPHfXGn_V74N0,524
@@ -8,7 +8,7 @@ monarch/fetch.py,sha256=JMxC8HdWMvpik0T4E6e-gfxvmNnOkA0ul4eo4R3Jg_o,1712
8
8
  monarch/gradient_generator.py,sha256=Rl3dmXGceTdCc1mYBg2JciR88ywGPnW7TVkL86KwqEA,6366
9
9
  monarch/memory.py,sha256=ol86dBhFAJqg78iF25-BuK0wuwj1onR8FIioZ_B0gjw,1377
10
10
  monarch/mesh_controller.py,sha256=mOk2misobJun2AgR_ALjFoopAEcOPYQVrrAJXa18ZTs,13810
11
- monarch/monarch_controller,sha256=qT8YsQcQzd28wlNXtzKvitavskPXoPQmifgopbo8Zjw,21250240
11
+ monarch/monarch_controller,sha256=PZ3QDkhSKGdjaqr95NUedfVbA8Nvcq79037TekR9uOM,21262872
12
12
  monarch/notebook.py,sha256=zu9MKDFKf1-rCM2TqFSRJjMBeiWuKcJSyUFLvoZRQzs,25949
13
13
  monarch/opaque_module.py,sha256=jCcg0DjbcEVXA9WNG0NhUzGteLHOJLTZEBvrIYJIAns,10436
14
14
  monarch/opaque_object.py,sha256=x1LoX6RIMGh4ux52xIfhPgoh6PhZHdkf9bMccHW3DW0,2808
@@ -25,12 +25,12 @@ monarch/tensorboard.py,sha256=MnLgH5lbqeUJauEuirEgR6L_qYl2NGdtwZOWIAuOZao,2587
25
25
  monarch/world_mesh.py,sha256=ob5dJWaC49Uw0xqClHBm8CQLvL4xKnjd4TGzk7k8NxI,980
26
26
  monarch/_src/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
27
  monarch/_src/actor/__init__.py,sha256=4iK3nzQZmEPe0HGNY70fABBenw3lCVVaaF0xddF5Fa0,235
28
- monarch/_src/actor/actor_mesh.py,sha256=guYD9nZHguLGJAvTisc3Q664ASkupcNC6z9iheeGFUQ,29188
28
+ monarch/_src/actor/actor_mesh.py,sha256=wmFUf3NJcHmJeK7WrLkGOrzmAvdHmjLUaeQ5W6WDLk0,30867
29
29
  monarch/_src/actor/allocator.py,sha256=WpHEK1SvjgF3GdIWIYUkonXli2-gQVKJVZPInl2RFQo,8212
30
30
  monarch/_src/actor/bootstrap_main.py,sha256=e5eU3GvX60MWWmCty7VcZrAmukD29iJdWBysNgQ2o3A,2342
31
31
  monarch/_src/actor/debugger.py,sha256=t2iAAxz03b2KZ89T3VjRc__7GzSf83R8gM81SDyX3-o,19532
32
32
  monarch/_src/actor/device_utils.py,sha256=gBpl23wMjppVAEzzj8U9HyX-B7Bs2_3ftiMAkzUS4j4,577
33
- monarch/_src/actor/endpoint.py,sha256=jM3XYWze6gB6ajE4AMojNFSN4IaaxgioNAErJkkywjE,9721
33
+ monarch/_src/actor/endpoint.py,sha256=HCOGXe8dhvkqfeIaEF_PO1ZqJzk1wOUlTf8ogjklY84,11189
34
34
  monarch/_src/actor/event_loop.py,sha256=2i4fKIkemBzua_t47BqVa2roZ6fWB6sbmMFPNx2zKN0,2832
35
35
  monarch/_src/actor/future.py,sha256=jOGh1wfwKyGJxhl9t1P8eapXYywf8KwQldZCCbupmb8,4042
36
36
  monarch/_src/actor/pdb_wrapper.py,sha256=-QxRktntdEO2LdHixBGKLboYtADyh8bEIAoa3gFwIEo,4161
@@ -89,7 +89,7 @@ monarch/controller/rust_backend/__init__.py,sha256=J8qjUOysmcMAek2KFN13mViOXZxTY
89
89
  monarch/controller/rust_backend/controller.py,sha256=8IYnVUiqEVKO9rGL3vKqcCSAhWJG1bYYQ0MoaMqsp78,9521
90
90
  monarch/gradient/__init__.py,sha256=kqmzwt16mMpk0M3GhpgP_f7da4DGnaV9chDzbt66k4Q,308
91
91
  monarch/gradient/_gradient_generator.pyi,sha256=6cX0UxaDt9NAlwgIhTgnweqGOf6qRhHiGnUzSWNCxdU,630
92
- monarch/gradient/_gradient_generator.so,sha256=oUxX5Ww47ioFGvxKaE4IFgrCZGuK_-uGKMe0P6aAIKs,11535816
92
+ monarch/gradient/_gradient_generator.so,sha256=RNWeH_QnGgDTVl3O28nwuVliO_Q-Ot7yYygztbL0SDA,11535768
93
93
  monarch/parallel/__init__.py,sha256=6920kIkhiX7AiyjYvyc1ad8ccP-bStJJ1sS5KkeN2P0,352
94
94
  monarch/parallel/pipelining/__init__.py,sha256=J8qjUOysmcMAek2KFN13mViOXZxTYc5vCrF02t3VuFU,223
95
95
  monarch/parallel/pipelining/runtime.py,sha256=KK8TG1gUYEzSsquiZoPTWGSIC74mlncD7cYknKxfb3c,32470
@@ -157,7 +157,7 @@ tests/test_future.py,sha256=cXzaNi2YDwVyjR541ScXmgktX1YFsKzbl8wep0DMVbk,3032
157
157
  tests/test_grad_generator.py,sha256=p4Pm4kMEeGldt2jUVAkGKCB0mLccKI28pltH6OTGbQA,3412
158
158
  tests/test_mock_cuda.py,sha256=5hisElxeLJ5MHw3KM9gwxBiXiMaG-Rm382u3AsQcDOI,3068
159
159
  tests/test_pdb_actor.py,sha256=5KJhuhcZDPWMdjC6eAtDdwnz1W7jNFXvIrMSFaCWaPw,3858
160
- tests/test_python_actors.py,sha256=fts3dfdld-zkpRaKyxEAOW6JFnG_jQspu1WehenwyI0,15220
160
+ tests/test_python_actors.py,sha256=rkfMfMn8YPz58-HY4UUki2EL7a6XNZuAW-i8jBfd29o,15540
161
161
  tests/test_rdma.py,sha256=vgeCCsfOjRjlGoGR0SYRuTP_Sx5RlEUUKfO9ATK0d4E,6125
162
162
  tests/test_remote_functions.py,sha256=VT65W7htp1jCsP9-AsiO1dofhx-4OebWEOssDEgi3GM,51054
163
163
  tests/test_rust_backend.py,sha256=3TLu8dSVEqyLhjHED2DoAEQHTpbBQcr3WI6K2eGZLZw,7861
@@ -169,9 +169,9 @@ tests/simulator/test_profiling.py,sha256=TGYCfzTLdkpIwnOuO6KApprmrgPIRQe60KRX3wk
169
169
  tests/simulator/test_simulator.py,sha256=LO8lA0ssY-OGEBL5ipEu74f97Y765TEwfUOv-DtIptM,14568
170
170
  tests/simulator/test_task.py,sha256=ipqBDuDAysuo1xOB9S5psaFvwe6VATD43IovCTSs0t4,2327
171
171
  tests/simulator/test_worker.py,sha256=QrWWIJ3HDgDLkBPRc2mwYPlOQoXQcj1qRfc0WUfKkFY,3507
172
- torchmonarch_nightly-2025.7.26.dist-info/licenses/LICENSE,sha256=e0Eotbf_rHOYPuEUlppIbvwy4SN98CZnl_hqwvbDA4Q,1530
173
- torchmonarch_nightly-2025.7.26.dist-info/METADATA,sha256=rJuOVCi7kVf2R9tHhtMSlaWv80ybWS5g9MvMzmso5M8,3852
174
- torchmonarch_nightly-2025.7.26.dist-info/WHEEL,sha256=lduYNUEDASmtUEDemd8SmeX1qOMvvA6YKAbAo1Qbwk8,104
175
- torchmonarch_nightly-2025.7.26.dist-info/entry_points.txt,sha256=60QVSpYVzkzS4iDOiLp0fsLxVp47X3J2l3v7W-59LMo,117
176
- torchmonarch_nightly-2025.7.26.dist-info/top_level.txt,sha256=E-ZssZzyM17glpVrh-S9--qJ-w9p2EjuYOuNw9tQ4Eg,33
177
- torchmonarch_nightly-2025.7.26.dist-info/RECORD,,
172
+ torchmonarch_nightly-2025.7.27.dist-info/licenses/LICENSE,sha256=e0Eotbf_rHOYPuEUlppIbvwy4SN98CZnl_hqwvbDA4Q,1530
173
+ torchmonarch_nightly-2025.7.27.dist-info/METADATA,sha256=mrcnj35gY6Yc3IvNjpyGBTkogRkHOTlf2VTaSOxTDeE,3852
174
+ torchmonarch_nightly-2025.7.27.dist-info/WHEEL,sha256=lduYNUEDASmtUEDemd8SmeX1qOMvvA6YKAbAo1Qbwk8,104
175
+ torchmonarch_nightly-2025.7.27.dist-info/entry_points.txt,sha256=60QVSpYVzkzS4iDOiLp0fsLxVp47X3J2l3v7W-59LMo,117
176
+ torchmonarch_nightly-2025.7.27.dist-info/top_level.txt,sha256=E-ZssZzyM17glpVrh-S9--qJ-w9p2EjuYOuNw9tQ4Eg,33
177
+ torchmonarch_nightly-2025.7.27.dist-info/RECORD,,