fix(tp): acknowledge shm reads so rank0 cannot corrupt in-flight RPC (#246)#248
Open
Anai-Guo wants to merge 1 commit into
Open
fix(tp): acknowledge shm reads so rank0 cannot corrupt in-flight RPC (#246)#248Anai-Guo wants to merge 1 commit into
Anai-Guo wants to merge 1 commit into
Conversation
…eeeekExplorer#246) In tensor-parallel mode the rank0->worker command channel only had a forward notification event, so rank0 could overwrite the shared-memory buffer with the next RPC while a worker was still reading the previous pickled payload, causing _pickle.UnpicklingError and a subsequent NCCL hang. Add a per-worker acknowledgement event: each worker sets it after fully reading a command, and rank0 waits for all acks before reusing the buffer. Ack events are pre-set so the first command is not blocked.
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.
Summary
Fixes #246.
In tensor-parallel mode (
tensor_parallel_size > 1), rank0 dispatches method calls to worker ranks through a shared-memory buffer plus a per-workermultiprocessing.Event. The protocol only had a forward (rank0 → worker) notification: there was no acknowledgement that a worker had finished reading the previous command.As a result rank0 could return from one
call()and immediatelywrite_shm()the next RPC, overwriting the shared buffer while a worker was still insidepickle.loads(self.shm.buf[...])for the previous command. That corrupts the payload (_pickle.UnpicklingError); once one worker rank dies, the surviving ranks hang in the next NCCL collective until timeout.Fix
Add a per-worker acknowledgement event that closes the handshake:
read_shm(worker): after fully reading and unpickling the payload,self.ack_event.set().write_shm(rank0): before overwriting the buffer,wait()+clear()every worker's ack event, so the buffer is only reused once all workers have consumed the previous command.LLMEngineso the very first command isn't blocked waiting on a read that hasn't happened yet.This is the ping-pong the buffer needs: rank0 clears each ack before setting the forward event, and a worker sets its ack only after the read completes, so no signal is lost and no read races an overwrite. No change to the public
LLM/LLMEngineAPI; onlyModelRunner's internal constructor gains anack_eventargument, and its sole caller (LLMEngine) is updated.Testing
python -m py_compileon both changed modules.call("exit")still drains cleanly) and the bootstrap case (pre-set acks let the firstwrite_shmproceed).🤖 Generated with Claude Code