A Composable Reward Engineering Framework for Reinforcement Learning
Project description
RLlama
A composable reward engineering framework for reinforcement learning.
Features
- 🧩 Modular Reward Components: Mix and match reward functions to shape agent behavior
- 🔍 Reward Optimization: Automatically tune reward weights with Bayesian optimization
- 🧠 Memory Systems: Episodic and working memory for improved agent capabilities
- 📊 Visualization Tools: Track and analyze reward contributions
- 🔗 RL Library Integration: Seamless integration with OpenAI Gym and Stable Baselines3
- 💬 RLHF Support: Tools for Reinforcement Learning from Human Feedback
- 🌐 Neural Network Reward Models: Deep learning based reward modeling
- 🎛️ Reward Normalization: Multiple strategies for normalizing rewards
Installation
# Install from PyPI
pip install rllama
# Install with all optional dependencies
pip install "rllama[all]"
# Install in development mode
git clone https://github.com/ch33nchanyes/rllama.git
cd rllama
pip install -e ".[dev]"
Quick Start
Python
from rllama import RewardEngine
# Initialize the reward engine with a config file
engine = RewardEngine('path/to/config.yaml')
# Use the engine to compute rewards
context = {"response": "This is a test response"}
reward = engine.compute(context)
print(f"Computed reward: {reward}")
Configuration
RLlama uses YAML configuration files to specify reward components and their parameters:
YAML
reward_components:
- name: LengthReward
params:
target_length: 100
strength: 0.001
- name: DiversityReward
params:
history_size: 10
strength: 0.5
shaping_config:
LengthReward:
weight: 0.5
DiversityReward:
weight: 1.0
logging:
log_dir: ./reward_logs
log_frequency: 100
Available Reward Components
RLlama includes many built-in reward components:
Basic Components
LengthReward: Rewards based on response length
ConstantReward: Provides a fixed reward value
DiversityReward: Rewards diversity in actions or outputs
Advanced Components
CuriosityReward: Rewards exploration of novel states
ProgressReward: Rewards progress toward a goal
AdaptiveClippingReward: Adaptively clips rewards
GradualCurriculumReward: Increases difficulty progressively
MetaLearningReward: Adapts to agent's learning progress
HindsightExperienceReward: Implements hindsight experience replay
Neural Network Reward Models
RLlama supports neural network-based reward models:
Python
from rllama.models import MLPRewardModel, RewardModelTrainer
import torch
# Create a reward model
model = MLPRewardModel(input_dim=8, hidden_dims=[64, 32])
# Train the model
trainer = RewardModelTrainer(model=model)
trainer.train(train_loader, val_loader, epochs=50)
Reinforcement Learning from Human Feedback (RLHF)
Learn reward models from human preferences:
Python
from rllama.rlhf import PreferenceTrainer, PreferenceDataset
from rllama.models import MLPRewardModel
# Create preference dataset
dataset = PreferenceDataset(states_a, states_b, preferences)
# Train model from preferences
model = MLPRewardModel(input_dim=8)
trainer = PreferenceTrainer(model=model)
trainer.train(train_loader, val_loader, epochs=50)
Documentation
For detailed documentation, please see:
Concepts: Core concepts and architecture
Usage Guide: Detailed usage instructions
Reward Cookbook: Recipes for common reward functions
Optimization Guide: Guide to reward optimization
License
MIT License
Copyright (c) 2025 Srinivas
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
rllama-0.7.0.tar.gz
(1.1 MB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
rllama-0.7.0-py3-none-any.whl
(60.8 kB
view details)
File details
Details for the file rllama-0.7.0.tar.gz.
File metadata
- Download URL: rllama-0.7.0.tar.gz
- Upload date:
- Size: 1.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
400a3573eecc6378f30790d64ff42a69ecd1f3b1047dba3cd840aab902f8f197
|
|
| MD5 |
c814c2843d573159cbe4f74699a0d530
|
|
| BLAKE2b-256 |
d26e42c118d2f5f45cc9b7d9cc3efcb61a91bb34a50c2cad67645d740d4382a7
|
File details
Details for the file rllama-0.7.0-py3-none-any.whl.
File metadata
- Download URL: rllama-0.7.0-py3-none-any.whl
- Upload date:
- Size: 60.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8d9f5435ccf40e79c10372e09762e3a31193aa505a3c76c1b92fe7d088b047a
|
|
| MD5 |
19f63f7a537236d74da7f4d3b35e707c
|
|
| BLAKE2b-256 |
af1e3d0240f1f35ded2ca840e8bf2ef2b7c5c3b932defc5d3f8cf506e7d31641
|