Commit 4f80b77
authored
Cache graph_signature property lookups in partitioning hot loops (#18352)
inputs_to_parameters, inputs_to_buffers, etc. are @Property methods
that rebuild a dict from input_specs on every access. In partitioning
loops that check each graph node, this causes O(nodes × params) dict
constructions. For a 40-layer MoE model with ~26K nodes and ~1,671
parameters, this results in ~260M iterations of pure overhead that
showed up as multiple minutes during to_edge_transform_and_lower.
Cache the dicts before the loops in:
- backend/utils.py: tag_constant_data (2 loops × 3 dict lookups each)
- backend/utils.py: tag_mutated_buffer (1 loop × 2 dict lookups)
- lowered_backend_module.py: __call__ (2 passes × 2 dict lookups)
- lowered_backend_module.py: arrange_graph_placeholders (1 loop × 2)
No behavioral change — the graph signature is not mutated between
caching and use in any of these functions.1 parent dff7d78 commit 4f80b77
2 files changed
Lines changed: 34 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | 27 | | |
29 | 28 | | |
30 | 29 | | |
| |||
351 | 350 | | |
352 | 351 | | |
353 | 352 | | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
354 | 360 | | |
355 | 361 | | |
356 | 362 | | |
357 | | - | |
358 | | - | |
359 | | - | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
360 | 366 | | |
361 | 367 | | |
362 | | - | |
| 368 | + | |
363 | 369 | | |
364 | 370 | | |
365 | 371 | | |
| |||
368 | 374 | | |
369 | 375 | | |
370 | 376 | | |
371 | | - | |
372 | | - | |
373 | | - | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
374 | 380 | | |
375 | 381 | | |
376 | 382 | | |
| |||
397 | 403 | | |
398 | 404 | | |
399 | 405 | | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
400 | 411 | | |
401 | 412 | | |
402 | 413 | | |
403 | | - | |
| 414 | + | |
404 | 415 | | |
405 | | - | |
| 416 | + | |
406 | 417 | | |
407 | 418 | | |
408 | 419 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
223 | 223 | | |
224 | 224 | | |
225 | 225 | | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
226 | 231 | | |
227 | 232 | | |
228 | 233 | | |
229 | 234 | | |
230 | 235 | | |
231 | 236 | | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
| 237 | + | |
| 238 | + | |
236 | 239 | | |
237 | 240 | | |
238 | 241 | | |
| |||
250 | 253 | | |
251 | 254 | | |
252 | 255 | | |
253 | | - | |
254 | | - | |
255 | | - | |
| 256 | + | |
256 | 257 | | |
257 | 258 | | |
258 | 259 | | |
| |||
402 | 403 | | |
403 | 404 | | |
404 | 405 | | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
405 | 409 | | |
406 | 410 | | |
407 | 411 | | |
408 | 412 | | |
409 | 413 | | |
410 | 414 | | |
411 | 415 | | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
| 416 | + | |
416 | 417 | | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
| 418 | + | |
421 | 419 | | |
422 | 420 | | |
423 | 421 | | |
| |||
0 commit comments