ops

Text-grad operations such as Sum and Aggregate.

Functions

sum_ops(params)

Represents a sum operation on a list of variables.

Classes

Sum()

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[source]

Bases: GradComponent

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

It enables gradients combination of a batch of data samples.

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, *args, **kwargs)[source]

Computes gradients for the predecessors of the sum operation. There is no gradient computation for the sum operation itself. It is a simple way to combine multiple losses for convenience.

sum.backward() => [loss1.backward(), loss2.backward(), …]

Parameters:

summation (Parameter) – The parameter representing the sum.

backward_engine: BackwardEngine
training: bool
teacher_mode: bool
tracing: bool