textgrad  by zou-group

Autograd engine for textual gradients, enabling LLM-driven optimization

Created 1 year ago
2,927 stars

Top 16.2% on SourcePulse

GitHubView on GitHub
Project Summary

TextGrad enables automatic differentiation for text-based tasks by leveraging Large Language Models (LLMs) to provide gradient feedback. This framework allows users to define loss functions and optimize textual outputs, such as reasoning steps, code snippets, or prompts, using a PyTorch-like API. It's designed for researchers and developers working with LLMs who need to fine-tune or improve the quality of generated text through an iterative optimization process.

How It Works

TextGrad implements a novel "textual gradient" concept, where LLMs act as differentiators. Instead of numerical gradients, LLMs provide textual feedback on the quality or correctness of an output. This feedback is then used by a Textual Gradient Descent (TGD) optimizer to iteratively refine the textual variable, guided by a natural-language loss function. This approach allows optimization of complex, unstructured data like natural language, code, or even multimodal inputs.

Quick Start & Requirements

Highlighted Details

  • Published in Nature (March 2025).
  • Supports multiple LLM backends via litellm, including Bedrock, Together, and Gemini.
  • Enables optimization of text, code, prompts, and multimodal inputs.
  • Features a PyTorch-like API for intuitive usage.

Maintenance & Community

  • Active development with recent updates introducing new litellm-based engines.
  • Key contributors include Federico Bianchi and Mert Yuksekgonul.
  • Inspiration drawn from PyTorch, DSPy, Micrograd, ProTeGi, and Reflexion.

Licensing & Compatibility

  • The repository does not explicitly state a license in the provided README. Further investigation is required for licensing details and commercial use compatibility.

Limitations & Caveats

  • The new litellm engines are experimental and may have issues.
  • The effectiveness of optimization is highly dependent on the quality of the LLM feedback and the defined loss function.
  • Requires access to LLM APIs, which may incur costs.
Health Check
Last Commit

1 month ago

Responsiveness

1 day

Pull Requests (30d)
2
Issues (30d)
0
Star History
97 stars in the last 30 days

Explore Similar Projects

Starred by Shizhe Diao Shizhe Diao(Author of LMFlow; Research Scientist at NVIDIA), Yineng Zhang Yineng Zhang(Inference Lead at SGLang; Research Scientist at Together AI), and
8 more.

EAGLE by SafeAILab

10.6%
2k
Speculative decoding research paper for faster LLM inference
Created 1 year ago
Updated 1 week ago
Starred by Chip Huyen Chip Huyen(Author of "AI Engineering", "Designing Machine Learning Systems") and Elvis Saravia Elvis Saravia(Founder of DAIR.AI).

NExT-GPT by NExT-GPT

0.1%
4k
Any-to-any multimodal LLM research paper
Created 2 years ago
Updated 4 months ago
Starred by Yineng Zhang Yineng Zhang(Inference Lead at SGLang; Research Scientist at Together AI), Lewis Tunstall Lewis Tunstall(Research Engineer at Hugging Face), and
15 more.

torchtune by pytorch

0.2%
5k
PyTorch library for LLM post-training and experimentation
Created 1 year ago
Updated 1 day ago
Feedback? Help us improve.