Repository navigation
[Tokenizer] Qualify the multi-tokenizer args shm name with the PID namespace - #41362
Open
zidanehuang001 wants to merge 1 commit into
Open
zidanehuang001 wants to merge 1 commit into
zidanehuang001 wants to merge 1 commit into
Conversation
…mespace The main process writes the multi-tokenizer args to multi_tokenizer_args_<pid>, and the tokenizer workers and Engine.attach_tokenizer_worker read them back by pid. A pid is unique only within its PID namespace: containers that share /dev/shm (e.g. docker --ipc=host) each run their server as pid 1, so two servers on one host write the same segment, and one server's workers start with the other server's args. That server never passes its health check. Put the PID namespace (inode of /proc/self/ns/pid) in the name. Readers address the pid from the same namespace, so attaching by pid keeps working; without /proc the name keeps the pid-only form. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
zidanehuang001
requested review from
CatherineSue,
JustinTong0323,
Ying1123,
hnyls2002,
ispobock,
merrymercy,
slin1237 and
xiezhq-hermann
as code owners
September 26, 2026 18:08
This branch has not been deployed
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.
Motivation
With
--tokenizer-worker-num > 1, the main process writes(port_args, server_args, scheduler_info)to the shared memory segmentmulti_tokenizer_args_<main pid>, and every HTTP tokenizer worker (andEngine.attach_tokenizer_worker) reads it back by the parent's pid. A pid is unique only within its PID namespace. Containers that share/dev/shm(for exampledocker run --ipc=host, a common setting for NCCL and CUDA IPC) each run their server as pid 1, so two servers on one host both use/dev/shm/multi_tokenizer_args_1.write_to_shared_memoryreuses an existing segment of that name, so the second server overwrites the first server's args. Whichever server's workers read after the other server's write start up with the other server's args.Reproduced on a build from
nightly-dev-20260912-a2077862: two servers (ports 30011 and 30012) in two containers on one host, both with--ipc host --tokenizer-worker-num 2, started a few seconds apart:port_args(IPC endpoints in the other container's/tmp). Their post-warm-up/freeze_gcwent tohttp://127.0.0.1:30012.Health check failed. Server couldn't get a response from detokenizer for last 20 secondskept repeating until the test stopped it about 9 minutes later./healthreturned 503 and/generatetimed out. Server 30012 served normally.Modifications
multi_tokenizer_args_shm_name(main_pid)inmulti_tokenizer_mixin.pyputs the PID namespace in the name:multi_tokenizer_args_<pid-namespace inode>_<pid>, where the inode comes fromos.stat("/proc/self/ns/pid").st_ino. Where/procis unavailable (e.g. macOS) the name staysmulti_tokenizer_args_<pid>.write_data_for_multi_tokenizer) and both readers (init_multi_tokenizerinhttp_server.pyandEngine.attach_tokenizer_worker) use the helper.attach_tokenizer_worker(parent_pid)keeps working. A process that can addressparent_pidis in the same PID namespace as that process, so it derives the same name. A random name handed to the workers through the environment would also fix the collision, but a process that is not a child of the server could not find that name.stale_shm_cleanup.pyneeds no change._creator_pidstill reads the pid from the last_field, and a test now covers the new name format.Accuracy Tests
No change to model outputs. The only change is where the tokenizer workers read their startup args.
test/registered/unit/managers/test_multi_tokenizer_mixin.py:/proc, the name falls back to the pid-only form.test_stale_shm_cleanup.pychecks that_creator_pidparses the new name. Both files pass (9 tests and 8 tests;test_orphan_family_sweepis skipped because it is CI-only)./healthand served/generate. The segments weremulti_tokenizer_args_4026543358_1andmulti_tokenizer_args_4026543383_1, matching the PID-namespace inodes of the two containers. Each server logged twoHealth check failedwarnings before its first request, the same as the healthy server in the unpatched run.Engine.attach_tokenizer_worker, sotest_engine_multi_tokenizer.pywas not run here. That test attaches from a spawned child, which is in the parent's PID namespace, so it derives the same name.Speed Tests and Profiling
Not applicable. The only extra work is one
statcall at startup per process.Related
/dev/shmis shared across PID namespaces, a pid from another namespace can't be checked for liveness. With this change, the name of this segment identifies its namespace.Engine.attach_tokenizer_worker.Checklist
🤖 Generated with Claude Code
CI States
Latest PR Test (Base): ❌ Run #36261501594
Latest PR Test (Extra): ❌ Run #36261501322
Latest PR Test (AMD ROCm 10): ❌ Run #36261501492