Skip to content

use rpyc in model_rpc.py#1221

Merged
hiworldwzj merged 2 commits intomainfrom
wzj_fix
Mar 7, 2026
Merged

use rpyc in model_rpc.py#1221
hiworldwzj merged 2 commits intomainfrom
wzj_fix

Conversation

@hiworldwzj
Copy link
Collaborator

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the inter-process communication (IPC) layer within the LightLLM framework. The previous custom shared memory (SHM) based RPC system has been replaced with rpyc, a more robust and flexible Python library for remote procedure calls. This change streamlines the communication between the router and model inference processes, enhancing maintainability and potentially improving stability. Additionally, minor adjustments were made to model configuration, API arguments, and logging practices.

Highlights

  • RPC Mechanism Migration: The custom shared memory (SHM) based RPC mechanism has been replaced with rpyc for inter-process communication between the router and model inference processes. This involves removing the rpc_shm.py module and refactoring ModelRpcServer and ModelRpcClient to utilize rpyc services and asynchronous calls over Unix sockets.
  • Router Manager Updates: The RouterManager has been updated to remove dependencies on the old SHM RPC events and now manages multiple rpyc clients for model processes, allowing for parallel initialization and data retrieval across all model ranks.
  • Bloom Model Configuration: New attributes q_head_num_, k_head_num_, v_head_num_, and o_head_num_ were added to the Bloom transformer layer weight configuration.
  • API Argument Default Change: The default value for the --chunked_prefill_size argument in the API CLI was changed from 8192 to None.
  • Logging Improvement: The logging level for retry failure messages in retry_utils.py was adjusted from info to warning.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • lightllm/models/bloom/layer_weights/transformer_layer_weight.py
    • Added q_head_num_, k_head_num_, v_head_num_, and o_head_num_ attributes.
  • lightllm/server/api_cli.py
    • Updated the default value for chunked_prefill_size to None.
  • lightllm/server/core/objs/init.py
    • Removed imports related to the deprecated shared memory RPC (RpcShmParams, RpcShmResults, ShmSyncStatusArray).
  • lightllm/server/core/objs/rpc_shm.py
    • Removed the entire file, eliminating the custom shared memory RPC implementation.
  • lightllm/server/router/manager.py
    • Removed rpc_event and rpc_finished_event.
    • Changed model_rpc_servers to model_rpc_clients to reflect the new rpyc client management.
    • Refactored model initialization and get_max_total_token_num calls to iterate over multiple rpyc clients.
  • lightllm/server/router/model_infer/model_rpc.py
    • Replaced custom shared memory RPC with rpyc.
    • Converted ModelRpcServer to inherit from rpyc.Service and exposed methods with exposed_ prefix.
    • Refactored ModelRpcClient to establish rpyc connections over Unix sockets and use rpyc.async_ for remote calls.
    • Added _generate_unix_socket_path utility function.
    • Removed rpc_loop and related shared memory synchronization logic.
  • lightllm/utils/retry_utils.py
    • Changed the logging level for retry failure messages from info to warning.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the inter-process communication mechanism from a custom shared-memory implementation to using the rpyc library, which is a positive architectural change. However, a critical security vulnerability has been introduced by using rpyc with allow_pickle=True over a Unix domain socket located in the world-writable directory (/tmp). This configuration allows any local user on the system to achieve arbitrary code execution by sending malicious pickle payloads. Additionally, a change to a command-line argument default alters a key feature's behavior, which should be clarified for users.

success_event.set()
model_rpc_server = ModelRpcServer(args, rank, rank_in_node, node_world_size, info_queue)
# Start rpyc server with Unix socket
t = ThreadedServer(model_rpc_server, socket_path=socket_path, protocol_config={"allow_pickle": True})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-critical critical

The application uses the rpyc library for inter-process communication between the router and model inference processes. Both the server (ThreadedServer) and the client (unix_connect) are configured with allow_pickle=True. The communication occurs over a Unix domain socket located in the /tmp directory. Because /tmp is a world-writable directory on most Unix-like systems, any local user can identify the socket and connect to it. Since allow_pickle is enabled, an attacker can send a maliciously crafted pickled object to the server or client, which, upon deserialization, will execute arbitrary code in the context of the lightllm process.

return None
from lightllm.utils.retry_utils import retry

conn = retry(max_attempts=20, wait_time=2)(unix_connect)(socket_path, config={"allow_pickle": True})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-critical critical

The client side of the rpyc connection also enables allow_pickle=True. This exposes the client process to arbitrary code execution if it connects to a malicious socket or if the communication is intercepted by a local attacker who can connect to the Unix socket in /tmp.

Comment on lines +233 to +236
def _generate_unix_socket_path() -> str:
"""Generate a random Unix socket path"""
unique_id = uuid.uuid4().hex[:8]
return f"/tmp/lightllm_model_infer_{unique_id}.sock"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using /tmp for Unix domain sockets can be a security risk on multi-user systems. The /tmp directory is typically world-writable, and while the socket name is randomized, it's not impossible for another local user to discover and connect to it. Since protocol_config has allow_pickle=True, a malicious local user could potentially execute arbitrary code by sending crafted pickle data to the socket. It's strongly recommended to use a more secure location. For example, you could create a temporary directory with restricted permissions using tempfile.mkdtemp() and place the socket file there.

parser.add_argument("--disable_dynamic_prompt_cache", action="store_true", help="disable dynamic prompt cache")

parser.add_argument("--chunked_prefill_size", type=int, default=8192, help="chunked prefill size")
parser.add_argument("--chunked_prefill_size", type=int, default=None, help="chunked prefill size")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Changing the default value of chunked_prefill_size from 8192 to None effectively disables the chunked prefill feature by default. This is a significant change in default behavior that might surprise users. It would be good to either reconsider this change or update the help string to clarify that chunked prefill is disabled by default and must be explicitly enabled by setting a size.

@hiworldwzj hiworldwzj merged commit 8ed5074 into main Mar 7, 2026
1 check passed
@hiworldwzj hiworldwzj deleted the wzj_fix branch March 7, 2026 04:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant