MPTransport#
- class torchrl.modules.inference_server.MPTransport(ctx: BaseContext | None = None, *, use_manager: bool = False)[source]#
Cross-process transport using
multiprocessingqueues.Response routing uses per-actor queues (one per
client()call) so that nomp.Queueobject is ever serialised through another queue. Clients must be created withclient()before spawning child processes.- Parameters:
ctx – a multiprocessing context (e.g.
mp.get_context("spawn")). Defaults tomp.get_context("spawn").use_manager (bool, optional) – if
True, back the request and response queues with a multiprocessing manager. This is useful when clients are forwarded through another spawned process. Defaults toFalse.
Example
>>> import multiprocessing as mp >>> transport = MPTransport() >>> client = transport.client() # creates response queue >>> p = mp.Process(target=actor_fn, args=(client,)) >>> p.start() # queue inherited
- client() MailboxClient[source]#
Create an actor-side client with a dedicated response queue.
Must be called in the parent process before spawning children. In particular, a manager-backed transport (
use_manager=True) loses its manager handle when pickled, so calling this on an unpickled copy raises aRuntimeError.- Returns:
A
_QueueInferenceClientthat can be passed to a child process as an argument tomultiprocessing.Process.
- close() None[source]#
Release transport resources.
Shuts down the multiprocessing manager backing the request/response queues when the transport was built with
use_manager=True(a no-op otherwise). The process that owns the transport must call this once the server and all clients are done with it:ProcessInferenceServerdoes not close the transport onshutdown().