3939from torchwright .compiler .forward .scheduling_policy import SchedulingPolicy
4040from 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
169184def _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
0 commit comments