textgrad.autograd.function#

Classes

BackwardContext(backward_fn, *args, **kwargs)

Represents a context for backward computation.

Function()

The class to define a function that can be called and backpropagated through.

Module()

Abstract module class with parameters akin to PyTorch's nn.Module.

class textgrad.autograd.function.BackwardContext(backward_fn, *args, **kwargs)#

Bases: object

Represents a context for backward computation.

Parameters:
  • backward_fn (callable) – The backward function to be called during backward computation.

  • args – Variable length argument list to be passed to the backward function.

  • kwargs – Arbitrary keyword arguments to be passed to the backward function.

Variables:
  • backward_fn (callable) – The backward function to be called during backward computation.

  • fn_name (str) – The fully qualified name of the backward function.

  • args – Variable length argument list to be passed to the backward function.

  • kwargs – Arbitrary keyword arguments to be passed to the backward function.

Method __call__(backward_engine:

EngineLM) -> Any: Calls the backward function with the given backward engine and returns the result.

Method __repr__() -> str:

Returns a string representation of the BackwardContext object.

__call__(backward_engine)#

Call self as a function.

Parameters:

backward_engine (EngineLM)

class textgrad.autograd.function.Function#

Bases: ABC

The class to define a function that can be called and backpropagated through.

__call__(*args, **kwargs)#

Call self as a function.

abstract backward(*args, **kwargs)#
abstract forward(*args, **kwargs)#
Return type:

Variable

class textgrad.autograd.function.Module#

Bases: ABC

Abstract module class with parameters akin to PyTorch’s nn.Module.

__call__(*args, **kwargs)#

Call self as a function.

abstract forward(*args, **kwargs)#
named_parameters()#
parameters: List[Variable]#
zero_grad()#