boundlab.expr.TupleExpr#

class boundlab.expr.TupleExpr[source]#

Bases: object

A base class for expressions that represent multiple tensors as a tuple. Usually a output of a multi-output operation, such as torch.chunk or a convolution that returns both output and pre-activation.

This is used to represent multiple outputs from a single operation, such as the two outputs of a convolution (output and pre-activation). TupleExpr is not intended to be used directly by users; it is an implementation detail for handling multi-output operations.

To simplify Expr APIs, TupleExpr is not a subclass of Expr and does not support the full expression interface. It resembles Expr in that it has a unique ID and can be used as a child of Expr through GetTupleItem, but its shape is a tuple of torch.Size, and its backward methods takes multiple weights operators corresponding to each output.

children#

A tuple of sub-expressions.

Methods

__init__

backward

Perform backward-mode bound propagation through this expression.

to_string

Convert this expression to a string for debugging purposes.

with_children

Return a new TupleExpr with the same flags but new children.

__init__(*flags)[source]#
property shape: tuple[torch.Size, ...]#
property children: tuple[Expr, ...]#

Children expressions that contribute to this TupleExpr. This is used for topological sorting and weight propagation.

backward(*weights, direction='==')[source]#

Perform backward-mode bound propagation through this expression.

with_children(*new_children)[source]#

Return a new TupleExpr with the same flags but new children. This is used for expression rewriting during bound propagation.

to_string(*children_str, indent=0)[source]#

Convert this expression to a string for debugging purposes. The children_str arguments are the string representations of the children expressions, in the same order as self.children.