Skip to content

Make debug_print more readable #313

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

Closed
ricardoV94 opened this issue May 22, 2023 · 2 comments · Fixed by #319
Closed

Make debug_print more readable #313

ricardoV94 opened this issue May 22, 2023 · 2 comments · Fixed by #319

Comments

@ricardoV94
Copy link
Member

ricardoV94 commented May 22, 2023

import pytensor
import pytensor.tensor as pt

x = pt.scalar("x")
y = pt.vector("y")
z = x + pt.exp(y)

pytensor.dprint(z)
Elemwise{add,no_inplace} [id A]
 |InplaceDimShuffle{x} [id B]
 | |x [id C]
 |Elemwise{exp,no_inplace} [id D]
   |y [id E]

This contains a lot of detail that is irrelevant for most users:

  1. Elemwise{...}. Almost all operations are Elemwise because users don't build graphs with scalars. I suggest we just call Add. The "type" of addition can be guessed from the input types which are visible with print_type=True. This will be even more relevant after Implement graph.vectorize and Blockwise Op #306 where everything that is not an Elemwise will likely be a Blockwise. We can maybe add a kwarg to show the exact Op that is being used.
  2. The inplace/no_inplace is seldom important for users. This information is still visible via either print_destroy_map or print_view_map. Maybe we can have a print_memory_map that is equivalent to setting both of those to True.
  3. DimShuffles are incredibly common, but very obscure because they are a term only used in PyTensor. I suggest we specialize the name for the following 4 cases:
    1. ExpandDims{axis/axes=dims}
    2. DropDims{axis/axes=dims} (or Squeeze?)
    3. Transpose{axis/axes=dims}
    4. DimShuffle{order} (if it's a mix of the ones above)

The default dprint for the above graph would then look something like:

Add [id A]
 |ExpandDims{axis=0} [id B]
 | |x [id C]
 |Exp [id D]
   |y [id E]

And dprint(print_type=True, print_memory_map=True)

Add [id A] <TensorType(float64, (?,))>
 |ExpandDims{axis=0} [id B] <TensorType(float64, (1,))> v={0: [0]}
 | |x [id C] <TensorType(float64, ())>
 |Exp [id D] <TensorType(float64, (?,))>
   |y [id E] <TensorType(float64, (?,))>

Which I think is way more readable! We can go one step further and rename <TensorType(float64, (?,))> to <Tensor(float64, shape=(?,))> or even <Vector(float64, shape=(?,))>

@ricardoV94 ricardoV94 changed the title Make debug_print more readable Make debug_print more readable May 22, 2023
@twiecki
Copy link
Member

twiecki commented May 22, 2023

This would be great, I have a really hard time parsing everything that's going on in that output usually, but your simplified proposal is much easier to parse.

On Aesara there also was the proposal to use more complex characters like ┕.

@ricardoV94
Copy link
Member Author

On Aesara there also was the proposal to use more complex characters like ┕.

Yeah that would be even nicer!

@ricardoV94 ricardoV94 added help wanted Extra attention is needed and removed help wanted Extra attention is needed labels May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants