Skip to content

refactor: make time_stats msgpack-native - #30005

Open
oleksii-tumanov wants to merge 4 commits into
sgl-project:mainfrom
oleksii-tumanov:refactor/msgpack-time-stats
Open

oleksii-tumanov wants to merge 4 commits into
sgl-project:mainfrom
oleksii-tumanov:refactor/msgpack-time-stats

Conversation

@oleksii-tumanov

@oleksii-tumanov oleksii-tumanov commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Part of #29465. Task 2

Makes request time_stats msgpack-native by removing their remaining PickleWrapper usage.

Modifications

  • Convert request time stats to tagged msgspec.Struct types and remove their PickleWrapper paths.
  • Preserve tracing, cross-process clock conversion, pickle compatibility, and multi-tokenizer output handling.
  • Add transport tests for pickle and msgpack across request/output variants, including 128-bit trace IDs and disabled metrics.

Scheduler IPC snapshot with metrics enabled:

  • Before: 988 bytes; all 32 fields encoded, including defaults
  • After: 153 bytes; only the type tag, three required timestamps, and clock offset encoded

Accuracy Tests

Not applicable. This changes internal IPC serialization and does not affect model outputs.

Speed Tests and Profiling

No end-to-end inference benchmark was run because model execution is unchanged. The representative scheduler snapshot above verifies that default fields are omitted from the serialized payload.

Testing

  • PYTHONPATH=python python3 -m pytest test/registered/unit/observability/test_trace.py test/registered/unit/managers/test_io_struct.py test/registered/unit/managers/test_multi_tokenizer_mixin.py python/sglang/multimodal_gen/test/unit/test_disagg_trace.py -q (97 passed, 16 subtests passed)
  • pre-commit run --all-files (passed)
  • git diff --check (passed)

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 #29791248995
Latest PR Test (Extra): ❌ Run #29791248876

@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!

@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!

@oleksii-tumanov
oleksii-tumanov force-pushed the refactor/msgpack-time-stats branch from 90b5d76 to 288639a Compare July 3, 2026 05:45
@oleksii-tumanov oleksii-tumanov changed the title refactor: make time_stats msgpack-native (drop PickleWrapper) refactor: make time_stats msgpack-native Jul 3, 2026
@oleksii-tumanov
oleksii-tumanov force-pushed the refactor/msgpack-time-stats branch from 288639a to 532f045 Compare July 9, 2026 00:34
Comment thread python/sglang/srt/observability/req_time_stats.py Outdated
self.__dict__.update(state)

struct_fields = {field.name for field in msgspec.structs.fields(type(self))}
for key, value in state.items():

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.

It seems we could handle both timestamp conversion and setattr in a single iteration to avoid additional performance overhead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Implemented in 33f91c8df. setstate now converts timestamps and assigns struct fields in one pass without mutating the input state.

return TraceNullContext()

@staticmethod
def _encode_trace_ctx_ids(trace_ctx_state: Dict[str, Any]) -> Dict[str, 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.

Operations related to trace_ctx would be better implemented in python/sglang/srt/observability/trace.py, by directly modifying TraceReqContext.__getstate__() and __setstate__().

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks. I agree, TraceReqContext should be an owner for it and it should be backward compatible with old IDs. It will do a PR a bit bigger.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Implemented in 33f91c8df. TraceReqContext now owns fixed-width ID serialization and accepts legacy integer IDs; pickle, msgpack, and multimodal JSON round trips are covered.

@oleksii-tumanov
oleksii-tumanov force-pushed the refactor/msgpack-time-stats branch from 33f91c8 to 1040792 Compare July 19, 2026 08:55
@oleksii-tumanov
oleksii-tumanov requested a review from BBuf as a code owner July 19, 2026 08:55
@oleksii-tumanov

Copy link
Copy Markdown
Contributor Author

Hi @sufeng-buaa, I addressed your comments and rebased the PR onto the latest main. Could you please take another look when you have time? Thanks!

@sufeng-buaa

Copy link
Copy Markdown
Collaborator

Hi @sufeng-buaa, I addressed your comments and rebased the PR onto the latest main. Could you please take another look when you have time? Thanks!

OK, let me run some key tests locally.

@sufeng-buaa

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Jul 20, 2026
@oleksii-tumanov

Copy link
Copy Markdown
Contributor Author

@sufeng-buaa
The failed jobs appear unrelated to this PR (runner/cache failures). Could you please run /rerun-failed-ci? Thanks!

@sufeng-buaa

Copy link
Copy Markdown
Collaborator

@sufeng-buaa The failed jobs appear unrelated to this PR (runner/cache failures). Could you please run /rerun-failed-ci? Thanks!

It seems the main branch currently has some bugs, and so does my PR. We need to wait a while for others to fix the bug in the main branch, and then we can re-merge main.

@oleksii-tumanov

Copy link
Copy Markdown
Contributor Author

thank you for updates!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diffusion SGLang Diffusion run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants