The library of Trace is designed to be a lightweight, modularized package to allow developers to easily try new ideas on generative optimization and integrate learning wtih their pipelines.
Currently, the Trace library has three main modules collected under the opto top module.
-
opto.traceprovides the infrastructure for tracing computational workflows. It defines two primitivestrace.nodeand@trace.bundle. They can be applied to Python objects and methods, respectively, which define the root nodes and operators of the directed acyclic graph (DAG) of computation. They both have atrainableflag. When setTrue, the wrapped objects are viewed as parameters of the computational worflow. Users can usetrace.nodeand@trace.bundleto declare the data and computation that they wish to trace and/or adapt, and we call the resulting workflow defined by these two primitives a traced workflow. When running a traced workflow, a DAG will be automatiically created by Trace as a data structure, which will later be sent to optimizers inopto.optimizersfor updates (upon callingnode.backwardwith soem feedback). -
opto.optimizershas a collection of generative optimization algorithms, whose API is defined by an abstract classOptimizer. Think them like gradient algorithms. Their job is to propose a new version of the parameters (i.e. those set withtrainable=True) when receiving a computational graph (DAG) and the feedback given to the computed output. Typically, these algorithms can be viewed as an LLM agent, which makes calls to LLM to analyze the computational graph and the feedback, and to propose updates. In Trace library, we provide implementation of several popular optimizers, suchOptoPrime,TextGrad, andOPRO. -
opto.trainersare a collection of training algorithms (under theAlgorithmBaseclass) that use optimizers inopto.optimizersas subroutines to improve a given workflow following a feedback oracle constructed by datasets, interactive environments, etc. WhileOptimizerdefines a low-level optimization API,AlgorithmBasedefines a high-level learning API which standarizes the format of agent (by theModuleclass created by@trace.model), the data loader (by theDataLoaderclass), and the feedback oracle (by theAutoGuideclass). With this common abstraction, we offer training algorithms, from the basicMinibatchAlgorithmwhich trains minibatches of samples to search algorithms likeBeamSearch. TheAlgorithmBasealso handles logging of the training process. While there are overlapping between the functions ofOptimizerandAlgorithmBase, the main distinction is that algorithms underAlgorithmBaseare meta algorithms, as they should work for different optimizers inopto.optimizers. -
opto.utilshas a collection of helper functions and backends, which are reusable for various applications. This includes, e.g., abstraction of LLMs, database, etc. Making use of all these utils would requie installing optional depedencies.
In summary, opto.trace is the infrastructure, opto.optimizers are algorithms that process feedback and propose new parameter candidates, and opto.trainers are algorithms built on top of opto.trace and opto.optimizers to train learning agents.
- Use
trace.nodeand@trace.bundleto define the traceable workflow and its trainable parameter. - Wrap the workflow as a
trace.Moduleusing@trace.model - Create a dataloader using
DataLoaderand define the feedback oracle (an analogy of loss function) usingAutoGuide. - Create a trainer from
opto.trainersusing optimizers fromopto.optimizersand the above module, dataloader, and feedback oracle. - Run the trainer.
- Developing new optimization agent Contribute to
trace.optimizersand design new algorithms underOptimizer - Developing new learning algorithms Contribute to
trace.trainers(andtrace.optimizerswhen necessary). Design new algorithms underAlgorithmBase, new dataloader underDataLoader, or new feedback oracle underAutoGuide. - Improving infrastructure Propose updates to change
opto.trace(e.g., to improve UI, add new tracing, etc.) - Onboarding other utility tools Add to
opto.utilsand updatesetup.pywith optional requirements.