Skip to content

Defer FX graph stringification until DEBUG logging is enabled. - #4598

Draft
micwill755 wants to merge 1 commit into
skip-aliased-fold-executefrom
lazy-graph-printing
Draft

Defer FX graph stringification until DEBUG logging is enabled.#4598
micwill755 wants to merge 1 commit into
skip-aliased-fold-executefrom
lazy-graph-printing

Conversation

@micwill755

@micwill755 micwill755 commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Stop building the full FX graph string on every logger.debug call. logger.debug("…" + str(gm.graph)) and f-string dumps run Graph.__str__ even at INFO.
  • Pass gm.graph as a %s argument so Python logging formats it only when DEBUG is actually enabled.
  • Covers the compile hot path (compile / refit / torch.compile backend and the lowering passes that dumped the graph after each rewrite).

PR 7 of the compile-startup stack; based on #4597.

Test plan

  • tests/py/dynamo/lowering/test_lazy_graph_printing.py (source scan for eager str(gm.graph) in dynamo debug logs; constant_fold does not stringify at INFO and still does at DEBUG)
  • Klein/Flux not re-run: estimated ~40–55 ms at INFO/WARNING from ~6 dumps × ~8–9 ms; 0 at DEBUG

Stack created with GitHub Stacks CLIGive Feedback 💬

@meta-cla meta-cla Bot added the cla signed label Aug 26, 2026
@github-actions github-actions Bot added component: tests Issues re: Tests component: lowering Issues re: The lowering / preprocessing passes component: core Issues re: The core compiler component: api [Python] Issues re: Python API component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: torch_compile labels Aug 26, 2026
@github-actions
github-actions Bot requested a review from lanluo-nvidia August 26, 2026 22:14
logger.debug("..." + str(gm.graph)) and f-string graph dumps build the full graph even at INFO. Pass gm.graph as a %s argument so Graph.__str__ runs only when the line is emitted.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla signed component: api [Python] Issues re: Python API component: core Issues re: The core compiler component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: lowering Issues re: The lowering / preprocessing passes component: tests Issues re: Tests component: torch_compile

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant