textgrad.autograd.algebra#

Classes

Aggregate()

This function is WIP

Sum()

Represents a sum operation on a list of variables.

class textgrad.autograd.algebra.Aggregate#

Bases: Function

This function is WIP

backward(aggregated_variable, backward_engine)#
Parameters:
forward(variables)#

Aggregates a list of variables. In TextGrad, forward pass of aggregation is simply concatenation of the values of the variables. The backward pass performs a reduction operation on the gradients of the variables. This reduction is currently an LLM call to summarize the gradients.

Parameters:

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

Returns:

The aggregated variable.

Return type:

Variable

class textgrad.autograd.algebra.Sum#

Bases: Function

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

backward(summation, backward_engine)#

Performs the backward pass of the sum operation. This is simply an idempotent operation, where we pass the feedback to the predecessors variables.

Parameters:
  • summation (Variable) – The variable representing the sum.

  • backward_engine (EngineLM) – The backward engine used for backpropagation.

forward(variables)#

Performs the forward pass of the sum (concatenation) operation.

Parameters:

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

Returns:

A new variable representing the sum of the input variables.

Return type:

Variable