-
-
Notifications
You must be signed in to change notification settings - Fork 17.8k
[Fix][MoRI] Align MoRI-IO message format with P2pNcclConnector and vllm-router #39565
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
tjtanaa
merged 14 commits into
vllm-project:main
from
simondanielsson:fix/align-moriio-messages
Apr 22, 2026
+203
−91
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0168926
[Fix] Align MoRIIO registration format with vLLM router and handle de…
mpashkovskii a0efc3d
[Fix] Enhance MoRIIOConnectorScheduler to return KV transfer paramete…
mpashkovskii 7c8ffbf
fix: embed non-standard kv_transfer_params fields into zmq_address
simondanielsson da139fd
fix: set moriio ping interval to 3s from 5s
simondanielsson 1639adf
fix: add potential '-<seq>-<hex>' suffix to _DECODE_ZMQ_RE regex
simondanielsson 7ef0d71
fix: raise error if zmq_address is malformed instead of falling back …
simondanielsson 54f4112
fix: discard registrations with incorrect transfer mode
simondanielsson 93ef546
fix: refresh existing entries in router upon matching http_address
simondanielsson 50578b9
fix: pass transfer_id in decode request
simondanielsson ab58983
fix: log unrecognized message formats in toy proxy
simondanielsson 619af87
Merge remote-tracking branch 'upstream/main' into fix/align-moriio-me…
simondanielsson 65ffb26
Merge remote-tracking branch 'upstream/main' into fix/align-moriio-me…
simondanielsson 0d8518d
Merge remote-tracking branch 'upstream/main' into fix/align-moriio-me…
simondanielsson bb4720c
Merge branch 'main' into fix/align-moriio-messages
tjtanaa 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,6 @@ | |
|
|
||
| import aiohttp | ||
| import msgpack | ||
| import regex as re | ||
| import zmq | ||
| from quart import Quart, Request, make_response, request | ||
|
|
||
|
|
@@ -25,32 +24,10 @@ | |
| request_nums = 0 | ||
| app = Quart(__name__) | ||
|
|
||
| IP_PORT_PATTERN = re.compile(r"//(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(\d+)") | ||
|
|
||
|
|
||
| TRANSFER_TYPE = None | ||
|
|
||
|
|
||
| def _append_whole_dict_unique(target_list, data_dict): | ||
| new_filtered = {k: v for k, v in data_dict.items() if k != "index"} | ||
| for existed in target_list: | ||
| existed_filtered = {k: v for k, v in existed.items() if k != "index"} | ||
| if existed_filtered == new_filtered: | ||
| return False | ||
| print("!!APPEND!!", data_dict) | ||
| target_list.append(data_dict) | ||
| transfer_mode = data_dict.get("transfer_mode", "unknown") | ||
| global TRANSFER_TYPE | ||
|
|
||
| if TRANSFER_TYPE is None: | ||
| TRANSFER_TYPE = transfer_mode | ||
| logger.info("SET TRANSFER TYPE TO %s", TRANSFER_TYPE) | ||
| elif transfer_mode != TRANSFER_TYPE: | ||
| raise ValueError(f"mismatched transfer mode {TRANSFER_TYPE} vs {transfer_mode}") | ||
|
|
||
| return True | ||
|
|
||
|
|
||
| _list_lock = threading.RLock() | ||
|
|
||
|
|
||
|
|
@@ -68,23 +45,81 @@ def _listen_for_register(hostname, port): | |
| if router_socket in socks: | ||
| remote_addr, msg = router_socket.recv_multipart() | ||
| data = msgpack.loads(msg) | ||
| if data["type"] == "HELLO": | ||
| if data.get("type") == "HELLO": | ||
| pass | ||
| elif ( | ||
| data["type"] == "register" | ||
| and data["role"] == "P" | ||
| and data["request_address"] not in prefill_instances | ||
| ): | ||
| elif data.get("type") in ("P", "D"): | ||
| role = data["type"] | ||
| required_keys = { | ||
| "http_address", | ||
| "zmq_address", | ||
| "dp_size", | ||
| "tp_size", | ||
| "transfer_mode", | ||
| } | ||
| missing = required_keys - data.keys() | ||
| if missing: | ||
| logger.error( | ||
| "Registration message missing required keys %s; skipping", | ||
| missing, | ||
| ) | ||
| continue | ||
| # Derive request_address from http_address | ||
| # api path suffix is appended at request time | ||
| instance = { | ||
| "role": role, | ||
| "request_address": f"http://{data['http_address']}/v1", | ||
| "http_address": data["http_address"], | ||
| "zmq_address": data["zmq_address"], | ||
| "dp_size": data["dp_size"], | ||
| "tp_size": data["tp_size"], | ||
| "transfer_mode": data["transfer_mode"], | ||
| } | ||
| # zmq_address format: "host:IP,handshake:PORT,notify:PORT" | ||
| # Stored verbatim; embedded into the request_id by handle_request. | ||
|
|
||
| global TRANSFER_TYPE | ||
| transfer_mode = instance["transfer_mode"] | ||
| target_list = prefill_instances if role == "P" else decode_instances | ||
| with _list_lock: | ||
| _append_whole_dict_unique(prefill_instances, data) | ||
|
|
||
| elif ( | ||
| data["type"] == "register" | ||
| and data["role"] == "D" | ||
| and data["request_address"] not in decode_instances | ||
| ): | ||
| with _list_lock: | ||
| _append_whole_dict_unique(decode_instances, data) | ||
| if TRANSFER_TYPE is None: | ||
| TRANSFER_TYPE = transfer_mode | ||
| logger.info("SET TRANSFER TYPE TO %s", TRANSFER_TYPE) | ||
| elif transfer_mode != TRANSFER_TYPE: | ||
| logger.error( | ||
| "Mismatched transfer mode: expected %s, got %s;" | ||
| " skipping registration of %s", | ||
| TRANSFER_TYPE, | ||
| transfer_mode, | ||
| data["http_address"], | ||
| ) | ||
| continue | ||
| existing_idx = next( | ||
| ( | ||
| idx | ||
| for idx, i in enumerate(target_list) | ||
| if i.get("http_address") == data["http_address"] | ||
| ), | ||
| None, | ||
| ) | ||
| if existing_idx is not None: | ||
| target_list[existing_idx] = instance | ||
| logger.info( | ||
| "Updated existing %s instance: %s", | ||
| "Prefill" if role == "P" else "Decode", | ||
| instance, | ||
| ) | ||
| else: | ||
| target_list.append(instance) | ||
| logger.info( | ||
| "Registered %s instance: %s", | ||
| "Prefill" if role == "P" else "Decode", | ||
| instance, | ||
| ) | ||
| else: | ||
| logger.warning( | ||
| "Received message with unrecognized type %r; ignoring", | ||
| data.get("type"), | ||
| ) | ||
|
|
||
|
|
||
| def start_service_discovery(hostname, port): | ||
|
|
@@ -101,20 +136,16 @@ def start_service_discovery(hostname, port): | |
|
|
||
|
|
||
| async def send_request_to_prefill( | ||
| endpoint, req_data, request_id, d_endpoint, dip, dport, selected_prefill_dp_rank | ||
| endpoint, req_data, request_id, selected_prefill_dp_rank | ||
| ): | ||
| req_data_copy = req_data | ||
|
|
||
| req_data_copy["kv_transfer_params"].update( | ||
| { | ||
| "do_remote_decode": True, | ||
| "do_remote_prefill": False, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Explanation: These were MoRI-specific fields. For uniformity we instead we embed them into the zmq_address which is then injected into the request id, similar to P2pNccl |
||
| "remote_handshake_port": d_endpoint["handshake_port"], | ||
| "remote_notify_port": d_endpoint["notify_port"], | ||
| "remote_engine_id": None, | ||
| "remote_block_ids": None, | ||
| "remote_host": dip, | ||
| "remote_port": dport, | ||
| } | ||
| ) | ||
| req_data_copy["stream"] = False | ||
|
|
@@ -197,14 +228,7 @@ async def handle_request(api: str, request: Request): | |
| global request_nums | ||
| request_nums += 1 | ||
|
|
||
| def extract_ip_port_fast(url): | ||
| match = IP_PORT_PATTERN.search(url) | ||
| if not match: | ||
| raise ValueError(f"Invalid URL format: {url}") | ||
| return match.groups() | ||
|
|
||
| req_data = await request.get_json() | ||
| request_id = str(uuid.uuid4()) | ||
|
|
||
| prefill_instance_endpoint = None | ||
| decode_instance_endpoint = None | ||
|
|
@@ -230,7 +254,14 @@ def extract_ip_port_fast(url): | |
| prefill_instance_endpoint["dp_size"], | ||
| ) | ||
|
|
||
| dip, dport = extract_ip_port_fast(decode_instance_endpoint["request_address"]) | ||
| # Embed both zmq_addresses in the request_id so the connector can parse | ||
| # the peer's host/ports from it, similar to P2P-NCCL | ||
| uid = str(uuid.uuid4()).replace("-", "") | ||
| request_id = ( | ||
| f"___prefill_addr_{prefill_instance_endpoint['zmq_address']}" | ||
| f"___decode_addr_{decode_instance_endpoint['zmq_address']}" | ||
| f"_{uid}" | ||
| ) | ||
|
|
||
| transfer_id = f"{MoRIIOConstants.TRANSFER_PREFIX}-{str(uuid.uuid4())}" | ||
|
|
||
|
|
@@ -251,35 +282,30 @@ def extract_ip_port_fast(url): | |
| prefill_request_url, | ||
| req_data_to_prefill, | ||
| request_id, | ||
| decode_instance_endpoint, | ||
| dip, | ||
| dport, | ||
| selected_prefill_dp_rank, | ||
| ) | ||
| ) | ||
| ip, port = extract_ip_port_fast(prefill_request_url) | ||
|
|
||
| req_data["max_tokens"] -= 1 | ||
|
|
||
| req_data["kv_transfer_params"] = { | ||
| "do_remote_decode": False, | ||
| "do_remote_prefill": True, | ||
| "remote_handshake_port": prefill_instance_endpoint["handshake_port"], | ||
| "remote_notify_port": prefill_instance_endpoint["notify_port"], | ||
| "remote_engine_id": None, | ||
| "remote_block_ids": None, | ||
| "remote_host": ip, | ||
| "remote_port": port, | ||
| "transfer_id": transfer_id, | ||
| } | ||
|
simondanielsson marked this conversation as resolved.
|
||
| if TRANSFER_TYPE == "READ": | ||
| # In read mode, prefill and decode are executed serially. | ||
| prefill_response = await send_prefill_task | ||
| req_data["kv_transfer_params"]["remote_engine_id"] = prefill_response[ | ||
| "kv_transfer_params" | ||
| ]["remote_engine_id"] | ||
| req_data["kv_transfer_params"]["remote_block_ids"] = prefill_response[ | ||
| "kv_transfer_params" | ||
| ]["remote_block_ids"] | ||
| prefill_kv = prefill_response["kv_transfer_params"] | ||
| req_data["kv_transfer_params"]["remote_engine_id"] = prefill_kv[ | ||
| "remote_engine_id" | ||
| ] | ||
| req_data["kv_transfer_params"]["remote_block_ids"] = prefill_kv[ | ||
| "remote_block_ids" | ||
| ] | ||
| req_data["kv_transfer_params"]["transfer_id"] = prefill_kv["transfer_id"] | ||
|
|
||
| req_data["kv_transfer_params"]["remote_dp_size"] = prefill_instance_endpoint[ | ||
| "dp_size" | ||
|
|
@@ -290,7 +316,6 @@ def extract_ip_port_fast(url): | |
|
|
||
| if selected_prefill_dp_rank is not None: | ||
| req_data["kv_transfer_params"]["remote_dp_rank"] = selected_prefill_dp_rank | ||
| req_data["kv_transfer_params"]["transfer_id"] = transfer_id | ||
|
|
||
| decode_request_url = decode_instance_endpoint["request_address"] + api | ||
| decode_request_task = asyncio.create_task( | ||
|
|
||
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
Oops, something went wrong.
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.