-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[TRTLLM-8189][chore] enhance GenerationExecutor with RPC (part1) #5543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
994f72c
init
Superjomn 3cd2103
fix test
Superjomn df1ee9e
refactor worker
Superjomn b4ab041
support client shutdown_server and cancel requests
Superjomn d34ce1b
support rpc streaming call
Superjomn dc9f745
refactor RPC client interface
Superjomn 1d1fd7c
fix WorkerBase and test
Superjomn 0f646e4
fix rpc server pickle error
Superjomn 6269ae4
add llm tests
Superjomn 78b6869
fix orchestrator_type
Superjomn 4a903ce
add get_stats and kv_cache_event
Superjomn a86ec76
better reuse code between remote methods
Superjomn f13a34e
add rpc test list
Superjomn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| # A Lightweight RPC | ||
| This is a pure-Python lightweight RPC we build to simplify our existing IPC code in the orchestrator part. It provides multiple call modes (sync, async, future, streaming) and supports both IPC and TCP connections. | ||
|
|
||
| ## Examples | ||
| ### Create Server and Client | ||
|
|
||
| ```python | ||
| from tensorrt_llm.executor.rpc import RPCServer, RPCClient | ||
|
|
||
| # Define your application | ||
| class App: | ||
| def add(self, a: int, b: int) -> int: | ||
| return a + b | ||
|
|
||
| async def async_multiply(self, x: int, y: int) -> int: | ||
| return x * y | ||
|
|
||
| # Create and start server | ||
| app = App() | ||
| with RPCServer(app) as server: | ||
| server.bind("ipc:///tmp/my_rpc") # or "tcp://127.0.0.1:5555" | ||
| server.start() | ||
|
|
||
| # Create client and make calls | ||
| with RPCClient("ipc:///tmp/my_rpc") as client: | ||
| result = client.add(5, 3).remote() | ||
| print(result) # Output: 8 | ||
| ``` | ||
|
|
||
| ### Different Remote Calls | ||
|
|
||
| #### Synchronous Call | ||
| ```python | ||
| # Blocking call that waits for result | ||
| result = client.add(10, 20).remote() | ||
| # or with timeout | ||
| result = client.add(10, 20).remote(timeout=5.0) | ||
| ``` | ||
|
|
||
| #### Asynchronous Call | ||
| ```python | ||
| # Async call that returns a coroutine | ||
| result = await client.async_multiply(3, 4).remote_async() | ||
Superjomn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| #### Future-based Call | ||
| ```python | ||
| # Returns a concurrent.futures.Future | ||
| future = client.add(1, 2).remote_future() | ||
| # Get result later | ||
| result = future.result() | ||
| ``` | ||
|
|
||
| #### Fire-and-Forget Call | ||
| ```python | ||
| # Send request without waiting for response | ||
| client.submit_task(task_id=123).remote(need_response=False) | ||
| ``` | ||
|
|
||
| #### Streaming Call | ||
| ```python | ||
| # For async generator methods | ||
| async for value in client.stream_data(n=10).remote_streaming(): | ||
| print(f"Received: {value}") | ||
| ``` | ||
|
|
||
| ### Error Handling | ||
| ```python | ||
| from tensorrt_llm.executor.rpc import RPCError, RPCTimeout | ||
|
|
||
| try: | ||
| result = client.risky_operation().remote(timeout=1.0) | ||
| except RPCTimeout: | ||
| print("Operation timed out") | ||
| except RPCError as e: | ||
| print(f"RPC Error: {e}") | ||
| print(f"Original cause: {e.cause}") | ||
| print(f"Traceback: {e.traceback}") | ||
| ``` | ||
|
|
||
| ### Graceful Shutdown | ||
| ```python | ||
| # Shutdown server from client | ||
| client.shutdown_server() | ||
| ``` | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| from .rpc_client import RPCClient | ||
| from .rpc_common import (RPCCancelled, RPCError, RPCParams, RPCRequest, | ||
| RPCResponse, RPCStreamingError, RPCTimeout) | ||
| from .rpc_server import RPCServer, Server | ||
|
|
||
| __all__ = [ | ||
| "RPCClient", "RPCServer", "Server", "RPCError", "RPCTimeout", | ||
| "RPCCancelled", "RPCStreamingError", "RPCRequest", "RPCResponse", | ||
| "RPCParams" | ||
| ] |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.