From e1115082dee224d21830da2a120ba451d85da585 Mon Sep 17 00:00:00 2001 From: Nicholas Pavez Date: Tue, 6 Oct 2026 22:14:38 -0700 Subject: [PATCH] Add threshold robustness sweep Sweep each threshold on its own and report the band where every verdict matches the default run, plus what changes just outside it. The stage threshold is the narrow one (1.06 to 1.20). Both edges fail safe, and no setting tested replaces or pulls a healthy node. Bands on synthetic history are labeled as such. Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 2 + README.md | 25 +++++- docs/design.md | 4 + examples/robustness.txt | 24 ++++++ src/node_verdict/cli.py | 27 +++++- src/node_verdict/report.py | 18 ++++ src/node_verdict/robustness.py | 153 +++++++++++++++++++++++++++++++++ tests/test_robustness.py | 41 +++++++++ 8 files changed, 291 insertions(+), 3 deletions(-) create mode 100644 examples/robustness.txt create mode 100644 src/node_verdict/robustness.py create mode 100644 tests/test_robustness.py diff --git a/CLAUDE.md b/CLAUDE.md index 3bd3c97..e6c5b55 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -14,6 +14,7 @@ pytest -q python -m node_verdict demo python -m node_verdict verdicts # add --json, or --no-history python -m node_verdict simulate --sensitivity +python -m node_verdict robustness # threshold sweep # Rebuild data/derived/ from ByteDance's artifact (needs pyarrow) git clone https://github.com/ByteDance-Seed/StragglerAnalysis @@ -33,6 +34,7 @@ Evidence goes in, a verdict comes out, policy turns the verdict into an action. - `conditions.py`: Kubernetes-style node conditions. The four reason codes are a pinned API. - `policy.py`: actions are editable config. A fleet cap and a correlation guard sit on top. - `scenario.py`: the 32-node demo. Real timing, synthetic node history. +- `robustness.py`: sweeps each threshold and reports where verdicts change. - `simulator.py`: compares naive, naive+checkpoint, peer-aware, and attributed repair. Things that are easy to get wrong: diff --git a/README.md b/README.md index 3ff9947..6022f2f 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,7 @@ python -m node_verdict verdicts # verdict table python -m node_verdict verdicts --json # node conditions as JSON python -m node_verdict verdicts --no-history # what changes without cross-job history python -m node_verdict simulate --sensitivity +python -m node_verdict robustness # where each threshold flips a verdict pytest ``` @@ -189,6 +190,25 @@ every 200 steps +9.2 pts +0.2 pts -0.2 pts - What attribution adds over a good detector does not depend on my assumptions. It pulls the corrupting chip, which timing alone cannot see. It gives every slow job an owner (3 of 3, against 1 of 3), so the two customers whose jobs are the problem are told so. And it will not replace a node on one job of evidence (see the no-history run, where N00 drops to `Watch`). - In a supply-limited cloud, spares are the constraint. Attribution spends one more spare than peer-aware, on purpose, to pull a chip that would otherwise keep corrupting training runs. +## How fragile are the thresholds? + +I set the thresholds by hand on three traces, and the public artifact has no held-out data. So I checked the next best thing: sweep each threshold on its own and find the band where every verdict stays the same (`python -m node_verdict robustness`). + +``` +threshold default verdicts unchanged range tested tested against +--------------- ------- ------------------ ------------ ----------------- +peer_threshold 1.15 1.02 to 2.32 1.02 to 2.50 real timing +persistence_min 0.80 0.05 to 1.00 0.05 to 1.00 real timing +stage_threshold 1.15 1.06 to 1.20 1.00 to 1.80 real timing +lemon_min_score 4 1 to 10 1 to 12 synthetic history +lemon_min_jobs 2 1 to 5 1 to 6 synthetic history +sdc_min_jobs 2 1 to 4 1 to 6 synthetic history +``` + +The stage threshold is the one that matters. Below 1.06, job-a's last stage (1.04x the job median) gets blamed on the customer's job. Above 1.20, job-c's slow stage (1.20x) is no longer explained. Both failures are safe: neither changes a node. At no setting tested does a healthy node get replaced or pulled. + +This does not validate the thresholds for a real fleet. The peer threshold looks robust only because the planted slow worker runs 2.35x its peers. A degraded node in production may run 1.1x, which is where this threshold would actually be tested. The bands on history only show that the planted history is not borderline. + ## Data: real and synthetic | Input | Status | @@ -203,7 +223,7 @@ every 200 steps +9.2 pts +0.2 pts -0.2 pts ## Limits -1. **Three traces.** I set the thresholds by hand and checked them on these three jobs only. They are not validated on held-out data. Treat them as starting points. +1. **Three traces.** I set the thresholds by hand and checked them on these three jobs only. They are not validated on held-out data. The robustness sweep shows they are not on a knife edge, not that they are right. Treat them as starting points. 2. **History is synthetic.** The signal types follow what Meta reports (jobs that excluded a node, repair tickets, multi-node failures). The weights are illustrative. This is not Meta's model. 3. **The data may not carry over.** ByteDance ran a dedicated cluster with plenty of network capacity. A shared cloud may see more node problems than workload problems. 4. **Monitoring costs something.** I did not measure overhead. AWS found its own health agent slowed training jobs. I treat under 1% as a budget (ByteDance reports 0.86% for online corruption detection). That is a target here, not a result. @@ -231,7 +251,8 @@ src/node_verdict/ conditions.py node conditions and the reason-code contract policy.py actions and guards scenario.py the 32-node demo pool - simulator.py naive vs attributed + simulator.py naive, peer-aware and attributed repair + robustness.py threshold sweep data/derived/ small tables derived from the ByteDance traces scripts/ rebuild the derived tables tests/ unit and scenario tests, including the pinned reason codes diff --git a/docs/design.md b/docs/design.md index c941198..3603933 100644 --- a/docs/design.md +++ b/docs/design.md @@ -36,6 +36,10 @@ Rules run in a fixed order and the first match wins for a node. The 1.15 threshold applies to both the peer comparison and the stage comparison. Defaults live in `AttributionConfig`. +### Robustness + +`robustness.py` sweeps each threshold on its own and reports the band where every verdict matches the default run. The stage threshold is the narrow one: 1.06 to 1.20. Below that band a healthy stage gets a workload verdict. Above it a slow stage goes unexplained. Neither side changes a node, and no setting on any grid replaces or pulls a healthy node. This is a check against overfitting the demo, not a validation on held-out data. + ### Why stage peers Pipeline stages do different amounts of work. In the ST trace, stage 3 runs about 1.6x longer than the others on every replica. Compare each rank to the whole job and you flag both stage 3 nodes. Compare to stage peers and neither is an outlier, which is correct: the stage is slow, not the nodes. diff --git a/examples/robustness.txt b/examples/robustness.txt new file mode 100644 index 0000000..4547eaf --- /dev/null +++ b/examples/robustness.txt @@ -0,0 +1,24 @@ +Each threshold swept on its own, the rest at defaults. A band is where every verdict matches the default run. + +threshold default verdicts unchanged range tested tested against +--------------- ------- ------------------ ------------ ----------------- +peer_threshold 1.15 1.02 to 2.32 1.02 to 2.50 real timing +persistence_min 0.80 0.05 to 1.00 0.05 to 1.00 real timing +stage_threshold 1.15 1.06 to 1.20 1.00 to 1.80 real timing +lemon_min_score 4 1 to 10 1 to 12 synthetic history +lemon_min_jobs 2 1 to 5 1 to 6 synthetic history +sdc_min_jobs 2 1 to 4 1 to 6 synthetic history + +Just outside each band: + +peer_threshold above 2.32: N00 loses NodeLemon. +stage_threshold below 1.06: N12 to N15 gain WorkloadImbalance. +stage_threshold above 1.20: N28 to N31 lose WorkloadImbalance. +lemon_min_score above 10: N00 NodeLemon to NodeSuspect. +lemon_min_jobs above 5: N00 NodeLemon to NodeSuspect. +sdc_min_jobs above 4: N27 loses SDCSuspect. + +Healthy nodes that would be replaced or pulled at any setting tested: 0. + +A wide band means the demo is not on a knife edge. It does not validate the thresholds for a real fleet. +The planted slow worker runs 2.35x its peers, so any peer threshold below that catches it. Bands on synthetic history only show the planted history is not borderline. diff --git a/src/node_verdict/cli.py b/src/node_verdict/cli.py index 84065cc..ef6b9f1 100644 --- a/src/node_verdict/cli.py +++ b/src/node_verdict/cli.py @@ -9,7 +9,15 @@ from .attribution import AttributionConfig from .engine import run_engine from .policy import PolicyConfig, plan -from .report import action_table, comparison_table, sensitivity_table, verdict_table +from .report import ( + action_table, + comparison_table, + robustness_edges, + robustness_table, + sensitivity_table, + verdict_table, +) +from .robustness import all_bands, healthy_nodes_ever_changed from .scenario import BAD_NODE, DEFAULT_SPARES, SDC_NODE, build_scenario from .simulator import SimParams, compare, sensitivity @@ -39,6 +47,20 @@ def cmd_simulate(args) -> None: print(sensitivity_table(sensitivity(scenario, restart_steps=args.restart))) +def cmd_robustness(args) -> None: + bands = all_bands() + print("Each threshold swept on its own, the rest at defaults. A band is where every verdict matches the default run.\n") + print(robustness_table(bands)) + print("\nJust outside each band:\n") + print(robustness_edges(bands)) + changed = healthy_nodes_ever_changed() + worst = sum(len(v) for v in changed.values()) + print(f"\nHealthy nodes that would be replaced or pulled at any setting tested: {worst}.") + print("\nA wide band means the demo is not on a knife edge. It does not validate the thresholds for a real fleet.") + print("The planted slow worker runs 2.35x its peers, so any peer threshold below that catches it. " + "Bands on synthetic history only show the planted history is not borderline.") + + def cmd_demo(args) -> None: scenario = build_scenario(args.spares) conditions = _conditions(scenario, no_history=False) @@ -99,6 +121,9 @@ def main(argv: list[str] | None = None) -> int: p.add_argument("--sensitivity", action="store_true") p.set_defaults(func=cmd_simulate) + p = sub.add_parser("robustness", help="sweep each threshold and show where verdicts change") + p.set_defaults(func=cmd_robustness) + args = parser.parse_args(argv) args.func(args) return 0 diff --git a/src/node_verdict/report.py b/src/node_verdict/report.py index ead8b3c..e40eb88 100644 --- a/src/node_verdict/report.py +++ b/src/node_verdict/report.py @@ -50,6 +50,24 @@ def row(label: str, fn) -> list[str]: return table(["metric"] + [r.name for r in results], rows) +def robustness_table(bands) -> str: + rows = [ + [b.param, b.fmt(b.default), f"{b.fmt(b.low)} to {b.fmt(b.high)}", f"{b.fmt(b.grid_min)} to {b.fmt(b.grid_max)}", b.basis] + for b in bands + ] + return table(["threshold", "default", "verdicts unchanged", "range tested", "tested against"], rows) + + +def robustness_edges(bands) -> str: + lines = [] + for b in bands: + if b.below: + lines.append(f"{b.param} below {b.fmt(b.low)}: {b.below}.") + if b.above: + lines.append(f"{b.param} above {b.fmt(b.high)}: {b.above}.") + return "\n".join(lines) + + def sensitivity_table(rows: list[tuple[int, float, float, float]]) -> str: body = [[f"every {c} steps", f"{a:+.1f} pts", f"{b:+.1f} pts", f"{c2:+.1f} pts"] for c, a, b, c2 in rows] return table(["checkpoint interval", "vs naive", "vs naive+checkpoint", "vs peer-aware"], body) diff --git a/src/node_verdict/robustness.py b/src/node_verdict/robustness.py new file mode 100644 index 0000000..087d754 --- /dev/null +++ b/src/node_verdict/robustness.py @@ -0,0 +1,153 @@ +"""Threshold robustness: how far can each threshold move before a verdict changes? + +The thresholds were set by hand on three traces, and the public artifact has +no held-out data to validate them. This is the next best check. Sweep each +threshold on its own, keep the rest at their defaults, and report the band +where every verdict matches the default run, plus what changes just outside. + +A wide band says the demo is not balanced on a knife edge. It does not say the +thresholds are right for a real fleet. The planted slow worker runs 2.35x its +peers, far above any sensible threshold. A degraded node in production may run +1.1x. +""" +from __future__ import annotations + +from dataclasses import dataclass, replace + +from .attribution import AttributionConfig +from .engine import run_engine +from .scenario import Scenario, build_scenario + +# The peer threshold also decides persistence and the history written for the +# current jobs, so changing it means rebuilding the scenario. +REBUILD = {"peer_threshold"} + +GRIDS: dict[str, list[float]] = { + "peer_threshold": [round(1.02 + 0.02 * i, 2) for i in range(75)], # 1.02 to 2.50 + "persistence_min": [round(0.05 * i, 2) for i in range(1, 21)], # 0.05 to 1.00 + "stage_threshold": [round(1.00 + 0.02 * i, 2) for i in range(41)], # 1.00 to 1.80 + "lemon_min_score": [float(x) for x in range(1, 13)], + "lemon_min_jobs": [float(x) for x in range(1, 7)], + "sdc_min_jobs": [float(x) for x in range(1, 7)], +} + +INT_PARAMS = {"lemon_min_jobs", "sdc_min_jobs"} + +# What each threshold is tested against. Bands on synthetic history only show +# that the planted history is not borderline. They say nothing about real fleets. +BASIS = { + "peer_threshold": "real timing", + "persistence_min": "real timing", + "stage_threshold": "real timing", + "lemon_min_score": "synthetic history", + "lemon_min_jobs": "synthetic history", + "sdc_min_jobs": "synthetic history", +} + +NODE_CHANGING_REASONS = {"NodeLemon", "SDCSuspect"} + + +@dataclass(frozen=True) +class Band: + param: str + default: float + low: float # lowest grid value with the same verdicts as the default, contiguous with it + high: float + grid_min: float + grid_max: float + below: str # what changes just under the band, or "" if the band reaches the grid edge + above: str + + @property + def basis(self) -> str: + return BASIS[self.param] + + def fmt(self, x: float) -> str: + return f"{x:g}" if self.param in INT_PARAMS or self.param == "lemon_min_score" else f"{x:.2f}" + + +def verdicts(scenario: Scenario, cfg: AttributionConfig) -> dict[str, str]: + return {c.node: c.reason.value for c in run_engine(scenario, cfg)} + + +def _cfg(param: str, value: float, base: AttributionConfig) -> AttributionConfig: + return replace(base, **{param: int(value) if param in INT_PARAMS else value}) + + +def _nodes(names: list[str]) -> str: + return names[0] if len(names) == 1 else f"{names[0]} to {names[-1]}" if len(names) > 2 else " and ".join(names) + + +def _describe(ref: dict[str, str], got: dict[str, str]) -> str: + """Plain words for how a verdict map differs from the default, with nodes grouped by change.""" + changes: dict[str, list[str]] = {} + for node in sorted(set(ref) | set(got)): + a, b = ref.get(node), got.get(node) + if a == b: + continue + if a is None: + what = ("gain", b) + elif b is None: + what = ("lose", a) + else: + what = ("", f"{a} to {b}") + changes.setdefault(what, []).append(node) + + def phrase(verb: str, rest: str, n: int) -> str: + return f"{verb}{'s' if verb and n == 1 else ''} {rest}".strip() + + return "; ".join(f"{_nodes(nodes)} {phrase(v, r, len(nodes))}" for (v, r), nodes in changes.items()) + + +def sweep(param: str, values: list[float], base: AttributionConfig = AttributionConfig()) -> list[tuple[float, dict[str, str]]]: + scenario = None if param in REBUILD else build_scenario(cfg=base) + out = [] + for v in values: + cfg = _cfg(param, v, base) + s = build_scenario(cfg=cfg) if param in REBUILD else scenario + out.append((v, verdicts(s, cfg))) + return out + + +def band(param: str, values: list[float] | None = None, base: AttributionConfig = AttributionConfig()) -> Band: + values = values if values is not None else GRIDS[param] + default = float(getattr(base, param)) + ref = verdicts(build_scenario(cfg=base), base) + rows = sweep(param, values, base) + same = [v == ref for _, v in rows] + + # Start from the grid point nearest the default and grow outward while verdicts match. + start = min(range(len(rows)), key=lambda i: abs(rows[i][0] - default)) + if not same[start]: + raise ValueError(f"{param}: the grid point nearest the default does not reproduce the default verdicts") + lo = start + while lo > 0 and same[lo - 1]: + lo -= 1 + hi = start + while hi < len(rows) - 1 and same[hi + 1]: + hi += 1 + + below = _describe(ref, rows[lo - 1][1]) if lo > 0 else "" + above = _describe(ref, rows[hi + 1][1]) if hi < len(rows) - 1 else "" + return Band(param, default, rows[lo][0], rows[hi][0], values[0], values[-1], below, above) + + +def all_bands(base: AttributionConfig = AttributionConfig()) -> list[Band]: + return [band(p, base=base) for p in GRIDS] + + +def healthy_nodes_ever_changed(base: AttributionConfig = AttributionConfig()) -> dict[str, list[tuple[float, str]]]: + """For every grid point of every threshold: healthy nodes that would get a node-changing verdict. + + Empty lists mean no threshold setting on the grid would replace or pull a healthy node. + """ + truth = build_scenario(cfg=base).truth + out: dict[str, list[tuple[float, str]]] = {} + for param, values in GRIDS.items(): + out[param] = [ + (v, node) + for v, got in sweep(param, values, base) + for node, reason in got.items() + if reason in NODE_CHANGING_REASONS and node not in truth + ] + return out diff --git a/tests/test_robustness.py b/tests/test_robustness.py new file mode 100644 index 0000000..13ebcf8 --- /dev/null +++ b/tests/test_robustness.py @@ -0,0 +1,41 @@ +import pytest + +from node_verdict.robustness import band, healthy_nodes_ever_changed + + +@pytest.fixture(scope="module") +def stage(): + return band("stage_threshold") + + +def test_default_stage_threshold_sits_inside_its_stable_band(stage): + assert stage.low <= 1.15 <= stage.high + assert (stage.low, stage.high) == (1.06, 1.20) + + +def test_stage_threshold_fails_safe_on_both_sides(stage): + # Too low: job-a's healthy stage 3 (1.04x the job median) gets blamed on the job. + assert "N12 to N15 gain WorkloadImbalance" in stage.below + # Too high: job-c's slow stage (1.20x) is no longer explained. It gets no condition, not a node fault. + assert "N28 to N31 lose WorkloadImbalance" in stage.above + + +def test_peer_threshold_covers_the_range_the_handoff_asked_for(): + b = band("peer_threshold") + assert b.low <= 1.10 and b.high >= 1.25 + assert b.above == "N00 loses NodeLemon" # only once the threshold passes the planted 2.35x + + +def test_persistence_requirement_does_not_move_any_verdict(): + b = band("persistence_min") + assert (b.low, b.high) == (b.grid_min, b.grid_max) + + +def test_no_threshold_setting_replaces_or_pulls_a_healthy_node(): + changed = healthy_nodes_ever_changed() + assert all(v == [] for v in changed.values()), changed + + +def test_band_rejects_a_grid_that_misses_the_default(): + with pytest.raises(ValueError, match="nearest the default"): + band("stage_threshold", values=[1.60, 1.70])