ops#

Text-grad operations such as Sum and Aggregate.

Functions

sum_ops(params)

Represents a sum operation on a list of variables.

Classes

Sum(*args, **kwargs)

The class to define a sum operation on a list of parameters, such as losses or gradients.

sum_ops(params: List[Parameter]) Parameter[source]#

Represents a sum operation on a list of variables. In TextGrad, sum is simply concatenation of the values of the variables.

Parameters:

variables (List[Variable]) – The list of variables to be summed (concatenated).

Returns:

A new variable representing the sum of the input variables.

Return type:

Variable

class Sum(*args, **kwargs)[source]#

Bases: GradComponent

The class to define a sum operation on a list of parameters, such as losses or gradients.

name: str = 'Sum'#
forward(params: List[Parameter]) Parameter[source]#

Performs the forward pass of the sum operation. This is a simple operation that concatenates the values of the parameters.

Parameters:

params (List[Parameter]) – The list of parameters to be summed.

Return type:

Parameter

backward(summation: Parameter)[source]#

Performs the backward pass of the sum operation. This is simply an idempotent operation, where we make a gradient with the combined feedback and add it to the predecessors’grads.

Parameters:

summation (Parameter) – The parameter representing the sum.

backward_engine: BackwardEngine#
training: bool#