Skip to content

Commit 7aebbd9

Browse files
committed
[monarch] envvar to force v1 by default
Having monarch.actor selectively import from the same parts. This fixes the public API. Internal uses will probably need to call the add create_host_mesh_from_alloc which will give the right kind of host mesh based on environment variable. `MONARCH_HOST_MESH_V1_REMOVE_ME_BEFORE_RELEASE` is the name of the flag. Chosen because this needs to be gone before the public release. Differential Revision: [D84107651](https://our.internmc.facebook.com/intern/diff/D84107651/) **NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D84107651/)! ghstack-source-id: 314700169 Pull Request resolved: #1463
1 parent d959e28 commit 7aebbd9

File tree

4 files changed

+43
-21
lines changed

4 files changed

+43
-21
lines changed

python/monarch/_src/actor/v1/__init__.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,28 @@
55
# LICENSE file in the root directory of this source tree.
66

77
# pyre-unsafe
8+
import os
9+
10+
from monarch._rust_bindings.monarch_hyperactor.alloc import AllocConstraints
11+
from monarch._rust_bindings.monarch_hyperactor.shape import Shape, Slice
12+
13+
from monarch._src.actor.allocator import AllocateMixin
14+
15+
from monarch._src.actor.endpoint import Extent
16+
from monarch._src.actor.host_mesh import HostMesh as HostMeshV0
17+
from monarch._src.actor.v1.host_mesh import HostMesh as HostMeshV1
18+
19+
enabled = os.environ.get("MONARCH_HOST_MESH_V1_REMOVE_ME_BEFORE_RELEASE", "0") != "0"
20+
21+
22+
def host_mesh_from_alloc(
23+
name: str, extent: Extent, allocator: AllocateMixin, constraints: AllocConstraints
24+
) -> "HostMeshV0 | HostMeshV1":
25+
if enabled:
26+
return HostMeshV1.allocate_nonblocking(name, extent, allocator, constraints)
27+
else:
28+
return HostMeshV0(
29+
Shape(extent.labels, Slice.new_row_major(extent.sizes)),
30+
allocator,
31+
constraints,
32+
)

python/monarch/_src/job/job.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
# note: the jobs api is intended as a library so it should
1616
# only be importing _public_ monarch API functions.
17-
from monarch._src.actor.host_mesh import HostMesh, this_host
18-
from typing_extensions import Self
17+
from monarch.actor import HostMesh, this_host
1918

2019

2120
class JobState:

python/monarch/_src/job/meta.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
)
2020

2121
from monarch._rust_bindings.monarch_hyperactor.pytokio import PythonTask, Shared
22-
from monarch._rust_bindings.monarch_hyperactor.shape import Shape, Slice
22+
from monarch._rust_bindings.monarch_hyperactor.shape import Extent
2323
from monarch._src.actor.allocator import AllocateMixin
24-
from monarch._src.actor.host_mesh import HostMesh
2524
from monarch._src.actor.meta.allocator import (
2625
MastAllocator,
2726
MastAllocatorBase,
2827
MastAllocatorConfig,
2928
)
29+
from monarch._src.actor.v1 import host_mesh_from_alloc
3030

3131
from monarch._src.job.job import BatchJob, JobState, JobTrait
3232

@@ -173,10 +173,8 @@ def _state(self) -> JobState:
173173
job_started,
174174
)
175175
constraints = AllocConstraints({MastAllocator.ALLOC_LABEL_TASK_GROUP: name})
176-
host_meshes[name] = HostMesh(
177-
Shape(["hosts"], Slice.new_row_major([num_host])),
178-
allocator,
179-
constraints,
176+
host_meshes[name] = host_mesh_from_alloc(
177+
name, Extent(["hosts"], [num_host]), allocator, constraints
180178
)
181179

182180
return JobState(host_meshes)

python/monarch/actor/__init__.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
Monarch Actor API - Public interface for actor functionality.
1010
"""
1111

12+
from typing import TYPE_CHECKING
13+
1214
from monarch._rust_bindings.monarch_hyperactor.channel import ChannelTransport
1315
from monarch._rust_bindings.monarch_hyperactor.shape import Extent
1416
from monarch._src.actor.actor_mesh import (
@@ -34,19 +36,17 @@
3436
from monarch._src.actor.endpoint import endpoint
3537
from monarch._src.actor.future import Future
3638

37-
from monarch._src.actor.host_mesh import (
38-
HostMesh,
39-
hosts_from_config,
40-
this_host,
41-
this_proc,
42-
)
43-
from monarch._src.actor.proc_mesh import (
44-
get_or_spawn_controller,
45-
local_proc_mesh,
46-
proc_mesh,
47-
ProcMesh,
48-
sim_proc_mesh,
49-
)
39+
from monarch._src.actor.host_mesh import hosts_from_config
40+
from monarch._src.actor.proc_mesh import local_proc_mesh, proc_mesh, sim_proc_mesh
41+
42+
from monarch._src.actor.v1 import enabled as v1_enabled
43+
44+
if TYPE_CHECKING or not v1_enabled:
45+
from monarch._src.actor.host_mesh import HostMesh, this_host, this_proc
46+
from monarch._src.actor.proc_mesh import get_or_spawn_controller, ProcMesh
47+
else:
48+
from monarch._src.actor.v1.host_mesh import HostMesh, this_host, this_proc
49+
from monarch._src.actor.v1.proc_mesh import get_or_spawn_controller, ProcMesh
5050

5151
__all__ = [
5252
"Accumulator",

0 commit comments

Comments
 (0)