pyreft  by stanfordnlp

Python library for representation finetuning (ReFT) of language models

Created 1 year ago
1,513 stars

Top 27.4% on SourcePulse

GitHubView on GitHub
Project Summary

Stanford's pyreft library enables Representation Fine-Tuning (ReFT), a novel approach to adapting large language models by intervening on specific token representations rather than modifying model weights directly. This method allows for more targeted and efficient fine-tuning, particularly for tasks requiring nuanced control over model behavior, and is designed for researchers and practitioners working with HuggingFace Transformers.

How It Works

ReFT distinguishes itself from methods like LoRA or Adapters by selecting specific timesteps (tokens) for intervention and targeting internal representations. This allows for fine-grained control, such as applying modifications only to the first or last token's representation, or even to specific linear subspaces. This approach offers greater flexibility and interpretability in model adaptation, enabling complex interventions that are difficult or impossible with weight-based methods.

Quick Start & Requirements

  • Install via pip: pip install pyreft or pip install git+https://github.com/stanfordnlp/pyreft.git
  • Requires Python, HuggingFace Transformers, and PyTorch. GPU with CUDA is recommended for performance.
  • Official quick-start guide and live demo available.

Highlighted Details

  • Enables parameter-efficient fine-tuning with minimal trainable parameters (e.g., 32,772 for a rank-4 LoReFT).
  • Supports integration with HuggingFace's PEFT library for combined LoRA and ReFT training.
  • Facilitates easy sharing of fine-tuned models via HuggingFace Hub.
  • Offers Gradio deployment options and hosts several example models.

Maintenance & Community

  • Developed by Stanford NLP.
  • Links to HuggingFace spaces for demos and examples.

Licensing & Compatibility

  • No explicit license mentioned in the README. Compatibility for commercial use or closed-source linking is not specified.

Limitations & Caveats

The README does not specify a license, which may impact commercial adoption. While the library aims for efficiency, the effectiveness of ReFT on unseen prompts may vary, as noted in the example where generalization is tested.

Health Check
Last Commit

7 months ago

Responsiveness

1 day

Pull Requests (30d)
0
Issues (30d)
4
Star History
9 stars in the last 30 days

Explore Similar Projects

Starred by Tobi Lutke Tobi Lutke(Cofounder of Shopify), Yineng Zhang Yineng Zhang(Inference Lead at SGLang; Research Scientist at Together AI), and
26 more.

axolotl by axolotl-ai-cloud

0.5%
10k
CLI tool for streamlined post-training of AI models
Created 2 years ago
Updated 13 hours ago
Feedback? Help us improve.