Skip to main content

RLlama

RLlama Logo

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

Metadata

Release files for rllama 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rllama 0.7.0
File Size Uploaded Provenance Actions
rllama-0.7.0.tar.gz 1.1 MB Without provenance Details for rllama-0.7.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rllama 0.7.0
File Interpreter ABI Platform Actions
rllama-0.7.0-py3-none-any.whl Python 3 none any Details for rllama-0.7.0-py3-none-any.whl

Total release size: 1.2 MB

Release files / rllama-0.7.0.tar.gz

Download URL rllama-0.7.0.tar.gz
Size 1.1 MB
Tags Source
SHA-256 checksum
How to use checksums
400a3573eecc6378f30790d64ff42a69ecd1f3b1047dba3cd840aab902f8f197
BLAKE2b-256 checksum
How to use checksums
d26e42c118d2f5f45cc9b7d9cc3efcb61a91bb34a50c2cad67645d740d4382a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.6

Release files / rllama-0.7.0-py3-none-any.whl

Download URL rllama-0.7.0-py3-none-any.whl
Size 60.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c8d9f5435ccf40e79c10372e09762e3a31193aa505a3c76c1b92fe7d088b047a
BLAKE2b-256 checksum
How to use checksums
af1e3d0240f1f35ded2ca840e8bf2ef2b7c5c3b932defc5d3f8cf506e7d31641
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.6

Security for rllama 0.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page