-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to print inner graphs in debugprint function #1293
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1293 +/- ##
=======================================
Coverage 82.03% 82.03%
=======================================
Files 188 188
Lines 48567 48567
Branches 8675 8675
=======================================
Hits 39841 39841
Misses 6574 6574
Partials 2152 2152
🚀 New features to boost your workflow:
|
pytensor/printing.py
Outdated
@@ -322,7 +325,7 @@ def debugprint( | |||
print_view_map=print_view_map, | |||
) | |||
|
|||
if len(inner_graph_vars) > 0: | |||
if len(inner_graph_vars) > 0 and print_inner_graphs: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's some logic above about collecting this inner_graph_vars, can we avoid doing that work when print_inner_graphs=False
?
Also wonder if we could instead specify the "depth" of the inner graphs we are interested in, like we have the depth
argument now for the depth of the graph. So if inner_graphs_depth=-1, we have the default behavior (show all inner_graphs), but if 0, we don't show any, and if 1 we show one level of inner graphs, but wouldn't show inner graphs inside other inner graphs, (and so on)?.
Can you spot if that would be feasible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added an extra argument inner_depth
to the debugprint function, which controls the depth of the inner graph to be printed. For example:
import pytensor
import pytensor.tensor as pt
from pytensor.compile.mode import get_default_mode
n = pt.iscalar("n")
x0 = pt.vector("x0")
xs, _ = pytensor.scan(lambda xtm1: xtm1 + 1, outputs_info=[x0], n_steps=n)
mode = get_default_mode().including("scan_save_mem")
fn = pytensor.function([n, x0], xs, mode=mode, on_unused_input="ignore")
fn.dprint(inner_depth = 1)
# Subtensor{start:stop} [id A] 9
# ├─ Scan{scan_fn, while_loop=False, inplace=all} [id B] 8
# │ ├─ n [id C]
# │ └─ SetSubtensor{:stop} [id D] 7
# │ ├─ AllocEmpty{dtype='float64'} [id E] 6
# │ │ ├─ Composite{...}.2 [id F] 0
# │ │ │ └─ n [id C]
# │ │ └─ Shape_i{0} [id G] 5
# │ │ └─ x0 [id H]
# │ ├─ Unbroadcast{0} [id I] 4
# │ │ └─ ExpandDims{axis=0} [id J] 3
# │ │ └─ x0 [id H]
# │ └─ 1 [id K]
# ├─ ScalarFromTensor [id L] 2
# │ └─ Composite{...}.1 [id F] 0
# │ └─ ···
# └─ ScalarFromTensor [id M] 1
# └─ Composite{...}.0 [id F] 0
# └─ ···
# Inner graphs:
# Scan{scan_fn, while_loop=False, inplace=all} [id B]
# ← Add [id N]
# Composite{...} [id F]
# ← add [id O] 'o0'
# ← add [id P] 'o1'
# ← add [id Q] 'o2'
fn.dprint(inner_depth = 2)
# ...
# Inner graphs:
# Scan{scan_fn, while_loop=False, inplace=all} [id B]
# ← Add [id N]
# ├─ [1.] [id O]
# └─ *0-<Vector(float64, shape=(?,))> [id P] -> [id D]
# Composite{...} [id F]
# ← add [id Q] 'o0'
# ├─ sub [id R]
# └─ maximum [id S] 't13'
# ← add [id T] 'o1'
# ├─ sub [id U]
# └─ maximum [id S] 't13'
# └─ ···
# ← add [id V] 'o2'
# ├─ Switch [id W]
# └─ 1 [id X]
Are these changes fine?
86dec25
to
c7d0a54
Compare
@@ -374,7 +383,7 @@ def debugprint( | |||
_debugprint( | |||
ig_var, | |||
prefix=prefix, | |||
depth=depth, | |||
depth=inner_depth, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
depth and inner_depth are not the same. Depth still makes sense alongside inner_depth. Inner depth tells how many inner graphs to step into, depth tells how many ops in a graph (or inner garph) to step into
I added an option
print_inner_graphs
to print inner graphs in the debugprint function.Description
A boolean argument
print_inner_graphs
is provided to the debugprint function, which defaults to True. In case we don't want to print the inner graphs, we can set it to False.For example:
Related Issue
Checklist
Type of change
📚 Documentation preview 📚: https://pytensor--1293.org.readthedocs.build/en/1293/