Skip to content

refactor: make mm_data_mooncake msgpack-native (drop PickleWrapper) - #29553

Closed
mvanhorn wants to merge 2 commits into
sgl-project:mainfrom
mvanhorn:refactor/29465-refactor-make-mmdatamooncake-msgpack-nat
Closed

mvanhorn wants to merge 2 commits into
sgl-project:mainfrom
mvanhorn:refactor/29465-refactor-make-mmdatamooncake-msgpack-nat

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Follow-up to #28688, which moved IPC dataclasses to msgspec.Struct and added the opt-in msgpack transport (SGLANG_USE_PICKLE_IPC=0). Several fields still fall back to PickleWrapper. This handles Task 6 of #29465: mm_data_mooncake on TokenizedGenerateReqInput was typed Optional[PickleWrapper] and carried a pickled List[{"url": ..., "modality": Modality}] produced by MMReceiverBase._extract_url_data. Giving it a concrete msgspec type removes the whole-field pickle round-trip on the mooncake encode path. It is the most self-contained of the open tasks: one field, a known shape, and a single producer.

Refs #29465

Modifications

  • Added a MooncakeMMUrlItem msgspec.Struct (url, modality) in io_struct.py and retyped mm_data_mooncake from Optional[PickleWrapper] to Optional[List[MooncakeMMUrlItem]]. url is typed Any because msgspec cannot express a union mixing str and bytes; every payload _extract_url_data produces (URL string, raw dict, or bytes) is a native msgpack type, so the field round-trips without a wrapper.
  • Dropped mm_data_mooncake from wrap_pickle_fields() / unwrap_pickle_fields() on TokenizedGenerateReqInput. mm_inputs and time_stats are untouched.
  • Updated the producer MMReceiverBase._extract_url_data to build MooncakeMMUrlItem instead of a dict, and switched every consumer in encode_receiver.py (mooncake RDMA dispatch, HTTP encode dispatch, gRPC encode, and _assign_items_by_modality) from ["url"]/["modality"] dict access to attribute access.
  • Added test/registered/unit/managers/test_io_struct_msgpack.py covering msgpack round-trip of mm_data_mooncake: populated string URLs, a raw dict payload, None, empty list, and each Modality variant.

tokenizer_manager.py (passes the field through) and request_logger.py (lists it as a log-skip name) need no change.

Accuracy Tests

Not applicable: this is a transport type change for an internal IPC field and does not affect model outputs.

Speed Tests and Profiling

Not applicable to accuracy; the change removes a pickle encode/decode for this field on the mooncake path under msgpack IPC.

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

CI States

Latest PR Test (Base): ❌ Run #28315034919
Latest PR Test (Extra): ❌ Run #28315034857

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

Copy link
Copy Markdown
Contributor

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 replaces the pickled dictionary representation of Mooncake multimodal URL data with a typed msgspec.Struct named MooncakeMMUrlItem. This allows native msgpack serialization and deserialization without pickle wrapping, improving performance and type safety. Corresponding updates were made in encode_receiver.py to use attribute access instead of dictionary access, and unit tests were added to verify the round-trip serialization of the new struct. There are no review comments, and I have no additional feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@ShangmingCai ShangmingCai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Logic looks good to me, but why only refactor mm_data_mooncake?

CC: @liusy58 @ZhengWG for double-check.

@ShangmingCai ShangmingCai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@rainj-me, could you also help check this?

@ronhuafeng

Copy link
Copy Markdown
Contributor

I validated the current PR head 95b01f7 for the Task 6 slice from #29465.

Local checks:

git diff --check HEAD^..HEAD

python3 -m py_compile \
  python/sglang/srt/managers/io_struct.py \
  python/sglang/srt/disaggregation/encode_receiver.py \
  test/registered/unit/managers/test_io_struct_msgpack.py

PYTHONPATH=python python3 -m pytest \
  test/registered/unit/managers/test_io_struct_msgpack.py -q

Results:

  • diff whitespace check: passed
  • py_compile for the changed Python files/test: passed
  • focused msgpack unit test in a disposable lmsysorg/sglang:latest container: 5 passed, 25 warnings, 3 subtests passed in 27.52s

I did not run GPU/server validation because this PR only changes the typed IPC
representation and unit coverage for mm_data_mooncake; it does not touch model
execution or GPU kernels.

``modality`` tags which encoder pool handles it.
"""

url: Any

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please treat Any extremely careful since the decode will never deserialize it.

@hnyls2002

Copy link
Copy Markdown
Collaborator

Thanks @mvanhorn! The encode_receiver.py module this PR refactors was removed in the New EPD refactor (#30398), so the change no longer applies. Closing as obsolete — please reopen against the new disaggregation/encoder/ layout if the msgpack-native cleanup is still relevant.

@hnyls2002 hnyls2002 closed this Sep 22, 2026
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.

5 participants