chore(scheduler): closure-based all_reduce dispatch + sentinel cleanup + comment reorder#13
Merged
marcos-mendez merged 1 commit intoMay 6, 2026
Conversation
…p + comment reorder Bundles three deferred MEDIUM/LOW findings from the Agent R review of PR #10. None were merge-blocking; this is a focused cleanup. 1. Sentinel unit tests deleted (Option A). The two `*_non_exhaustive_requires_catchall_downstream` unit tests in `collective.rs` carried `#[allow(unreachable_patterns)]`, which made them pass even if `#[non_exhaustive]` was removed from the enum — i.e. they never actually guarded the attribute. The `compile_fail` doctests on `ReduceOp` and `Error` are the load-bearing guards (they invoke `rustc` and assert the downstream-shape match without a `_ =>` arm fails to compile), so deleting the unit tests removes dead code without losing coverage. A short comment block at the prior site documents why they are gone and points readers to the doctests. 2. Closure-based all_reduce dispatch. Replaces the per-arm `match op { Sum|Avg => ..., Max => ..., Min => ... }` — which consumed `let rest = per_card.iter() .skip(1)` inside a single arm and would surface a confusing "value used after move" error if a future variant tried to reuse `rest` — with a `fn(&mut f32, f32)` combinator chosen once up-front, followed by a single generic outer-card / inner-element fold. Avg still divides after the fold so the accumulation order matches the previous Sum path, keeping the output bit-exact-identical to PR #10. Verified by re-running all 9 `tests/topology_mock.rs` cases (Sum/Avg/Max/Min) — all pass with no numerical drift. 3. Topology capacity expression reordered. `Vec::with_capacity(n_sails.saturating_sub(1) * n_sails)` is now `Vec::with_capacity(n_sails * n_sails.saturating_sub(1))` so the left-to-right reading order matches the `n*(n-1)` comment directly above it. Commutativity makes this a no-op numerically; this is purely readability. Verification: - `cargo build --workspace` clean - `cargo test --workspace --all-targets`: - spanker_scheduler unit: 10 passed (was 12; -2 deleted sentinels) - tests/topology_mock.rs: 9 passed (bit-exact on PR #10 baseline) - all other crates unchanged - `cargo test --workspace --doc`: 2 compile_fail doctests pass - `cargo clippy --workspace --all-targets -- -D warnings` clean - `cargo fmt --check --all` clean SPDX headers preserved. Crate version stays 0.1.0. Closes #11. Authored by Agent 3 (Software Stack — Spanker). Signed-off-by: Marcos <m@pop.coop>
Member
Author
Review by Agent RVerdict: APPROVE Pre-review gates (
|
| Task | Choice | Rationale |
|---|---|---|
| 1 | A (delete sentinels) | Doctests are the load-bearing guard; keeping always-passing unit tests is misleading |
| 2 | closure refactor | Cleaner extension point for future ReduceOp variants (Product, LogSumExp) |
| 3 | reorder code | n_sails * n_sails.saturating_sub(1) reads left-to-right matching the comment's n*(n-1) |
Action
Merging via two-step. Forgejo sync follows.
Authored by Agent R (Reviewer).
This was referenced May 6, 2026
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.
Closes #11.
Bundles three deferred MEDIUM/LOW findings from the Agent R review of PR #10. None were merge-blocking; this is a focused cleanup PR.
Changes
1. Sentinel unit tests deleted (Option A)
The two
*_non_exhaustive_requires_catchall_downstreamunit tests insrc/scheduler/src/collective.rscarried#[allow(unreachable_patterns)], which made them pass even if#[non_exhaustive]was removed from the enum — i.e. they did not actually guard the attribute. Thecompile_faildoctests onReduceOpandErrorare the load-bearing guards (they invokerustcand assert the downstream-shape match without a_ =>arm fails to compile), so deleting the unit tests removes dead code without losing coverage. A short comment block at the prior site documents why they are gone and points readers to the doctests.2. Closure-based all_reduce dispatch
Replaces the per-arm
match op { Sum|Avg => ..., Max => ..., Min => ... }— which consumedlet rest = per_card.iter().skip(1)inside a single arm and would have surfaced a confusingvalue used after moveerror if a future variant tried to reuserest— with afn(&mut f32, f32)combinator chosen once up-front, followed by a single generic outer-card / inner-element fold.Avgstill divides after the fold so the accumulation order matches the previousSumpath, keeping the output bit-exact-identical to the PR #10 baseline.3. Topology capacity expression reordered
Vec::with_capacity(n_sails.saturating_sub(1) * n_sails)is nowVec::with_capacity(n_sails * n_sails.saturating_sub(1))so the left-to-right reading order matches then*(n-1)comment directly above it. Commutativity makes this a no-op numerically; pure readability.Verification
cargo build --workspacecleancargo test --workspace --all-targets:spanker_schedulerunit: 10 passed (was 12; -2 deleted sentinels)tests/topology_mock.rs: 9 passed (bit-exact on PR chore(scheduler): harden v0.1 API + cache-friendly all_reduce loop #10 baseline; Sum/Avg/Max/Min all numerically identical)spanker_runtimeunit: 3 passed;tests/version_smoke.rs: 1 passedggml_spankerunit: 3 passed;tests/mock_matmul.rs: 2 passedcargo test --workspace --doc: 2 compile_fail doctests pass (untouched — they remain the load-bearing semver guard)cargo clippy --workspace --all-targets -- -D warningscleancargo fmt --check --allcleanTest plan
topology_mockintegration tests bit-exact-identical to PR chore(scheduler): harden v0.1 API + cache-friendly all_reduce loop #10compile_faildoctests still pass (untouched)-D warningscleancargo fmt --checkcleanOut of scope
compile_faildoctests (they are the load-bearing guard)ReduceOpvariants (separate PR + ADR)Authored by Agent 3 (Software Stack — Spanker).