Skip to content

refactor(qwen35): split TP worker runtime into tp_executor/worker.rs - #1035

Open
CAICAIIs wants to merge 3 commits into
pegainfer-project:mainfrom
CAICAIIs:feat/qwen35-tp-worker-split
Open

CAICAIIs wants to merge 3 commits into
pegainfer-project:mainfrom
CAICAIIs:feat/qwen35-tp-worker-split

Conversation

@CAICAIIs

@CAICAIIs CAICAIIs commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

What

Split the TP worker runtime out of the tp_executor.rs God module into tp_executor/worker.rs, the same seam pattern as the landed scheduler/{backend,tp}.rs splits (#967, #968). Pure move; behavior unchanged. Rebased over #1004/#1005/#1033/#1038 — the moved content includes the batched eager decode, decode-graph precapture, and slot-compaction machinery as worker-concern code.

Stacked PR 1/3 — the follow-ups (#1036 responses split, #1037 scheduler steps split) sit on top of this branch; merge in order.

Structure

tp_executor.rs keeps command/reply types, the Qwen35TpExecutor orchestration (including the precapture sweep and retired-slot tracking), plan validators, and response validation. tp_executor/worker.rs now owns the per-rank runtime: TpWorker spawn/drop lifecycle, TpStartupGate, the NCCL startup watchdog, TpWorkerState/TpWorkerPrepared and the per-rank command loop (run/respond/execute_*/run_decode_batch{,_graph}/precapture_*), the slot bookkeeping helpers, the shared decode-row view/sampling helpers, recurrent-capacity math, and the worker CublasThreadGuard binding. Cross-concern items reach each other via the same use super::*; style the landed scheduler splits use; moved items gain pub(super) only where the entry or its tests name them.

Defense table (all inherited — pure move)

Defense Failure mode Successor
NCCL startup watchdog (60s abort) startup hang blocks the process silently inherited: worker.rs spawn_nccl_startup_watchdog
Bounded worker shutdown (30s → abort) worker thread never exits inherited: worker.rs TpWorker::join_bounded
Worker panic → runtime poison one rank dies, peers block in collective inherited: worker.rs spawn closure catch_unwind
Recurrent-capacity floor (max_batch > 0 ensure) silent zero-capacity executor inherited: worker.rs TpWorkerPrepared::new
cuBLAS/CUDA thread rebinding per worker thread wrong-context kernel launches inherited: worker.rs bind_worker_thread/CublasThreadGuard
Graph-state drop before NCCL comm teardown teardown hang on recorded collectives inherited: worker.rs TpWorkerState field-order comment

Validation

  • cargo fmt --check clean; cargo clippy -p pegainfer-qwen35 --features qwen35 --all-targets -- -D warnings clean.
  • cargo test --lib green; the seven tp2_* GPU tests pass on 2×A100 (-- --ignored --test-threads=1) against Qwen3.5-4B; e2e_scheduler green.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ebbabd53f4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread pegainfer-qwen35/src/weights/layers.rs Outdated

impl LinearAttentionLayer {
/// Phase 2b: shard linear attention over TP ranks. The value-head unit
/// Linear-attention sharding over TP ranks. The value-head unit

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Remove the unrelated phase-wording changes

This commit's stated invariant is a behavior-preserving TP worker module split, but this edit only removes historical phase wording; lib.rs contains the same ride-along cleanup. Neither file is needed for that split, so exclude these changes rather than expanding the refactor's scope contrary to the repository's requirement that every changed file serve the production invariant.

AGENTS.md reference: AGENTS.md:L123-L123

Useful? React with 👍 / 👎.

@CAICAIIs
CAICAIIs force-pushed the feat/qwen35-tp-worker-split branch 3 times, most recently from 55e217e to 48ec7cf Compare September 8, 2026 06:57
@FeathBow

FeathBow commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

@codex review please

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 48ec7cf56a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

const TP_WORKER_SHUTDOWN_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(30);
const TP_RUNTIME_MEMORY_RESERVE_BYTES: usize = 512 * 1024 * 1024;

pub(super) fn spawn_nccl_startup_watchdog() -> Result<(mpsc::SyncSender<()>, JoinHandle<()>)> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve the watchdog disarm regression test

The current revision still includes a fresh scope violation: while moving this watchdog into worker.rs, it deletes nccl_startup_watchdog_disarms_after_success instead of moving it with the implementation. That test verifies the watchdog observes the completion signal and joins promptly; removing it changes the verification surface even though this commit promises a behavior-preserving module split. Restore the test in the new module or handle its retirement as a separately justified change.

AGENTS.md reference: AGENTS.md:L121-L123

Useful? React with 👍 / 👎.

@CAICAIIs
CAICAIIs force-pushed the feat/qwen35-tp-worker-split branch from 48ec7cf to ed9b5be Compare September 8, 2026 09:23
Move the per-rank worker runtime out of the tp_executor.rs God module:
TpWorker + spawn/drop lifecycle, TpStartupGate, the NCCL startup watchdog,
TpWorkerState/TpWorkerPrepared and its command loop (run/respond/
execute_*/precapture/drop), the slot bookkeeping helpers, the shared
decode-row view/sampling helpers, recurrent-capacity math, and the worker
CublasThreadGuard binding. The entry keeps command/reply types, the
executor orchestration (including the precapture sweep), plan validators,
and response validation, reaching worker items via the same `use super::*`
style as scheduler/{backend,tp}. Rebased over pegainfer-project#720/pegainfer-project#722. Behavior
unchanged; the watchdog disarm test moves into worker.rs with its
implementation.

Signed-off-by: CAICAIIs <3360776475@qq.com>
@CAICAIIs
CAICAIIs force-pushed the feat/qwen35-tp-worker-split branch from ed9b5be to fbe384b Compare September 10, 2026 03:43
The tp_executor entry and the worker module carried two near-identical
condvar gates: TpCommandStartGate (Pending/Execute/Cancel, first-write
resolve returning whether it won) and TpStartupGate (Pending/Connect/
Cancel, silent set). Both broadcast one go/cancel decision that is
resolved exactly once, so they collapse into TpGate + TpGateDecision
with the first-write-wins resolve; startup treats Go as connect and
asserts on the returned decision instead of a bool. Behavior unchanged.

Signed-off-by: CAICAIIs <3360776475@qq.com>
The scheduler and the TP worker carried byte-identical CUDA/cuBLAS thread
bindings (guard + set_device + bind_to_thread + cublas_init); the worker
split moved one of the two copies, making the duplication visible. Both
now call crate::cublas_thread::bind_model_thread with a role tag (the
failure messages are unchanged); the scheduler keeps its
tune_decode_gemm_algos step at its own call site. Behavior unchanged.

Signed-off-by: CAICAIIs <3360776475@qq.com>
@FeathBow

Copy link
Copy Markdown
Collaborator

@codex review thx

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4c087a4998

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +383 to +385
match crate::cublas_thread::bind_model_thread(backend.model(), "scheduler") {
Ok(_guard) => {
if let Err(err) = backend.model().tune_decode_gemm_algos() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Remove the unrelated scheduler binding refactor

Fresh evidence beyond the earlier phase-wording comment is that this revision now rewrites the single-GPU scheduler to use a new crate-level cuBLAS binder and moves GEMM tuning out of the binder. Neither the scheduler path nor cublas_thread.rs is needed to move the TP worker runtime—worker.rs can retain its existing worker binder—so this broadens a stated behavior-preserving split and changes the tuning-failure cleanup path without separate justification; keep the scheduler unchanged and limit this commit to the worker move.

AGENTS.md reference: AGENTS.md:L121-L123

Useful? React with 👍 / 👎.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants