Skip to content

Commit f2de5a7

Browse files
physicsrobclaude
andcommitted
Reformat with black 26.3.1
Mechanical: the unpinned dev-group black moved to 26.x, which formats differently than the committed baseline; make lint's black step is green again. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent f3d952c commit f2de5a7

29 files changed

Lines changed: 328 additions & 163 deletions

scripts/dump_measure_noise.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,27 @@
55
66
make modal-run MODULE=scripts.dump_measure_noise > docs/op_noise_data.json
77
"""
8+
89
import sys
910
from pathlib import Path
1011

1112
from scripts.measure_op_noise import _measure_all, render_json
12-
from torchwright.compiler.forward.compile import forward_compile # noqa: F401 pre-import
13+
from torchwright.compiler.forward.compile import (
14+
forward_compile,
15+
) # noqa: F401 pre-import
1316

1417

1518
def main():
1619
measurements = _measure_all()
1720
# Get commit SHA from env or fallback
1821
import subprocess
22+
1923
try:
2024
sha = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode().strip()
2125
except Exception:
2226
sha = "unknown"
2327
import datetime
28+
2429
now = datetime.datetime.utcnow().isoformat() + "Z"
2530
json_text = render_json(measurements, commit=sha, measured_at=now)
2631
# Print a separator so we can grep out the real JSON block

scripts/validate_multiply_2d_build_cost.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ def main() -> None:
4444
b = create_input("b", 1)
4545
tracemalloc.start()
4646
t0 = time.perf_counter()
47-
node = multiply_2d(
48-
a, b, max_abs1=max_abs, max_abs2=max_abs, step1=step, step2=step
49-
)
47+
node = multiply_2d(a, b, max_abs1=max_abs, max_abs2=max_abs, step1=step, step2=step)
5048
elapsed = time.perf_counter() - t0
5149
_cur, peak = tracemalloc.get_traced_memory()
5250
tracemalloc.stop()

tests/compile/forward/test_cpsat_knobs.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -650,9 +650,7 @@ def schedule_layer(self, *args, **kwargs):
650650
assert list(tmp_path.glob("*.json")) == []
651651

652652

653-
def test_schedule_cache_stores_once_after_replay_and_not_on_hit(
654-
tmp_path, monkeypatch
655-
):
653+
def test_schedule_cache_stores_once_after_replay_and_not_on_hit(tmp_path, monkeypatch):
656654
"""The positive mirror: a successful non-cached solve stores exactly once
657655
(after replay), and a cache hit does not store again."""
658656
from torchwright.compiler.forward import compile as compile_mod

tests/compile/forward/test_cpsat_pin_cancels.py

Lines changed: 66 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
from torchwright.compiler.forward.scheduling_policy import SchedulingPolicy
4040
from torchwright.compiler.lower import lower
4141

42-
4342
# ---------------------------------------------------------------------------
4443
# The six example graphs (matches test_cpsat_sym1.py / test_cpsat_snapshot.py).
4544
# ---------------------------------------------------------------------------
@@ -60,7 +59,13 @@ def _build_bucketed_argmin():
6059
value = InputNode("baib_value", vw, value_range=(-100.0, 100.0))
6160
return attend_argmin_above_in_bucket(
6261
create_rope_config(d_head=d_head, max_positions=512),
63-
score, validity, kb, above, qb, th, value,
62+
score,
63+
validity,
64+
kb,
65+
above,
66+
qb,
67+
th,
68+
value,
6469
)
6570

6671

@@ -77,12 +82,22 @@ def _example_specs():
7782
# calculator: d pinned at the pre-unification test width (the canonical
7883
# publish D_MODEL=8192 would make this schedule test enormous for
7984
# nothing); d_head follows the module — it is baked into the graph.
80-
"calculator": (lambda: calculator_simple.create_network_parts()[0], 1024, calculator_simple.D_HEAD),
85+
"calculator": (
86+
lambda: calculator_simple.create_network_parts()[0],
87+
1024,
88+
calculator_simple.D_HEAD,
89+
),
8190
"caesar": (lambda: caesar_cipher.create_network_parts()[0], 512, 16),
82-
"sort_digits": (lambda: sort_digits_v1.create_network_parts()[0], sort_digits_v1.D_MODEL, sort_digits_v1.D_HEAD),
91+
"sort_digits": (
92+
lambda: sort_digits_v1.create_network_parts()[0],
93+
sort_digits_v1.D_MODEL,
94+
sort_digits_v1.D_HEAD,
95+
),
8396
"fibonacci": (lambda: fibonacci.create_network_parts()[0], 512, 16),
8497
"binary_increment": (
85-
lambda: binary_increment.create_network_parts()[0], 256, 16
98+
lambda: binary_increment.create_network_parts()[0],
99+
256,
100+
16,
86101
),
87102
"bucketed_argmin": (_build_bucketed_argmin, 512, 32),
88103
}
@@ -129,9 +144,9 @@ def test_default_build_is_pinned(name):
129144
on = _proto_text(build_cpsat_model(node, _pin_cancels=True, **cfg))
130145
assert default == on, f"{name}: default proto differs from pinned build"
131146
assert "parked" not in default, f"{name}: default build has parked vars"
132-
assert "pin_attn" in default or "pin_mlp" in default, (
133-
f"{name}: default build posts no pin aux vars (pin is dead)"
134-
)
147+
assert (
148+
"pin_attn" in default or "pin_mlp" in default
149+
), f"{name}: default build posts no pin aux vars (pin is dead)"
135150

136151

137152
@pytest.mark.parametrize("name", _NAMES)
@@ -147,9 +162,9 @@ def test_knob_off_reproduces_legacy_model(name):
147162
off = _proto_text(build_cpsat_model(node, _pin_cancels=False, **cfg))
148163
assert off != default, f"{name}: knob-off proto identical to default"
149164
assert "parked" in off, f"{name}: legacy build has no parked vars"
150-
assert "pin_attn" not in off and "pin_mlp" not in off, (
151-
f"{name}: legacy build still posts pin aux vars"
152-
)
165+
assert (
166+
"pin_attn" not in off and "pin_mlp" not in off
167+
), f"{name}: legacy build still posts pin aux vars"
153168

154169

155170
# ---------------------------------------------------------------------------
@@ -168,8 +183,13 @@ def test_knob_off_reproduces_legacy_model(name):
168183

169184
def _solve_cfg(d, d_head):
170185
return dict(
171-
d=d, d_head=d_head, d_hidden=d, max_layers=100,
172-
time_budget_s=60.0, policy=SchedulingPolicy(), tighten_domains=True,
186+
d=d,
187+
d_head=d_head,
188+
d_hidden=d,
189+
max_layers=100,
190+
time_budget_s=60.0,
191+
policy=SchedulingPolicy(),
192+
tighten_domains=True,
173193
)
174194

175195

@@ -190,8 +210,13 @@ def test_pinned_solution_valid_in_unpinned_model(name, d):
190210
)
191211

192212
built = build_cpsat_model(
193-
low, d=d, d_head=d_head, d_hidden=d, max_layers=100,
194-
policy=SchedulingPolicy(), tighten_domains=True,
213+
low,
214+
d=d,
215+
d_head=d_head,
216+
d_hidden=d,
217+
max_layers=100,
218+
policy=SchedulingPolicy(),
219+
tighten_domains=True,
195220
_pin_cancels=False, # the legacy model is the verification target
196221
)
197222
for nid, L in asg.node_to_layer.items():
@@ -228,12 +253,12 @@ def _solve(pin):
228253

229254
off_asg, off_stats = _solve(False)
230255
on_asg, on_stats = _solve(True)
231-
assert off_asg is not None and off_stats.is_optimal, (
232-
f"{name} d={d}: unpinned not optimal in budget ({off_stats.status_name})"
233-
)
234-
assert on_asg is not None and on_stats.is_optimal, (
235-
f"{name} d={d}: pinned not optimal in budget ({on_stats.status_name})"
236-
)
256+
assert (
257+
off_asg is not None and off_stats.is_optimal
258+
), f"{name} d={d}: unpinned not optimal in budget ({off_stats.status_name})"
259+
assert (
260+
on_asg is not None and on_stats.is_optimal
261+
), f"{name} d={d}: pinned not optimal in budget ({on_stats.status_name})"
237262
assert on_asg.n_layers >= off_asg.n_layers, (
238263
f"{name} d={d}: pinned optimum {on_asg.n_layers} beats unpinned "
239264
f"{off_asg.n_layers} — impossible for a pure restriction"
@@ -267,9 +292,9 @@ def test_pin_reaches_snapshot_path():
267292
)
268293
live_default = _proto_text(build_cpsat_model(node, **cfg))
269294
assert snap_default != snap_off, "knob dead on the snapshot path"
270-
assert snap_default == live_default, (
271-
"default (pinned) snapshot proto differs from default live"
272-
)
295+
assert (
296+
snap_default == live_default
297+
), "default (pinned) snapshot proto differs from default live"
273298

274299

275300
# ---------------------------------------------------------------------------
@@ -298,9 +323,9 @@ def test_full_hint_with_pin_passes_strict_validation():
298323
_pin_cancels=True,
299324
**cfg,
300325
)
301-
assert asg is not None, (
302-
f"pinned solve with full hint found nothing ({stats.status_name})"
303-
)
326+
assert (
327+
asg is not None
328+
), f"pinned solve with full hint found nothing ({stats.status_name})"
304329

305330

306331
# ---------------------------------------------------------------------------
@@ -315,8 +340,12 @@ def test_default_pinned_compile_replays_clean():
315340
build, d, d_head = _example_specs()["caesar"]
316341
torch.manual_seed(0)
317342
net = forward_compile(
318-
d=d, d_head=d_head, output_node=build(), device="cpu",
319-
verbose=False, optimize=1,
343+
d=d,
344+
d_head=d_head,
345+
output_node=build(),
346+
device="cpu",
347+
verbose=False,
348+
optimize=1,
320349
)
321350
# A raise above would be the replay-depth tripwire (or any compile error)
322351
# firing; a clean return with real layers is the tripwire staying silent.
@@ -327,7 +356,13 @@ def test_knob_off_compile_replays_clean():
327356
build, d, d_head = _example_specs()["caesar"]
328357
torch.manual_seed(0)
329358
net = forward_compile(
330-
d=d, d_head=d_head, output_node=build(), device="cpu",
331-
verbose=False, optimize=1, _pin_cancels=False, _force_resolve=True,
359+
d=d,
360+
d_head=d_head,
361+
output_node=build(),
362+
device="cpu",
363+
verbose=False,
364+
optimize=1,
365+
_pin_cancels=False,
366+
_force_resolve=True,
332367
)
333368
assert len(net.layers) > 0

tests/compile/forward/test_cpsat_snapshot.py

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
)
3333
from torchwright.compiler.forward.scheduling_policy import SchedulingPolicy
3434

35-
3635
# ---------------------------------------------------------------------------
3736
# The six example graphs (matches scripts/intralayer_example_sweep.py)
3837
# ---------------------------------------------------------------------------
@@ -53,7 +52,13 @@ def _build_bucketed_argmin():
5352
value = InputNode("baib_value", vw, value_range=(-100.0, 100.0))
5453
return attend_argmin_above_in_bucket(
5554
create_rope_config(d_head=d_head, max_positions=512),
56-
score, validity, kb, above, qb, th, value,
55+
score,
56+
validity,
57+
kb,
58+
above,
59+
qb,
60+
th,
61+
value,
5762
)
5863

5964

@@ -70,12 +75,22 @@ def _example_specs():
7075
# calculator: d pinned at the pre-unification test width (the canonical
7176
# publish D_MODEL=8192 would make this schedule test enormous for
7277
# nothing); d_head follows the module — it is baked into the graph.
73-
"calculator": (lambda: calculator_simple.create_network_parts()[0], 1024, calculator_simple.D_HEAD),
78+
"calculator": (
79+
lambda: calculator_simple.create_network_parts()[0],
80+
1024,
81+
calculator_simple.D_HEAD,
82+
),
7483
"caesar": (lambda: caesar_cipher.create_network_parts()[0], 512, 16),
75-
"sort_digits": (lambda: sort_digits_v1.create_network_parts()[0], sort_digits_v1.D_MODEL, sort_digits_v1.D_HEAD),
84+
"sort_digits": (
85+
lambda: sort_digits_v1.create_network_parts()[0],
86+
sort_digits_v1.D_MODEL,
87+
sort_digits_v1.D_HEAD,
88+
),
7689
"fibonacci": (lambda: fibonacci.create_network_parts()[0], 512, 16),
7790
"binary_increment": (
78-
lambda: binary_increment.create_network_parts()[0], 256, 16
91+
lambda: binary_increment.create_network_parts()[0],
92+
256,
93+
16,
7994
),
8095
"bucketed_argmin": (_build_bucketed_argmin, 512, 32),
8196
}
@@ -128,8 +143,12 @@ def test_canonicalized_snapshot_rebuilds_a_valid_model():
128143
node, d, d_head = _build("caesar")
129144
cfg = dict(d=d, d_head=d_head, d_hidden=d, max_layers=40)
130145
problem = snapshot_from_graph_model(build_graph_model(node)).canonicalized(node)
131-
a = _proto_text(build_model_from_snapshot(SchedulingProblem.loads(problem.dumps()), **cfg))
132-
b = _proto_text(build_model_from_snapshot(SchedulingProblem.loads(problem.dumps()), **cfg))
146+
a = _proto_text(
147+
build_model_from_snapshot(SchedulingProblem.loads(problem.dumps()), **cfg)
148+
)
149+
b = _proto_text(
150+
build_model_from_snapshot(SchedulingProblem.loads(problem.dumps()), **cfg)
151+
)
133152
assert a == b # canonical rebuild is deterministic across loads
134153

135154

@@ -144,7 +163,11 @@ def test_hinted_build_proto_identical():
144163
# would make this proto comparison vacuous on the widening path.
145164
node, d, d_head = _build("caesar")
146165
cfg = dict(
147-
d=d, d_head=d_head, d_hidden=d, max_layers=40, tighten_domains=True,
166+
d=d,
167+
d_head=d_head,
168+
d_hidden=d,
169+
max_layers=40,
170+
tighten_domains=True,
148171
_pin_cancels=False,
149172
)
150173
# A feasible schedule -> hint dicts that exercise the cancel-window widening.
@@ -158,9 +181,7 @@ def test_hinted_build_proto_identical():
158181
problem = SchedulingProblem.loads(
159182
snapshot_from_graph_model(build_graph_model(node)).dumps()
160183
)
161-
snap = _proto_text(
162-
build_model_from_snapshot(problem, diagnostic_hint=hint, **cfg)
163-
)
184+
snap = _proto_text(build_model_from_snapshot(problem, diagnostic_hint=hint, **cfg))
164185
assert snap == live
165186

166187

@@ -186,8 +207,13 @@ def test_frozen_hint_roundtrips():
186207
def test_solve_from_snapshot_matches_live_solve():
187208
node, d, d_head = _build("caesar")
188209
kw = dict(
189-
d=d, d_head=d_head, d_hidden=d, max_layers=40, time_budget_s=30.0,
190-
tighten_domains=True, policy=SchedulingPolicy(),
210+
d=d,
211+
d_head=d_head,
212+
d_hidden=d,
213+
max_layers=40,
214+
time_budget_s=30.0,
215+
tighten_domains=True,
216+
policy=SchedulingPolicy(),
191217
solver_params={"random_seed": 1},
192218
)
193219
live_asg, live_stats = solve_schedule(node, **kw)
@@ -208,8 +234,13 @@ def test_solve_from_snapshot_matches_live_solve():
208234
def test_save_load_with_fingerprint_gate(tmp_path):
209235
node, d, d_head = _build("binary_increment")
210236
geom = dict(
211-
d=d, d_head=d_head, d_hidden=d, flex_routing=True, cancel_slack=2,
212-
policy=SchedulingPolicy(), max_layers=60,
237+
d=d,
238+
d_head=d_head,
239+
d_hidden=d,
240+
flex_routing=True,
241+
cancel_slack=2,
242+
policy=SchedulingPolicy(),
243+
max_layers=60,
213244
)
214245
cp = 5 # arbitrary stand-in for the lowered critical path in this unit test
215246
problem = (

0 commit comments

Comments
 (0)