Skip to content

Don't repeat inner graphs with multiple outputs in debugprint #196

Closed
@ricardoV94

Description

@ricardoV94

Description

import pytensor
import pytensor.tensor as pt
x = pt.vector("x")
outs, _ = pytensor.scan(
    fn = lambda x: (
        pt.exp(pt.random.normal(x)),
        pt.log(pt.random.normal(x)), 
        pt.cos(pt.random.normal(x)),
    ),
    sequences=[x],
)
fn = pytensor.function([x], outs)
pytensor.dprint(fn)
for{cpu,scan_fn}.0 [id A] 5
 |Shape_i{0} [id B] 0
 | |x [id C]
 |Subtensor{int64:int64:int8} [id D] 4
 | |x [id C]
 | |ScalarFromTensor [id E] 3
 | | |Elemwise{Composite{Switch(LE(i0, i1), i1, i2)}} [id F] 2
 | |   |Shape_i{0} [id B] 0
 | |   |TensorConstant{0} [id G]
 | |   |TensorConstant{0} [id H]
 | |ScalarFromTensor [id I] 1
 | | |Shape_i{0} [id B] 0
 | |ScalarConstant{1} [id J]
 |Shape_i{0} [id B] 0
 |Shape_i{0} [id B] 0
 |Shape_i{0} [id B] 0
 |RandomGeneratorSharedVariable(<Generator(PCG64) at 0x12E952EA0>) [id K]
 |RandomGeneratorSharedVariable(<Generator(PCG64) at 0x12E89F4C0>) [id L]
 |RandomGeneratorSharedVariable(<Generator(PCG64) at 0x12E8E4740>) [id M]
for{cpu,scan_fn}.1 [id A] 5
for{cpu,scan_fn}.2 [id A] 5

Inner graphs:

for{cpu,scan_fn}.0 [id A]
 >Elemwise{exp,no_inplace} [id N]
 > |normal_rv{0, (0, 0), floatX, False}.1 [id O]
 >   |*1-<RandomGeneratorType> [id P] -> [id K]
 >   |TensorConstant{[]} [id Q]
 >   |TensorConstant{11} [id R]
 >   |*0-<TensorType(float64, ())> [id S] -> [id D]
 >   |TensorConstant{1.0} [id T]
 >Elemwise{log,no_inplace} [id U]
 > |normal_rv{0, (0, 0), floatX, False}.1 [id V]
 >   |*2-<RandomGeneratorType> [id W] -> [id L]
 >   |TensorConstant{[]} [id Q]
 >   |TensorConstant{11} [id R]
 >   |*0-<TensorType(float64, ())> [id S] -> [id D]
 >   |TensorConstant{1.0} [id T]
 >Elemwise{cos,no_inplace} [id X]
 > |normal_rv{0, (0, 0), floatX, False}.1 [id Y]
 >   |*3-<RandomGeneratorType> [id Z] -> [id M]
 >   |TensorConstant{[]} [id Q]
 >   |TensorConstant{11} [id R]
 >   |*0-<TensorType(float64, ())> [id S] -> [id D]
 >   |TensorConstant{1.0} [id T]

for{cpu,scan_fn}.1 [id A]
 >Elemwise{exp,no_inplace} [id N]
 >Elemwise{log,no_inplace} [id U]
 >Elemwise{cos,no_inplace} [id X]

for{cpu,scan_fn}.2 [id A]
 >Elemwise{exp,no_inplace} [id N]
 >Elemwise{log,no_inplace} [id U]
 >Elemwise{cos,no_inplace} [id X]

The last two entries of inner-graphs are completely redundant, since the information is already contained in the first inner graph. This will be even more relevant after #121 as multiple output Composites will also be printed like this.

Does anyone know a good reason for repeating the outputs in inner graphs? Maybe inplace or view info?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions