Skip to content

Update: start L2 worker hierarchy eagerly in Worker.init() - #1381

Closed
YunjiQin wants to merge 1 commit into
hw-native-sys:mainfrom
YunjiQin:eager-l2-worker-init
Closed

Update: start L2 worker hierarchy eagerly in Worker.init()#1381
YunjiQin wants to merge 1 commit into
hw-native-sys:mainfrom
YunjiQin:eager-l2-worker-init

Conversation

@YunjiQin

Copy link
Copy Markdown
Contributor

Summary

Move _start_hierarchical() into Worker.init() for L3+ workers, so the
whole L2 hierarchy is live — chip/sub children forked, ChipWorker.init
done, ChipCallables uploaded H2D, prewarm complete — by the time init()
returns, instead of being deferred to the first run().

  • Call _start_hierarchical() from init() (inside the try block, so a
    startup failure is reaped by _cleanup_partial_init).
  • Remove the five now-redundant lazy trigger sites (run,
    create_host_buffer, remote require/register/unregister). Each is reached
    only after init(), so the calls were idempotent no-ops.
  • Behavioral change: registrations between init() and run() now take
    the post-start broadcast path; a childless L3 registering a Python fn after
    init() raises eagerly instead of being silently snapshotted.
  • Update docstrings/comments and docs (task-flow, worker-manager,
    hierarchical_level_runtime) to describe eager startup.
  • Rework the three test_host_worker tests that asserted the removed
    "init-done-but-not-started" window; stub _start_hierarchical in the
    remote-id bookkeeping unit test that uses a fake C worker.

Testing

  • Python unit tests pass: test_host_worker (63),
    test_callable_identity + test_remote_l3_lifecycle (84),
    test_l4_recursive + test_ensure_prepared + test_error_propagation (27).
  • Onboard / sim st tests: not validated locally. The dev box
    (320 cores, OMP_NUM_THREADS unset) hangs fork-heavy L3 st tests due to a
    pre-existing torch-OpenMP fork-safety issue that reproduces identically on
    main
    and is unrelated to this change (torch spawns a 320-thread pool
    at import, before any Worker ctor, so a forked chip child inherits a
    corrupt pool and deadlocks). Relying on CI for onboard/sim coverage.

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 30efd4c8-1b50-4689-97b1-2698d97d9327

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Hierarchical workers now start eagerly during Worker.init() for L3+ levels. Lazy startup calls were removed from runtime paths, tests were adjusted for pre-init behavior, and fork-order documentation was updated.

Changes

Hierarchical startup timing

Layer / File(s) Summary
Move hierarchical startup into init()
python/simpler/worker.py
Worker.init() now starts L3+ hierarchies, while remote operations, host-buffer creation, and dispatch rely on already-started workers.
Align tests and fork-order documentation
tests/ut/py/test_callable_identity.py, tests/ut/py/test_worker/test_host_worker.py, docs/*.md
Tests cover pre-init registration behavior, and documentation describes eager nested forking during initialization.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Worker
  participant Hierarchy
  participant InnerWorker
  participant ChildWorkers
  Worker->>Hierarchy: Worker.init() calls _start_hierarchical()
  Hierarchy->>InnerWorker: create and initialize L3 worker
  InnerWorker->>ChildWorkers: eagerly fork sub/chip children
  Worker->>InnerWorker: dispatch via inner_worker.run(...)
Loading

Possibly related PRs

Poem

I’m a bunny by the forked-worker tree,
Eager children now hop free.
Init starts the nested flight,
Dispatch waits till paths are right.
Docs and tests now sing along—
Thump, thump, startup’s timing song!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: eager worker hierarchy startup in Worker.init().
Description check ✅ Passed The description matches the changeset and accurately describes the eager startup, removed lazy triggers, docs, and test updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request changes the initialization behavior of hierarchical workers (level >= 3) to be eager rather than lazy. Specifically, _start_hierarchical(), which forks child processes and starts the C++ scheduler, is now called directly within init() instead of being deferred to the first run(). Consequently, various deferred startup calls and state checks across worker.py have been removed, and the documentation and unit tests have been updated to align with this eager initialization model. There are no review comments, so I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@YunjiQin
YunjiQin force-pushed the eager-l2-worker-init branch 6 times, most recently from c628ed8 to 4925f72 Compare July 17, 2026 06:22
@YunjiQin
YunjiQin force-pushed the eager-l2-worker-init branch from 4925f72 to c8b094d Compare July 17, 2026 10:31
Move _start_hierarchical() into Worker.init() for L3+ workers, so the
whole L2 hierarchy is live — chip/sub children forked, ChipWorker.init
done, ChipCallables uploaded H2D, prewarm complete — by the time init()
returns, instead of being deferred to the first run().

- Call _start_hierarchical() from init() for L3+, inside the try block
  so a startup failure is reaped by _cleanup_partial_init.
- Remove the five now-redundant lazy trigger sites (run,
  create_host_buffer, remote require/register/unregister); each is
  reached only after init(), so the calls were idempotent no-ops.
- New contract: input tensors must be allocated before init(), or via
  create_host_buffer after init(). SceneTestCase's L3 path rehosts
  generate_args() tensors onto create_host_buffer regions so the
  eagerly-forked chip children can see them.
- Fix a latent create_host_buffer bug the rehosting exposed:
  _rewrite_blob_host_addrs rewrote EVERY tensor whose VA fell in a
  registered host-buffer range, including child_memory device pointers
  (an HCCL comm-window scratch slot). A collective's window pointer whose
  numeric VA coincidentally collided with a host-buffer parent VA got
  redirected into a create_host_buffer mapping, deadlocking the exchange.
  Skip child_memory tensors (byte 43 of the 128 B Tensor) — only host
  pointers are ever rewritten.
- Registrations between init() and run() now take the post-start
  broadcast path; a childless L3 registering a Python fn after init
  raises eagerly instead of being silently snapshotted.
- Update docstrings/comments and docs (task-flow, worker-manager,
  hierarchical_level_runtime) to describe eager startup.
- Rework the three host-worker tests that asserted the removed
  "init-done-but-not-started" window; stub _start_hierarchical in the
  remote-id bookkeeping unit test that uses a fake C worker.
@ChaoWao

ChaoWao commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

Closing as superseded by #1397 (merged as 483d97e).

#1397 delivers the complete eager, transactional, recursive Worker.init() this PR set out to start, and is a strict superset: it moves hierarchy startup into init() (the goal here) and adds the atomic NEW→INITIALIZING→READY|FAILED commit, recursive full-tree READY for L4→L3→L2, a single shared startup deadline, bounded rollback with process-group (SIGTERM/killpg) cancellation, prewarm-before-READY, the child_memory host-address rewrite guard, and the SceneTest rehost adapter — built on top of the #1396 readiness protocol, with full CI green including st-onboard-a2a3/st-onboard-a5.

Thanks for the original direction. Closing to keep the eager-init work tracked in one place.

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