Skip to content

Commit 21e99bc

Browse files
suofacebook-github-bot
authored andcommitted
expose specific-rank selection (#506)
Summary: Pull Request resolved: #506 only exposed via the low-level `send` API, not a first-class adverb on the endpoints (since I don't know how to make a good API for it). Reviewed By: dulinriley Differential Revision: D78172884 fbshipit-source-id: bd4d8d18d99af6039ea19e0aa1a9750ea8c1eae0
1 parent 1005c51 commit 21e99bc

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

python/monarch/_src/actor/actor_mesh.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def set(debug_context: "DebugContext") -> None:
125125
_load_balancing_seed = random.Random(4)
126126

127127

128-
Selection = Literal["all", "choose"] # TODO: replace with real selection objects
128+
Selection = Literal["all", "choose"] | int # TODO: replace with real selection objects
129129

130130

131131
# standin class for whatever is the serializable python object we use
@@ -202,7 +202,6 @@ def cast(
202202
idx = _load_balancing_seed.randrange(len(self._shape))
203203
actor_rank = self._shape.ndslice[idx]
204204
self._mailbox.post(self._please_replace_me_actor_ids[actor_rank], message)
205-
return
206205
elif selection == "all":
207206
# replace me with actual remote actor mesh
208207
call_shape = Shape(
@@ -215,6 +214,16 @@ def cast(
215214
call_shape,
216215
message,
217216
)
217+
elif isinstance(selection, int):
218+
try:
219+
self._mailbox.post(
220+
self._please_replace_me_actor_ids[selection], message
221+
)
222+
except IndexError:
223+
raise IndexError(
224+
f"Tried to send to an out-of-range rank {selection}: "
225+
f"mesh has {len(self._please_replace_me_actor_ids)} elements."
226+
)
218227
else:
219228
raise ValueError(f"invalid selection: {selection}")
220229

python/monarch/actor/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
endpoint,
1919
MonarchContext,
2020
Point,
21+
port,
2122
send,
2223
ValueMesh,
2324
)
@@ -44,6 +45,7 @@
4445
"Point",
4546
"proc_mesh",
4647
"ProcMesh",
48+
"port",
4749
"send",
4850
"ValueMesh",
4951
"debug_client",

0 commit comments

Comments
 (0)