Skip to content

Commit 4086bc5

Browse files
committed
[monarch/ext] fold monarch_hyperactor into actor_extension
Now we have achieved a good end-state for the actor native layer. - One rust extension (`actor_extension`) for defining bindings from actor stuff -> Python. - Exposed names in the extension directly map to the names in the `actor_extension` module hierarchy. Differential Revision: [D77949213](https://our.internmc.facebook.com/intern/diff/D77949213/) ghstack-source-id: 294914658 Pull Request resolved: #465
1 parent cac4f94 commit 4086bc5

Some content is hidden

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

82 files changed

+207
-373
lines changed

actor_extension/Cargo.toml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# @generated by autocargo from //monarch/actor_extension:actor_extension-lib
1+
# @generated by autocargo from //monarch/actor_extension:[actor_extension-lib,process_allocator-oss]
22

33
[package]
4-
name = "_extension"
4+
name = "actor_extension_lib"
55
version = "0.0.0"
66
authors = ["Meta"]
77
edition = "2021"
@@ -14,14 +14,23 @@ crate-type = ["cdylib"]
1414

1515
[dependencies]
1616
anyhow = "1.0.98"
17+
async-trait = "0.1.86"
1718
bincode = "1.3.3"
19+
clap = { version = "4.5.38", features = ["derive", "env", "string", "unicode", "wrap_help"] }
20+
erased-serde = "0.3.27"
21+
fbinit = { version = "0.2.0", git = "https://github.com/facebookexperimental/rust-shed.git", branch = "main" }
1822
hyperactor = { version = "0.0.0", path = "../hyperactor" }
1923
hyperactor_mesh = { version = "0.0.0", path = "../hyperactor_mesh" }
24+
hyperactor_multiprocess = { version = "0.0.0", path = "../hyperactor_multiprocess" }
2025
hyperactor_telemetry = { version = "0.0.0", path = "../hyperactor_telemetry" }
26+
inventory = "0.3.8"
2127
libc = "0.2.139"
22-
monarch_hyperactor = { version = "0.0.0", path = "../monarch_hyperactor" }
28+
monarch_types = { version = "0.0.0", path = "../monarch_types" }
29+
ndslice = { version = "0.0.0", path = "../ndslice" }
2330
pyo3 = { version = "0.24", features = ["anyhow", "multiple-pymethods"] }
2431
pyo3-async-runtimes = { version = "0.24", features = ["attributes", "tokio-runtime"] }
2532
serde = { version = "1.0.185", features = ["derive", "rc"] }
33+
serde_bytes = "0.11"
34+
thiserror = "2.0.12"
2635
tokio = { version = "1.45.0", features = ["full", "test-util", "tracing"] }
2736
tracing = { version = "0.1.41", features = ["attributes", "valuable"] }

monarch_hyperactor/src/actor.rs renamed to actor_extension/src/actor.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ use crate::proc::PySerialized;
5252
use crate::runtime::signal_safe_block_on;
5353
use crate::shape::PyShape;
5454

55-
#[pyclass(
56-
frozen,
57-
module = "monarch._src.actor._extension.monarch_hyperactor.actor"
58-
)]
55+
#[pyclass(frozen, module = "monarch._src.actor._extension.actor")]
5956
#[derive(Serialize, Deserialize, Named)]
6057
pub struct PickledMessage {
6158
sender_actor_id: ActorId,
@@ -99,7 +96,7 @@ impl PickledMessage {
9996
}
10097
}
10198

102-
#[pyclass(module = "monarch._src.actor._extension.monarch_hyperactor.actor")]
99+
#[pyclass(module = "monarch._src.actor._extension.actor")]
103100
pub struct PickledMessageClientActor {
104101
instance: Arc<Mutex<InstanceWrapper<PickledMessage>>>,
105102
}
@@ -174,10 +171,7 @@ impl PickledMessageClientActor {
174171
}
175172
}
176173

