Skip to content

Commit cc1674f

Browse files
committed
[monarch] monarch.actor submodule
This is the proposed `monarch.actor` submodule. The public API is just a flat namespace, determined by `monarch/actor/__init__.py`. *Everything else* is a private detail, signified by lots of underscores in filenames. That's a little unforunate, but I think draws some good boundaries, and keeps the API simple to the user. Some principles that should guide us moving forward: - **Every symbol has at most two locations**: a private location (which should be exactly the same as its location in the source tree), and optionally a public location in the user-facing API. - We discourage end-users from depending on private locations via underscores, per python convention. Differential Revision: [D77709116](https://our.internmc.facebook.com/intern/diff/D77709116/) ghstack-source-id: 294458318 Pull Request resolved: #437
1 parent baec2f4 commit cc1674f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1372
-1248
lines changed

monarch_extension/src/mesh_controller.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ impl History {
507507
.getattr("RemoteException")
508508
.unwrap();
509509
let pickle = py
510-
.import("monarch.actor_mesh")
510+
.import("monarch.actor._actor_mesh")
511511
.unwrap()
512512
.getattr("_pickle")
513513
.unwrap();

monarch_tensor_worker/src/stream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ impl StreamActor {
990990
})
991991
.and_then(|result| -> Result<PythonMessage, WorkerError> {
992992
let pickle = py
993-
.import("monarch.actor_mesh")
993+
.import("monarch.actor._actor_mesh")
994994
.unwrap()
995995
.getattr("_pickle")
996996
.unwrap();

python/monarch/__init__.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929

3030
if TYPE_CHECKING:
3131
from monarch import timer
32-
from monarch.allocator import LocalAllocator, ProcessAllocator
32+
from monarch.actor._allocator import LocalAllocator, ProcessAllocator
33+
from monarch.actor._shape import NDSlice, Shape
3334
from monarch.common._coalescing import coalescing
3435

3536
from monarch.common.device_mesh import (
@@ -50,11 +51,9 @@
5051
from monarch.common.pipe import create_pipe, Pipe, remote_generator
5152
from monarch.common.remote import remote
5253
from monarch.common.selection import Selection
53-
from monarch.common.shape import NDSlice, Shape
5454
from monarch.common.stream import get_active_stream, Stream
5555
from monarch.common.tensor import reduce, reduce_, Tensor
5656
from monarch.fetch import fetch_shard, inspect, show
57-
from monarch.future import ActorFuture
5857
from monarch.gradient_generator import grad_function, grad_generator
5958
from monarch.notebook import mast_mesh, reserve_torchx as mast_reserve
6059
from monarch.python_local_mesh import python_local_mesh
@@ -79,8 +78,8 @@
7978
"function_resolvers": ("monarch.common.function", "resolvers"),
8079
"Future": ("monarch.common.future", "Future"),
8180
"RemoteException": ("monarch.common.invocation", "RemoteException"),
82-
"Shape": ("monarch.common.shape", "Shape"),
83-
"NDSlice": ("monarch.common.shape", "NDSlice"),
81+
"Shape": ("monarch.actor._shape", "Shape"),
82+
"NDSlice": ("monarch.actor._shape", "NDSlice"),
8483
"Selection": ("monarch.common.selection", "Selection"),
8584
"OpaqueRef": ("monarch.common.opaque_ref", "OpaqueRef"),
8685
"create_pipe": ("monarch.common.pipe", "create_pipe"),
@@ -112,9 +111,8 @@
112111
"Simulator": ("monarch.simulator.interface", "Simulator"),
113112
"world_mesh": ("monarch.world_mesh", "world_mesh"),
114113
"timer": ("monarch.timer", "timer"),
115-
"ProcessAllocator": ("monarch.allocator", "ProcessAllocator"),
116-
"LocalAllocator": ("monarch.allocator", "LocalAllocator"),
117-
"ActorFuture": ("monarch.future", "ActorFuture"),
114+
"ProcessAllocator": ("monarch.actor._allocator", "ProcessAllocator"),
115+
"LocalAllocator": ("monarch.actor._allocator", "LocalAllocator"),
118116
"builtins": ("monarch.builtins", "builtins"),
119117
}
120118

@@ -183,7 +181,6 @@ def __getattr__(name):
183181
"timer",
184182
"ProcessAllocator",
185183
"LocalAllocator",
186-
"ActorFuture",
187184
"builtins",
188185
]
189186
assert sorted(__all__) == sorted(_public_api)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# True iff the rust extension was built with the tensor engine feature.
8+
def has_tensor_engine() -> bool: ...

python/monarch/_rust_bindings/monarch_hyperactor/alloc.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class RemoteAllocatorBase:
7373
def __new__(
7474
cls,
7575
world_id: str,
76-
initializer: "monarch.allocator.RemoteAllocInitializer", # pyre-ignore[11] defined in monarch/python/monarch/allocator.py
76+
initializer: "monarch.actor._allocator.RemoteAllocInitializer", # pyre-ignore[11]
7777
heartbeat_interval: timedelta = timedelta(seconds=5),
7878
) -> Self:
7979
"""

python/monarch/_testing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
from typing import Any, Callable, Dict, Generator, Literal, Optional
1414

1515
import monarch_supervisor
16+
from monarch.actor._shape import NDSlice
1617
from monarch.common.client import Client
1718
from monarch.common.device_mesh import DeviceMesh
1819
from monarch.common.invocation import DeviceException, RemoteException
19-
from monarch.common.shape import NDSlice
2020
from monarch.controller.backend import ProcessBackend
2121
from monarch.mesh_controller import spawn_tensor_engine
2222
from monarch.proc_mesh import proc_mesh, ProcMesh

python/monarch/actor/__init__.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
"""
8+
Monarch Actor API
9+
"""
10+
11+
from monarch.actor._actor_mesh import (
12+
Accumulator,
13+
Actor,
14+
ActorError,
15+
current_actor_name,
16+
current_rank,
17+
current_size,
18+
endpoint,
19+
MonarchContext,
20+
ValueMesh,
21+
)
22+
from monarch.actor._future import Future
23+
from monarch.actor._proc_mesh import proc_mesh, ProcMesh
24+
25+
__all__ = [
26+
"Accumulator",
27+
"Actor",
28+
"ActorError",
29+
"current_actor_name",
30+
"current_rank",
31+
"current_size",
32+
"endpoint",
33+
"MonarchContext",
34+
"ValueMesh",
35+
"proc_mesh",
36+
"ProcMesh",
37+
"Future",
38+
]

0 commit comments

Comments
 (0)