TensorDictServer#
- class tensordict._ucxx.TensorDictServer(port: int, *, consolidated: bool = True)#
Bases:
objectA one-to-many listener that accepts connections and yields TensorDictPipe instances.
Warning
TensorDictServeris experimental: its API can change in a minor release without a deprecation cycle.Wraps
ucxx.create_listenerto provide a server that can handle multiple clients, each getting their ownTensorDictPipe. It needs the optionalucxxpackage. Import it fromtensordict._ucxx.Examples
Each client connects with
TensorDictPipe.connect(). This example is not tested: it needsucxxand client processes.import asyncio from tensordict._ucxx import TensorDictServer async def handler(pipe): async for td in pipe: print(td["obs"].shape) async def main(): server = TensorDictServer(port=13337) await server.serve(handler) # runs until server.close() asyncio.run(main())
- async serve(on_connect: Callable[[TensorDictPipe], Awaitable[None]]) None#
Accept connections and call
on_connectfor each new client.This runs indefinitely until
close()is called.- Parameters:
on_connect – an async callable that receives a
TensorDictPipefor each new client connection.