LLM Rewards
A lean, modular reward functions for RLHF training with LLMs. Framework-agnostic design with built-in support for trlx, trl, and custom training loops.
Install
pip install -e .
Quick Start
from llm_rewards import RewardModel, SimpleThinkReward, LengthReward, XMLReward, create_reward_fn
# Create reward stack
rewards = [
LengthReward(target_length=1024, weight=0.1),
XMLReward(weight=0.5, partial_credit=True),
RewardModel("your/reward/model", weight=1.0),
SimpleThinkReward(weight=0.5)
]
# Get framework-agnostic reward function
reward_fn = create_reward_fn(rewards, normalize=True)
# Use with trlx
from trlx import Trainer
trainer = Trainer(reward_fn=reward_fn)
trainer.train(...)
Key Features
- Transformer reward models
- Reasoning validation (ThinkingReward)
- Length, format, XML validation
- Reference similarity
- Prompt relevance
- Framework adapters
- Batched inference
- Reward normalization
Example Training Script
See example/train_example.py for full Qwen-2.5 0.5B training example.
Custom Rewards
from llm_rewards import RewardFunction, RewardOutput
class MyReward(RewardFunction):
def compute(self, texts, **kwargs) -> RewardOutput:
rewards = [score(text) for text in texts]
return RewardOutput(values=torch.tensor(rewards))
License
MIT
Metadata
Release files for llm-rewards 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| llm_rewards-0.0.1.tar.gz | 12.1 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| llm_rewards-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.4 kB
Release files / llm_rewards-0.0.1.tar.gz
| Download URL | llm_rewards-0.0.1.tar.gz |
|---|---|
| Size | 12.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ff76c39da6c6ec3010a41df2ee9f1466b2daf5ee6e0aab158110e620ca15310b
|
|
BLAKE2b-256 checksum How to use checksums |
0de35a8f721d6de20a5dd8a51e17a2800397496e07c19a2f941684ccc7ea7d16
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 26, 2025.
Transparency logRelease files / llm_rewards-0.0.1-py3-none-any.whl
| Download URL | llm_rewards-0.0.1-py3-none-any.whl |
|---|---|
| Size | 11.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a5ac23bd8081e927c670f0852b5858f367dc861c46e7160e9792fc59b6e863cf
|
|
BLAKE2b-256 checksum How to use checksums |
ea5e1f2a20f19497833958535d35efd8bf2695141f9f017c5837d0c82c651cfa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 26, 2025.
Transparency logSecurity for llm-rewards 0.0.1
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for llm_rewards-0.0.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 26, 2025.
Transparency logA 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.