pyreft  by stanfordnlp

Python library for representation finetuning (ReFT) of language models

created 1 year ago
1,500 stars

Top 28.1% 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

5 months ago

Responsiveness

Inactive

Pull Requests (30d)
0
Issues (30d)
1
Star History
49 stars in the last 90 days

Explore Similar Projects

Feedback? Help us improve.