Make WebSocket policy inference nonblocking#938
Open
taivu1998 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #717.
This changes the WebSocket policy server so blocking
policy.infer()calls no longer run directly on the asyncio event-loop thread. The server now offloads inference to a boundedThreadPoolExecutor, with--inference-workers=1as the default so calls into the shared policy object remain serialized unless users explicitly opt into more concurrency.Root Cause
WebsocketPolicyServer._handler()awaited websocket receive/send operations, but calledself._policy.infer(obs)synchronously between those awaits. A slow JAX/PyTorch inference could therefore occupy the event loop and delay other clients from connecting, receiving metadata, or making progress through websocket I/O.Changes
WebsocketPolicyServer.inference_workersserver/CLI option for explicitly thread-safe policies that can run concurrent inference calls.Validation
git diff --checkuvx ruff format src/openpi/serving/websocket_policy_server.py src/openpi/serving/websocket_policy_server_test.py scripts/serve_policy.pyuvx ruff check src/openpi/serving/websocket_policy_server.py src/openpi/serving/websocket_policy_server_test.py scripts/serve_policy.py docs/remote_inference.mdPYTHONPATH=src:packages/openpi-client/src uvx --python 3.11 --with websockets --with msgpack --with numpy --with pynvml pytest src/openpi/serving/websocket_policy_server_test.pyFocused tests passed with
7 passed, 1 warning.The full repo-native
uv run pytest --strict-markers -m "not manual"could not be run on this macOS arm64 host becausejax-cuda12-plugin==0.5.3only provides Linux wheels.