177-
#[pyclass(
178-
frozen,
179-
module = "monarch._src.actor._extension.monarch_hyperactor.actor"
180-
)]
174+
#[pyclass(frozen, module = "monarch._src.actor._extension.actor")]
181175
#[derive(Default, Clone, Serialize, Deserialize, Named, PartialEq)]
182176
pub struct PythonMessage {
183177
pub(crate) method: String,
@@ -266,7 +260,7 @@ impl PythonMessage {
266260
}
267261
}
268262

269-
#[pyclass(module = "monarch._src.actor._extension.monarch_hyperactor.actor")]
263+
#[pyclass(module = "monarch._src.actor._extension.actor")]
270264
pub(super) struct PythonActorHandle {
271265
pub(super) inner: ActorHandle<PythonActor>,
272266
}
@@ -391,7 +385,7 @@ fn create_task_locals() -> pyo3_async_runtimes::TaskLocals {
391385
// in Python, can catch the PanicException and notify the Rust awaiter manually.
392386
// In this way we can guarantee that the awaiter will complete even if the
393387
// `PyTaskCompleter` callback explodes.
394-
#[pyclass(module = "monarch._src.actor._extension.monarch_hyperactor.actor")]
388+
#[pyclass(module = "monarch._src.actor._extension.actor")]
395389
struct PanicFlag {
396390
sender: Option<tokio::sync::oneshot::Sender<PyObject>>,
397391
}

monarch_hyperactor/src/actor_mesh.rs renamed to actor_extension/src/actor_mesh.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::shape::PyShape;
2626

2727
#[pyclass(
2828
name = "PythonActorMesh",
29-
module = "monarch._src.actor._extension.monarch_hyperactor.actor_mesh"
29+
module = "monarch._src.actor._extension.actor_mesh"
3030
)]
3131
pub struct PythonActorMesh {
3232
pub(super) inner: SharedCell<RootActorMesh<'static, PythonActor>>,

monarch_hyperactor/src/alloc.rs renamed to actor_extension/src/alloc.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use crate::runtime::signal_safe_block_on;
4141

4242
#[pyclass(
4343
name = "LocalAllocatorBase",
44-
module = "monarch._src.actor._extension.monarch_hyperactor.alloc",
44+
module = "monarch._src.actor._extension.alloc",
4545
subclass
4646
)]
4747
pub struct PyLocalAllocator;
@@ -88,7 +88,7 @@ impl PyLocalAllocator {
8888

8989
#[pyclass(
9090
name = "ProcessAllocatorBase",
91-
module = "monarch._src.actor._extension.monarch_hyperactor.alloc",
91+
module = "monarch._src.actor._extension.alloc",
9292
subclass
9393
)]
9494
pub struct PyProcessAllocator {
@@ -156,7 +156,7 @@ impl PyProcessAllocator {
156156
/// Basically follows https://pyo3.rs/v0.25.0/trait-bounds.html.
157157
/// The Python subclass should implement `def initialize_alloc(self) -> list[str]`.
158158
pub struct PyRemoteProcessAllocInitializer {
159-
// instance of a Python subclass of `monarch._src.actor._extension.monarch_hyperactor.alloc.RemoteProcessAllocInitializer`.
159+
// instance of a Python subclass of `monarch._src.actor._extension.alloc.RemoteProcessAllocInitializer`.
160160
py_inner: Py<PyAny>,
161161

162162
// allocation constraints passed onto the allocator's allocate call and passed along to python initializer.
@@ -234,7 +234,7 @@ impl RemoteProcessAllocInitializer for PyRemoteProcessAllocInitializer {
234234

235235
#[pyclass(
236236
name = "RemoteAllocatorBase",
237-
module = "monarch._src.actor._extension.monarch_hyperactor.alloc",
237+
module = "monarch._src.actor._extension.alloc",
238238
subclass
239239
)]
240240
pub struct PyRemoteAllocator {
@@ -335,10 +335,7 @@ impl PyRemoteAllocator {
335335
/// A python class that wraps a Rust Alloc trait object. It represents what
336336
/// is shown on the python side. Internals are not exposed.
337337
/// It ensures that the Alloc is only used once (i.e. moved) in rust.
338-
#[pyclass(
339-
name = "Alloc",
340-
module = "monarch._src.actor._extension.monarch_hyperactor.alloc"
341-
)]
338+
#[pyclass(name = "Alloc", module = "monarch._src.actor._extension.alloc")]
342339
pub struct PyAlloc {
343340
pub inner: Arc<Mutex<Option<PyAllocWrapper>>>,
344341
}
@@ -399,7 +396,7 @@ impl Alloc for PyAllocWrapper {
399396

400397
#[pyclass(
401398
name = "AllocConstraints",
402-
module = "monarch._src.actor._extension.monarch_hyperactor.alloc"
399+
module = "monarch._src.actor._extension.alloc"
403400
)]
404401
pub struct PyAllocConstraints {
405402
inner: AllocConstraints,
@@ -419,10 +416,7 @@ impl PyAllocConstraints {
419416
}
420417
}
421418

422-
#[pyclass(
423-
name = "AllocSpec",
424-
module = "monarch._src.actor._extension.monarch_hyperactor.alloc"
425-
)]
419+
#[pyclass(name = "AllocSpec", module = "monarch._src.actor._extension.alloc")]
426420
pub struct PyAllocSpec {
427421
pub inner: AllocSpec,
428422
}

monarch_hyperactor/src/bootstrap.rs renamed to actor_extension/src/bootstrap.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ pub fn bootstrap_main(py: Python) -> PyResult<Bound<PyAny>> {
3838

3939
pub fn register_python_bindings(hyperactor_mod: &Bound<'_, PyModule>) -> PyResult<()> {
4040
let f = wrap_pyfunction!(bootstrap_main, hyperactor_mod)?;
41-
f.setattr(
42-
"__module__",
43-
"monarch._src.actor._extension.monarch_hyperactor.bootstrap",
44-
)?;
41+
f.setattr("__module__", "monarch._src.actor._extension.bootstrap")?;
4542
hyperactor_mod.add_function(f)?;
4643

4744
Ok(())

monarch_hyperactor/src/channel.rs renamed to actor_extension/src/channel.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use pyo3::prelude::*;
1616
/// Python binding for [`hyperactor::channel::ChannelTransport`]
1717
#[pyclass(
1818
name = "ChannelTransport",
19-
module = "monarch._src.actor._extension.monarch_hyperactor.channel",
19+
module = "monarch._src.actor._extension.channel",
2020
eq
2121
)]
2222
#[derive(PartialEq, Clone, Copy, Debug)]
@@ -28,10 +28,7 @@ pub enum PyChannelTransport {
2828
// Sim(/*proxy address:*/ ChannelAddr), TODO kiuk@ add support
2929
}
3030

31-
#[pyclass(
32-
name = "ChannelAddr",
33-
module = "monarch._src.actor._extension.monarch_hyperactor.channel"
34-
)]
31+
#[pyclass(name = "ChannelAddr", module = "monarch._src.actor._extension.channel")]
3532
pub struct PyChannelAddr {
3633
inner: ChannelAddr,
3734
}

actor_extension/src/code_sync.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ use hyperactor_mesh::code_sync::WorkspaceLocation;
1616
use hyperactor_mesh::code_sync::rsync;
1717
use hyperactor_mesh::shape::Shape;
1818
use hyperactor_mesh::shared_cell::SharedCell;
19-
use monarch_hyperactor::proc_mesh::PyProcMesh;
20-
use monarch_hyperactor::runtime::signal_safe_block_on;
21-
use monarch_hyperactor::shape::PyShape;
2219
use pyo3::Bound;
2320
use pyo3::exceptions::PyRuntimeError;
2421
use pyo3::exceptions::PyValueError;
@@ -28,6 +25,10 @@ use pyo3::types::PyModule;
2825
use serde::Deserialize;
2926
use serde::Serialize;
3027

28+
use crate::proc_mesh::PyProcMesh;
29+
use crate::runtime::signal_safe_block_on;
30+
use crate::shape::PyShape;
31+
3132
#[pyclass(
3233
frozen,
3334
name = "WorkspaceLocation",
File renamed without changes.

0 commit comments

Comments
 (0)