Skip to content

Convert IPC dataclasses to msgspec.Struct with opt-in msgpack transport - #28688

Merged
merrymercy merged 3 commits into
mainfrom
dev/msgpack-migration
Jun 26, 2026
Merged

merrymercy merged 3 commits into
mainfrom
dev/msgpack-migration

Conversation

@rainj-me

@rainj-me rainj-me commented Jun 18, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Prepare SGLang IPC payloads for typed msgpack serialization without changing the default runtime transport yet.

This PR converts the IPC request/output classes from dataclasses to msgspec.Struct, but keeps pickle IPC enabled by default for compatibility. Developers can opt into the msgspec/msgpack transport by setting:

SGLANG_USE_PICKLE_IPC=0

For auditing fallback behavior, set:

SGLANG_LOG_PICKLE_IPC_OBJECTS=1

Changes

  • Convert IPC base/request/output classes in io_struct.py from dataclasses to msgspec.Struct.
  • Add pydantic schema support for msgspec-backed request structs.
  • Add msgpack encode/decode helpers and socket send/recv switching behind SGLANG_USE_PICKLE_IPC.
  • Keep pickle as the default IPC transport with SGLANG_USE_PICKLE_IPC=True.
  • Add typed encode/decode hooks for common payloads such as array, torch.Tensor, numpy.ndarray, and numpy floating scalars.
  • Add transitional PickleWrapper support for fields and structs that still carry opaque Python objects or broad Any/Dict[str, Any] payloads.
  • Wrap/unwrap known opaque IPC payloads such as time_stats, customized_info, multimodal inputs, and mooncake multimodal data at process boundaries.
  • Update tokenizer, detokenizer, scheduler receiver, DP controller, and multi-tokenizer routing paths for the wrapper protocol.
  • Add E2E coverage for customized_info through the normal scheduler -> detokenizer -> tokenizer-manager path.
  • Update unit test helpers to introspect msgspec.Struct fields instead of dataclass fields.

Notes

PickleWrapper is an intentional workaround during the migration. It lets the new typed structs travel through msgpack while fields that are not yet msgpack-safe continue to round-trip through pickle explicitly. This keeps the migration incremental and makes remaining pickle usage easier to audit.

The default behavior is still pickle IPC. The msgpack/msgspec path is opt-in with SGLANG_USE_PICKLE_IPC=0 until the remaining opaque fields are narrowed or wrapped safely.

Test Plan

PATH=.venv/bin:$PATH .venv/bin/python test/registered/unit/managers/test_tokenizer_manager_rid_cleanup.py
PATH=.venv/bin:$PATH .venv/bin/python test/registered/core/test_customized_info_e2e.py

CI States

Latest PR Test (Base): ✅ Run #28248758478
Latest PR Test (Extra): 🚫 Run #28248758407

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@rainj-me
rainj-me requested a review from sogalin as a code owner June 18, 2026 23:31
@github-actions github-actions Bot added the npu label Jun 18, 2026
@rainj-me rainj-me mentioned this pull request Jun 18, 2026
5 tasks done
@merrymercy

Copy link
Copy Markdown
Contributor

note for myself:

  • try to further simplify the type annotations
  • strictly review the auto-gen fastapi specs

@merrymercy

Copy link
Copy Markdown
Contributor

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Jun 19, 2026
@github-actions github-actions Bot added the diffusion SGLang Diffusion label Jun 19, 2026
@merrymercy merrymercy added run-ci CI: run the baseline test suite on this PR run-ci-extra CI: also run the extra suite (requires run-ci) labels Jun 25, 2026
@merrymercy
merrymercy force-pushed the dev/msgpack-migration branch from 8a89608 to e7f9926 Compare June 25, 2026 23:33
@merrymercy

Copy link
Copy Markdown
Contributor

good ci status


CI States

Latest PR Test (Base): ❌ Run #28207193093
Latest PR Test (Extra): ✅ Run #28207192971

@merrymercy
merrymercy force-pushed the dev/msgpack-migration branch from e7f9926 to 2cf97b4 Compare June 26, 2026 13:26
Comment thread python/sglang/srt/managers/data_parallel_controller.py
Comment thread python/sglang/test/scripted_runtime/scheduler_hook.py
@merrymercy
merrymercy force-pushed the dev/msgpack-migration branch from 2cf97b4 to c423efc Compare June 26, 2026 13:51
@merrymercy
merrymercy force-pushed the dev/msgpack-migration branch from b041945 to ab9be65 Compare June 26, 2026 14:09
@merrymercy
merrymercy force-pushed the dev/msgpack-migration branch from 6dcbcef to 0902d2c Compare June 26, 2026 15:05
@merrymercy

Copy link
Copy Markdown
Contributor

/tag-and-rerun-ci

@merrymercy
merrymercy merged commit be19301 into main Jun 26, 2026
404 of 461 checks passed
@merrymercy
merrymercy deleted the dev/msgpack-migration branch June 26, 2026 19:04
sunxxuns added a commit that referenced this pull request Jun 29, 2026
…ructions

PR #28688 (commit be19301) converted TokenizedGenerateReqInput from a
@DataClass to a kw_only=True msgspec.Struct, making token_type_ids
(declared Optional[List[int]] without a default) a required keyword
argument. The test was never updated, so both TokenizedGenerateReqInput
constructions raise TypeError: Missing required argument 'token_type_ids'.

This completes the fix started in PR #29584 which added input_embeds=None
but missed token_type_ids. The BatchTokenizedGenerateReqInput nested
construction is also fixed.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bypass-fastfail diffusion SGLang Diffusion documentation Improvements or additions to documentation high priority lora npu run-ci CI: run the baseline test suite on this PR run-ci-extra CI: also run the extra suite (requires run-ci)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants