Skip to content

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

Merged
micwill755 merged 1 commit into
skip-aliased-fold-executefrom
lazy-graph-printing
Oct 14, 2026
Merged

micwill755 merged 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 CLI • Give 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
@micwill755
micwill755 force-pushed the skip-aliased-fold-execute branch from d844300 to b61b68c Compare September 1, 2026 18:30
@micwill755
micwill755 force-pushed the skip-aliased-fold-execute branch from b61b68c to cacfbc5 Compare September 2, 2026 07:06
@micwill755
micwill755 force-pushed the skip-aliased-fold-execute branch from cacfbc5 to 59fd02a Compare September 9, 2026 22:54
@micwill755
micwill755 requested review from cehongwang and narendasan and removed request for lanluo-nvidia September 10, 2026 17:22
@micwill755
micwill755 force-pushed the skip-aliased-fold-execute branch from 59fd02a to e35fac9 Compare September 16, 2026 23:22
@micwill755
micwill755 force-pushed the skip-aliased-fold-execute branch from e35fac9 to f0695ce Compare September 16, 2026 23:23
@micwill755
micwill755 marked this pull request as ready for review September 29, 2026 17:20
@micwill755
micwill755 force-pushed the skip-aliased-fold-execute branch from f0695ce to 8ccd56d Compare September 29, 2026 17:44
@micwill755 micwill755 added this to the v2.15.0 milestone Sep 29, 2026

@cehongwang cehongwang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@micwill755
micwill755 force-pushed the skip-aliased-fold-execute branch 2 times, most recently from 6daf644 to 90f8285 Compare October 6, 2026 20:30
@micwill755
micwill755 force-pushed the lazy-graph-printing branch from c92404f to 907decb Compare October 6, 2026 20:32
@micwill755
micwill755 force-pushed the skip-aliased-fold-execute branch from 90f8285 to 79c54b0 Compare October 6, 2026 21:34
@micwill755
micwill755 force-pushed the lazy-graph-printing branch from 907decb to 292ccf4 Compare October 6, 2026 21:34

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some changes that do not conform to Python style guidelines:

--- /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/conversion/impl/moe.py	2026-10-06 21:35:01.728929+00:00
+++ /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/conversion/impl/moe.py	2026-10-06 21:35:31.514190+00:00
@@ -94,11 +94,13 @@
        ctx, offs, torch.int32, f"{name}_offs_i32", target, source_ir
    )
    offs_row = impl.shuffle.reshape(
        ctx, target, source_ir, f"{name}_offs_row", offs_i32, (1, -1)
    )
-    passed = impl.elementwise.le(ctx, target, source_ir, f"{name}_passed", offs_row, rows)
+    passed = impl.elementwise.le(
+        ctx, target, source_ir, f"{name}_passed", offs_row, rows
+    )
    group = impl.reduce.sum(
        ctx,
        target,
        source_ir,
        f"{name}_group",
--- /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/conversion/aten_ops_converters.py	2026-10-06 21:35:01.727179+00:00
+++ /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/conversion/aten_ops_converters.py	2026-10-06 21:35:35.685667+00:00
@@ -4640,13 +4640,11 @@
    if key in kwargs and kwargs[key] is not None:
        return kwargs[key]
    return args_bounds_check(args, index, default)


-def histc_validator(
-    node: Node, settings: Optional[CompilationSettings] = None
-) -> bool:
+def histc_validator(node: Node, settings: Optional[CompilationSettings] = None) -> bool:
    bins = _arg_or_kwarg(node.args, node.kwargs, 1, "bins", 100)
    lo = _arg_or_kwarg(node.args, node.kwargs, 2, "min", 0)
    hi = _arg_or_kwarg(node.args, node.kwargs, 3, "max", 0)
    if not all(
        isinstance(v, (int, float)) and not isinstance(v, bool) for v in (bins, lo, hi)

@lanluo-nvidia lanluo-nvidia modified the milestones: v2.15.0, v2.16.0 Oct 8, 2026
@micwill755
micwill755 force-pushed the skip-aliased-fold-execute branch from 79c54b0 to c778777 Compare October 13, 2026 19:06
@micwill755
micwill755 force-pushed the lazy-graph-printing branch 3 times, most recently from 548f37f to ae0c5d4 Compare October 13, 2026 22:09
@micwill755
micwill755 force-pushed the skip-aliased-fold-execute branch from 1565f07 to b9d3040 Compare October 13, 2026 23:12
@micwill755
micwill755 force-pushed the skip-aliased-fold-execute branch from b9d3040 to eebd4de Compare October 13, 2026 23:41
@micwill755
micwill755 force-pushed the skip-aliased-fold-execute branch from eebd4de to 98ad60b Compare October 13, 2026 23:51
@micwill755
micwill755 removed this pull request from stack #4533 October 13, 2026 23:52
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.
@micwill755
micwill755 merged commit 25749ad into skip-aliased-fold-execute Oct 14, 2026
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.

3 participants