Repository navigation
[Refactor] tokenizer: Fold TokenizerWorker into TokenizerManager - #48119
Merged
Merged
Conversation
There was a problem hiding this comment.
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.
hnyls2002
requested review from
CatherineSue,
JustinTong0323,
Ying1123,
ispobock,
slin1237 and
xiezhq-hermann
as code owners
November 3, 2026 08:58
…pause/continue helper; import torch at the top of http_server
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 |
Contributor
|
🚀 🚀 🚀 🚀 |
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.
1 task done
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
TokenizerWorkeris folded intoTokenizerManager. A manager behindMultiTokenizerRouter(tokenizer_ipc_nameis set) registers with the router, sends pause/continue through it and applies thePauseContinueBroadcastReqthe router sends to every tokenizer process; it does not start the PD bootstrap service, which the router runs. This replaces thestart_pd_bootstrap_serviceargument ofTokenizerManager.__init__.ServerArgs.get_tokenizer_worker_class()stays the hook for the class used in multi-tokenizer mode. It now returnsTokenizerManager, and a custom class subclassesTokenizerManagerinstead ofTokenizerWorker.torch.set_num_threads(1)move to the HTTP worker'sinit_multi_tokenizer._handle_output_by_indexbuilds the single-row output from the struct fields, as_handle_output_by_indicesdoes, instead of listing every field per output type.No behavior change, except that:
prompt_tokens,cached_tokens,image_tokens,audio_tokensandvideo_tokens(set only by the Rust server) instead of dropping them;Enginewithtokenizer_worker_num > 1no 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-testto run the tests your change touches, or copy this prompt for an agent: