Skip to content

Commit 771a3d0

Browse files
James Sunfacebook-github-bot
authored andcommitted
lazy init log client (#525)
Summary: Pull Request resolved: #525 like all other actors (_rdma_manager, _debug_manager, _rsync_mesh_client, etc in the ProcMesh object, let's also make the log client optioanl during init. Otherwise, it will init multiple times as ProcMesh is only a reference. Only init the client once we need it.) Reviewed By: dcci Differential Revision: D78229069 fbshipit-source-id: 7ba10d0a4bc0cfbe2de03c7a2cd972b8cf7d2db1
1 parent 442a810 commit 771a3d0

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

monarch_extension/src/logging.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ use pyo3::types::PyModule;
2828
module = "monarch._rust_bindings.monarch_extension.logging"
2929
)]
3030
pub struct LoggingMeshClient {
31-
// TODO: add more interfaces so that users can opt in/out streaming anytime they want
3231
actor_mesh: SharedCell<RootActorMesh<'static, LogForwardActor>>,
3332
}
3433

@@ -41,10 +40,10 @@ impl LoggingMeshClient {
4140
signal_safe_block_on(py, async move {
4241
let client_actor: ActorRef<LogClientActor> = proc_mesh
4342
.client_proc()
44-
.spawn("logging_client", ())
43+
.spawn("log_client", ())
4544
.await?
4645
.bind();
47-
let actor_mesh = proc_mesh.spawn("logging_source", &client_actor).await?;
46+
let actor_mesh = proc_mesh.spawn("log_forwarder", &client_actor).await?;
4847
Ok(Self { actor_mesh })
4948
})?
5049
}

python/monarch/_src/actor/proc_mesh.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ def __init__(
100100
self._mailbox: Mailbox = self._proc_mesh.client
101101
self._rsync_mesh_client: Optional[RsyncMeshClient] = None
102102
self._auto_reload_actor: Optional[AutoReloadActor] = None
103-
self._logging_mesh_client: LoggingMeshClient = LoggingMeshClient.spawn_blocking(
104-
proc_mesh=self._proc_mesh,
105-
)
103+
self._logging_mesh_client: Optional[LoggingMeshClient] = None
106104
self._maybe_device_mesh: Optional["DeviceMesh"] = _device_mesh
107105
self._stopped = False
108106
if _mock_shape is None and HAS_TENSOR_ENGINE:
@@ -281,6 +279,10 @@ def logging_option(self, stream_to_client: bool = False) -> None:
281279
Returns:
282280
None
283281
"""
282+
if self._logging_mesh_client is None:
283+
self._logging_mesh_client = LoggingMeshClient.spawn_blocking(
284+
proc_mesh=self._proc_mesh,
285+
)
284286
self._logging_mesh_client.set_mode(stream_to_client)
285287

286288
async def stop(self) -> None:

0 commit comments

Comments
 (0)