Skip to content
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 print_shape and print_memory_map option to debugprint #1236

Merged
merged 4 commits into from
Feb 24, 2025

Conversation

Aarsh-Wankar
Copy link
Contributor

@Aarsh-Wankar Aarsh-Wankar commented Feb 23, 2025

Description

I added an extra argument print_shape to debugprint and _debugprint, which, when True, prints the shape of every Variable in the graph.

Test demonstration:

import pytensor
import pytensor.tensor as pt
x = pt.matrix("x", shape=(None, 3))
y = pt.broadcast_to(x * 5, (5, 7, 3))
y.dprint(print_shape = True)

# Output:
# Alloc [id A] shape=(5, 7, 3)
#  ├─ Mul [id B] shape=(?, 3)
#  │  ├─ x [id C] shape=(?, 3)
#  │  └─ ExpandDims{axes=[0, 1]} [id D] shape=(1, 1)
#  │     └─ 5 [id E] shape=()
#  ├─ 5 [id F] shape=()
#  ├─ 7 [id G] shape=()
#  └─ 3 [id H] shape=()

Additionally, I also simplified the __str__ function logic of class TensorType to easily find the formatted shape.

formatted_shape = str(shape).replace("None", "?")

Related Issue

Checklist

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

📚 Documentation preview 📚: https://pytensor--1236.org.readthedocs.build/en/1236/

@ricardoV94 ricardoV94 added the enhancement New feature or request label Feb 23, 2025
Copy link

codecov bot commented Feb 23, 2025

Codecov Report

Attention: Patch coverage is 50.00000% with 5 lines in your changes missing coverage. Please review.

Project coverage is 81.98%. Comparing base (5d4e9e0) to head (640c759).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
pytensor/printing.py 37.50% 3 Missing and 2 partials ⚠️

❌ Your patch status has failed because the patch coverage (50.00%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1236      +/-   ##
==========================================
- Coverage   81.99%   81.98%   -0.02%     
==========================================
  Files         188      188              
  Lines       48566    48567       +1     
  Branches     8677     8677              
==========================================
- Hits        39823    39818       -5     
- Misses       6580     6584       +4     
- Partials     2163     2165       +2     
Files with missing lines Coverage Δ
pytensor/tensor/type.py 94.52% <100.00%> (-0.08%) ⬇️
pytensor/printing.py 51.43% <37.50%> (-0.25%) ⬇️

... and 1 file with indirect coverage changes

Copy link
Member

@ricardoV94 ricardoV94 left a comment

Choose a reason for hiding this comment

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

Awesome!

@ricardoV94
Copy link
Member

Another thing that I've been missing is to have a print_memory_map which is equivalent to setting both print_destroy_map and print_view_map to True. Usually I need both or neither, never just the one

@ricardoV94 ricardoV94 changed the title Added print_shape option to debugprint and simplified __str__ logic in TensorType Add print_shape option to debugprint Feb 23, 2025
@ricardoV94 ricardoV94 changed the title Add print_shape option to debugprint Add print_shape and print_memory_map option to debugprint Feb 24, 2025
@ricardoV94 ricardoV94 merged commit b12dc30 into pymc-devs:main Feb 24, 2025
72 of 73 checks passed
@ricardoV94
Copy link
Member

Thanks @Aarsh-Wankar

@Aarsh-Wankar Aarsh-Wankar deleted the add_print_shape_1191 branch February 24, 2025 19:06
Aarsh-Wankar added a commit to Aarsh-Wankar/pytensor that referenced this pull request Feb 24, 2025
…-devs#1236)

* Added print_shape option to debugprint and simplify __str__ logic in TensorType
* Add print_memory_map option to debugprint to enable destroy and view maps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request graph objects
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a print_shape argument to debug_print
2 participants