Skip to content

[Refactor] tokenizer: Fold TokenizerWorker into TokenizerManager - #48119

Merged
hnyls2002 merged 4 commits into
mainfrom
lsyin/multi-tokenizer-dedup
Nov 3, 2026
Merged

hnyls2002 merged 4 commits into
mainfrom
lsyin/multi-tokenizer-dedup

Conversation

@hnyls2002

@hnyls2002 hnyls2002 commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator
  • TokenizerWorker is folded into TokenizerManager. A manager behind MultiTokenizerRouter (tokenizer_ipc_name is set) registers with the router, sends pause/continue through it and applies the PauseContinueBroadcastReq the router sends to every tokenizer process; it does not start the PD bootstrap service, which the router runs. This replaces the start_pd_bootstrap_service argument of TokenizerManager.__init__.
  • ServerArgs.get_tokenizer_worker_class() stays the hook for the class used in multi-tokenizer mode. It now returns TokenizerManager, and a custom class subclasses TokenizerManager instead of TokenizerWorker.
  • The process title and torch.set_num_threads(1) move to the HTTP worker's init_multi_tokenizer.
  • _handle_output_by_index builds the single-row output from the struct fields, as _handle_output_by_indices does, instead of listing every field per output type.

No behavior change, except that:

  • a single-row split now carries prompt_tokens, cached_tokens, image_tokens, audio_tokens and video_tokens (set only by the Rust server) instead of dropping them;
  • a parent Engine with tokenizer_worker_num > 1 no longer renames its process or sets its torch thread count to 1.

CI States

Latest PR Test (Base): 🚫 Run #41721874526
Latest PR Test (Extra): ❌ Run #41721874265
Latest PR Test (AMD ROCm 10): 🚫 Run #41721874358

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

@hnyls2002
hnyls2002 requested a review from merrymercy as a code owner November 3, 2026 08:58

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

…pause/continue helper; import torch at the top of http_server
@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/rerun-test test_multi_tokenizer_mixin.py test_tokenizer_config_updates.py test_tokenizer_manager_rid_cleanup.py test_engine_multi_tokenizer.py registered/tokenizer/test_multi_tokenizer.py test_http2_server.py registered/tokenizer/test_skip_tokenizer_init.py

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

🚀 ubuntu-latest (3 tests): ✅ View workflow run

cd test/ && python3 registered/unit/managers/test_multi_tokenizer_mixin.py
cd test/ && python3 registered/unit/managers/test_tokenizer_config_updates.py
cd test/ && python3 registered/unit/managers/test_tokenizer_manager_rid_cleanup.py

🚀 1-gpu-h100 (1 test): ✅ View workflow run

cd test/ && python3 registered/e2e/entrypoints/test_engine_multi_tokenizer.py

🚀 2-gpu-h100 (1 test): ✅ View workflow run

cd test/ && python3 registered/tokenizer/test_multi_tokenizer.py

🚀 1-gpu-5090 (2 tests): ✅ View workflow run

cd test/ && python3 registered/openai_server/basic/test_http2_server.py
cd test/ && python3 registered/tokenizer/test_skip_tokenizer_init.py

@hnyls2002 hnyls2002 added the run-ci CI: run the baseline test suite on this PR label Nov 3, 2026
@hnyls2002
hnyls2002 merged commit 4e5057a into main Nov 3, 2026
112 of 151 checks passed
@hnyls2002
hnyls2002 deleted the lsyin/multi-tokenizer-dedup branch November 3, 2026 21:47
detain added a commit to detain/sglang that referenced this pull request Nov 11, 2026
…oot order -- maybe_init_router_registration moved back to __init__'s last step (upstream 4e5057a sgl-project#48119 placement)

Operator's real restart died at boot (era tip b069e6a):
  tokenizer_manager.py:623 __init__ -> :667 init_preprocess_executor ->
  :958 maybe_init_router_registration -> AttributeError:
  'TokenizerManager' object has no attribute 'tokenizer_ipc_name'

Root cause: upstream folded the registration in as the LAST statement of
__init__ (after init_ipc_channels assigns tokenizer_ipc_name/send_to_scheduler
and after the cuda_vmm transport construction); the fork (stack sgl-project#201, PR
sgl-project#39716) runs its init_preprocess_executor BEFORE init_ipc_channels, and the
b4 merge resolution wired the upstream call inside that earlier step -- so it
read attributes that are not assigned until the next step. Single-worker
servers crashed too: the read is unconditional in the method's guard.

Fix: move the call out of init_preprocess_executor to upstream's exact
position (final __init__ step). No guard, no hasattr -- the method's
semantics (dispatch over IPC) require the channels, which the fork builds
later; only the order was wrong. 2-line move + comment.

Regression test test_tokenizer_manager_init_order.py drives the REAL
__init__ sequence (only model/tokenizer loading, the SHM snapshot reader,
and sock_send stubbed), parameterized router OFF (tokenizer_worker_num=1:
construction completes, nothing dispatched) / ON (=2: exactly one
TokenizerWorkerRegistrationReq with the worker's IPC name, dispatched after
the attrs exist). RED at b069e6a: 2F (the verbatim AttributeError).
GREEN: 2P.

Family scan (window methods from 2a6c204..eb73a50 in
tokenizer_manager/detokenizer_manager, MRO-precise assignment check): no
other never-assigned attribute and no second init-order hazard; all other
window methods are post-init request handlers whose attrs init assigns
(detokenizer init chain verified). Uncertain-adjacent, report-only:
get_tokenizer_worker_class/entrypoints wiring untouched (outside managers
init zone).

Gates: ruff v0.15.1 F401,F821,F823,UP037 + format rc=0; check_registered_tests
/ check_no_bare_pytest_main / check_no_registered_tests_in_package rc=0;
import probe (CUDA_VISIBLE_DEVICES=9) rc=0; managers battery 1301P/2F/11s --
2F are the pre-existing test_mm_process_config pair, unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant