Skip to content

fix(ignition): expose current_source_roots and propagate source roots to tuning replicas - #678

Open
brandonmmusic-max wants to merge 1 commit into
NVIDIA:mainfrom
brandonmmusic-max:fix/spawn-propagate-source-roots
Open

brandonmmusic-max wants to merge 1 commit into
NVIDIA:mainfrom
brandonmmusic-max:fix/spawn-propagate-source-roots

Conversation

@brandonmmusic-max

@brandonmmusic-max brandonmmusic-max commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Why this change is needed

External recipe entrypoints (such as hyperflare_recipes.cli:main) bind recipe package directories through ignition.cli.main(..., source_roots=...), which stores (label, path) pairs in ignition.preparation.source_identity._EXTRA_ROOTS (a ContextVar). Without propagation across mp.get_context("spawn"), child processes start with an empty ContextVar, causing divergent ForwardCache roots (and FileNotFoundError or cache misses on main when loading rank 0's cache-relative paths, or explicit same-SKU cache-root mismatch errors when paired with unmerged PR #597).

Merged PR #670 (2acc3f3a) propagated bound source roots into ignition.preparation.rank_group._peer by importing private _EXTRA_ROOTS directly (matching aot.py). Two gaps remain on main:

  1. ignition/preparation/aot.py and ignition/preparation/rank_group.py import private _EXTRA_ROOTS directly from source_identity.py instead of using a public accessor.
  2. ignition/preparation/tuning_replicas.py spawns local tuning replicas via mp.get_context("spawn") without binding source_roots. Although _replica currently invokes prepare(..., compile_forwards=False) and exits on TuningComplete without reaching an in-tree ForwardCache or source_identity() call today, propagating bound source roots gives local tuning replicas spawn-boundary parity with rank_group._peer.

What changed

Before this change, aot.py and rank_group.py read _EXTRA_ROOTS.get() directly, source_identity.py exposed no public accessor, and tuning_replicas._replica executed with an empty source_roots context.

After this change:

  • ignition/preparation/source_identity.py: Added current_source_roots() -> tuple[tuple[str, Path], ...] returning _EXTRA_ROOTS.get(), and updated source_roots's docstring to cover active CLI and spawned worker contexts.
  • ignition/preparation/aot.py and ignition/preparation/rank_group.py: Replaced direct _EXTRA_ROOTS imports with current_source_roots(), keeping _EXTRA_ROOTS private to source_identity.py and leaving feat(helios,ignition): parameterize THINK_TAGS reasoning, add TAGGED_JSON tool parser, and propagate peer source roots #670's narrow with bind_source_roots(...) block in _peer untouched.
  • ignition/preparation/tuning_replicas.py: prepare_recipe captures current_source_roots() and passes extra_source_roots as a required argument to _replica, which binds with source_roots(extra_source_roots), CoreStorage(world=plan.world_size) as storage: around replica preparation.
  • tests/preparation/test_forward_cache_sources.py: Switched _record_source_roots_prepare to current_source_roots() (retaining feat(helios,ignition): parameterize THINK_TAGS reasoning, add TAGGED_JSON tool parser, and propagate peer source roots #670's real-spawn ForwardCache.root agreement assertions between rank 0 and rank 1 against the unbound baseline), added test_current_source_roots_reflects_active_scope, and added test_prepare_recipe_propagates_source_roots_to_spawned_tuning_replica asserting both current_source_roots() and ForwardCache.root agreement between replica 0 and spawned replica 1 against the unbound baseline.

Claimed benefit and compatibility impact

  • Encapsulates _EXTRA_ROOTS behind current_source_roots(), gives spawned local tuning replicas defensive spawn-boundary parity with rank_group._peer, and adds real-spawn CPU regression coverage for both current_source_roots() and tuning_replicas.prepare_recipe.
  • No model core format, Helios ABI, or single-GPU preparation behavior changes are introduced.

Supporting evidence and limitations

  • CPU validation (CUDA_VISIBLE_DEVICES=""): py_compile clean across all five modified Python files; git diff --check clean; git grep _EXTRA_ROOTS confirms zero references outside ignition/preparation/source_identity.py.
  • pytest -v tests/preparation/test_forward_cache_sources.py tests/preparation/test_forward_cache_concurrency.py tests/preparation/test_forward_cache_root.py tests/preparation/test_core_boundary.py tests/preparation/test_native_processes.py tests/preparation/test_tuning_shards.py tests/cli/test_recipe_injection.py: 36 passed, 0 failed, 0 skipped.
  • Limitations: the tuning-replica CPU test stubs torch.cuda.set_device, torch.cuda.synchronize, and CoreStorage while exercising real multiprocessing.get_context("spawn") serialization and source_roots rebinding; multi-GPU CUDA tuning-replica runs were not executed on CPU.

Discord: Brandonmusic

@flare-autobot

Copy link
Copy Markdown
Collaborator

A case file has been opened for 678.
Case File Intake Report

Future reviews will auto-run 90 minutes after code updates are pushed.

  • Re-review sooner: Call @flare-autobot after push.
  • Opt-out: Include #autobot:ignore in the PR or any comment.

@flare-autobot flare-autobot added area:preparation Ignition checkpoint loading, tuning, compilation, capture, and export. bug Something isn't working duplicate This issue or pull request already exists priority:P2 Normal bug priority: workflow failure or diagnosis with narrower impact or an available workaround. triage:review Proposed change needs code review; this does not imply merge readiness. labels Dec 2, 2026
@flare-autobot

Copy link
Copy Markdown
Collaborator

Autobot Review

Full Review · Value Proposition · Case File

Recommendation: Changes Requested

The spawn-boundary ContextVar propagation is sound and low-risk, but the PR description misstates the main failure mode (cites unmerged #597 while omitting #597/#670 context), the new peer spawn test never asserts ForwardCache.root/source_identity() agreement, and wrapping all of _peer creates avoidable conflict surface with #670 and #664.

  • Blockers: 0 · Should fix: 2 · Subtract/Simplify: 2 · Nits: 3
Walkthrough
  • ignition/preparation/source_identity.py:17-19: Adds current_source_roots() -> tuple[tuple[str, Path], ...] returning _EXTRA_ROOTS.get().
  • ignition/preparation/rank_group.py:44-45,53,59-143,295-312: Captures extra_source_roots = current_source_roots() in prepare_group, passes it as the trailing extra_source_roots=() argument to spawned _peer processes, and wraps _peer's body in with source_roots(extra_source_roots):.
  • ignition/preparation/tuning_replicas.py:142,145,158-165,174-176,190-194: Captures extra_source_roots = current_source_roots() in prepare_recipe, passes it as the trailing extra_source_roots=() argument to spawned _replica workers, and enters with source_roots(extra_source_roots), CoreStorage(...) as storage: before calling prepare(...).
  • tests/preparation/test_forward_cache_sources.py:71-189: Adds three CPU tests covering current_source_roots() nesting/reset, real-spawn propagation through rank_group.prepare_group over loopback Gloo, and real-spawn propagation through tuning_replicas.prepare_recipe (with CUDA/CoreStorage stubbed in the child).
Merge Risk: Low · up to e72ec0d
Pre-merge checks: ✅ 1 passed · ⚠️ 3 warnings

Have your agent review the Full Review for complete verified findings, file:line citations, and suggested changes.

To opt out, include #autobot:ignore in your post or comment.

… to tuning replicas

Commit 2acc3f3 (NVIDIA#670) propagated bound external recipe `source_roots` across
`mp.get_context("spawn")` in `ignition.preparation.rank_group`, reading private
`_EXTRA_ROOTS.get()` directly in `rank_group.py` (matching `aot.py`). Two gaps
remain on `main`:
1. `ignition/preparation/aot.py` and `ignition/preparation/rank_group.py` import
   private `_EXTRA_ROOTS` directly from `source_identity.py` instead of calling
   a public accessor.
2. `ignition/preparation/tuning_replicas.py` spawns local tuning replicas via
   `mp.get_context("spawn")` without propagating bound `source_roots`. Although
   `_replica` currently calls `prepare(..., compile_forwards=False)` and exits
   on `TuningComplete` without reaching an in-tree `ForwardCache` or
   `source_identity()` call today, binding `source_roots` in `_replica` gives
   local spawned tuning workers the same context invariant as `rank_group._peer`
   if a recipe or future preparation path inspects bound source roots during
   tuning.

Before this change, `aot.py` and `rank_group.py` imported `_EXTRA_ROOTS`
directly, `source_identity.py` had no public accessor for the active
`ContextVar`, and `tuning_replicas._replica` ran with an empty `source_roots`
context. After this change:
- `ignition/preparation/source_identity.py` adds `current_source_roots() ->
  tuple[tuple[str, Path], ...]` returning `_EXTRA_ROOTS.get()`, and updates
  `source_roots`'s docstring to cover active CLI and spawned worker contexts.
- `ignition/preparation/aot.py` and `ignition/preparation/rank_group.py` call
  `current_source_roots()` so `_EXTRA_ROOTS` stays private to
  `source_identity.py` (keeping `NVIDIA#670`'s narrow `with bind_source_roots(...)`
  scope in `rank_group._peer` untouched).
- `ignition/preparation/tuning_replicas.py` captures `current_source_roots()` in
  `prepare_recipe`, passes `extra_source_roots` as a required argument to
  `_replica`, and binds `with source_roots(extra_source_roots), CoreStorage(...)`
  around replica preparation.
- `tests/preparation/test_forward_cache_sources.py` switches
  `_record_source_roots_prepare` to `current_source_roots()`, adds
  `test_current_source_roots_reflects_active_scope`, and adds
  `test_prepare_recipe_propagates_source_roots_to_spawned_tuning_replica`
  asserting both `current_source_roots()` and `ForwardCache.root` agreement
  between replica 0 and spawned replica 1 against the unbound baseline.

Claimed result: keeps `_EXTRA_ROOTS` encapsulated behind
`current_source_roots()`, brings spawned local tuning replicas to spawn-boundary
parity with `rank_group._peer`, and adds real-spawn CPU regression coverage for
both helpers. No model core format, Helios ABI, or single-GPU preparation
behavior changes are introduced.

Validation and limitations (CPU, `CUDA_VISIBLE_DEVICES=""`):
- `py_compile` clean across all five modified Python files; `git diff --check`
  clean; `git grep _EXTRA_ROOTS` confirms zero references outside
  `ignition/preparation/source_identity.py`.
- `pytest -v tests/preparation/test_forward_cache_sources.py
  tests/preparation/test_forward_cache_concurrency.py
  tests/preparation/test_forward_cache_root.py
  tests/preparation/test_core_boundary.py
  tests/preparation/test_native_processes.py
  tests/preparation/test_tuning_shards.py
  tests/cli/test_recipe_injection.py`: 36 passed, 0 failed, 0 skipped.
- Limitations: the tuning-replica CPU test stubs `torch.cuda.set_device`,
  `torch.cuda.synchronize`, and `CoreStorage` while exercising real
  `multiprocessing.get_context("spawn")` serialization and `source_roots`
  rebinding; multi-GPU CUDA tuning-replica runs were not executed on CPU.

Design-Signed-Off-By: Brandon M. Music; design-review=2e5b
Signed-off-by: Brandon M. Music <266531604+brandonmmusic-max@users.noreply.github.com>
@brandonmmusic-max
brandonmmusic-max force-pushed the fix/spawn-propagate-source-roots branch from e72ec0d to 90b0d31 Compare December 2, 2026 21:29
@brandonmmusic-max brandonmmusic-max changed the title fix(ignition): propagate bound source roots to spawned rank and replica processes fix(ignition): expose current_source_roots and propagate source roots to tuning replicas Dec 2, 2026
@brandonmmusic-max

Copy link
Copy Markdown
Contributor Author

Rebased onto main (cc0a49d2, which includes merged #670) and addressed all Autobot review findings:

Validated with 36 passed, 0 failed across the 7 CPU test suites. @flare-autobot please re-review.

@flare-autobot

Copy link
Copy Markdown
Collaborator

Autobot Review

Full Review · Value Proposition · Case File

Recommendation: Ready To Merge

Rebased onto main (cc0a49d2, including merged #670), this PR cleanly resolves every Round 1 item: _EXTRA_ROOTS is encapsulated behind current_source_roots(), #670's narrow bind in rank_group._peer is preserved, and the CPU spawn tests assert real ForwardCache.root agreement. No correctness, safety, concurrency, or regression issues remain at 90b0d31; merge once the Python CPU tests workflow is green and the stale duplicate label is cleared.

  • Blockers: 0 · Should fix: 0 · Subtract/Simplify: 1 · Nits: 2
Walkthrough
  • ignition/preparation/source_identity.py:17-24: Adds public current_source_roots() -> tuple[tuple[str, Path], ...] returning _EXTRA_ROOTS.get() (mirroring ignition/registry.py's current_recipes()/current_prog() pattern) and updates source_roots's docstring for active CLI and spawned worker contexts.
  • ignition/preparation/aot.py:845-847 and ignition/preparation/rank_group.py:295-297: Replaces direct private _EXTRA_ROOTS imports with current_source_roots(), leaving _EXTRA_ROOTS referenced solely inside ignition/preparation/source_identity.py and preserving feat(helios,ignition): parameterize THINK_TAGS reasoning, add TAGGED_JSON tool parser, and propagate peer source roots #670's narrow with bind_source_roots(extra_roots): block in rank_group._peer.
  • ignition/preparation/tuning_replicas.py:142,153,158,174-176,190-194: Captures extra_source_roots = current_source_roots() in prepare_recipe, passes it as a required positional argument to _replica, and binds with source_roots(extra_source_roots), CoreStorage(world=plan.world_size) as storage: around replica prepare(...).
  • tests/preparation/test_forward_cache_sources.py:35-48,151-245: Extracts _stub_forward_cache_root() using pytest.MonkeyPatch.context(), migrates _record_source_roots_prepare to current_source_roots(), adds test_current_source_roots_reflects_active_scope covering nesting/reset, and adds Linux/Heliopause-gated test_prepare_recipe_propagates_source_roots_to_spawned_tuning_replica verifying real-spawn propagation and ForwardCache.root agreement against the unbound baseline.
Merge Risk: Low · up to 90b0d31
Pre-merge checks: ✅ 3 passed · ⚠️ 1 warning
  • ✅ Security / malicious screen: No unsafe deserialization, command execution, credential exposure, or prompt-injection content; only picklable (str, Path) tuples cross mp.get_context("spawn").
  • ✅ Charter & value fit: Right layer, clean encapsulation matching ignition/registry.py, no flags or model/recipe coupling, and complete four-part PR description with honest disclosure of defensive scope and CPU-test limitations (AGENTS.md:72-154, docs/design-review.md Principles 16–17).
  • ✅ Related / duplicate / conflict check: Properly rebased onto merged feat(helios,ignition): parameterize THINK_TAGS reasoning, add TAGGED_JSON tool parser, and propagate peer source roots #670 (cc0a49d2); edits in tuning_replicas.py:142-194 do not overlap PR Share local tuning across TP ranks in tuning replicas and reconcile serving selections #695's authorization()/ReplicaPreparation changes. The existing duplicate triage label is now stale and can be removed.
  • ⚠️ Tests & verification evidence: Author reports 36/36 CPU tests passing across 7 suites (with CUDA/CoreStorage stubbed inside the spawned replica test), but no GitHub Actions CI run is recorded on head 90b0d31 yet—confirm .github/workflows/python-cpu.yml passes before merging.

Have your agent review the Full Review for complete verified findings, file:line citations, and suggested changes.

To opt out, include #autobot:ignore in your post or comment.

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

Labels

area:preparation Ignition checkpoint loading, tuning, compilation, capture, and export. bug Something isn't working duplicate This issue or pull request already exists priority:P2 Normal bug priority: workflow failure or diagnosis with narrower impact or an available workaround. triage:review Proposed change needs code review; this does not imply merge readiness.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants