stateset-rl-core
High-performance Rust implementations of reinforcement learning operations, with optional Python bindings via PyO3.
Features
- GAE (Generalized Advantage Estimation) - Fast, parallel GAE computation
- Advantage Computation - Group-relative advantages for GRPO/PPO training
- Reward Normalization - Welford's algorithm for numerically stable online normalization
- GSPO Support - Sequence-level importance ratios and clipping for GSPO
- PPO Surrogate - Clipped surrogate objective computation
- Parallel Processing - Automatic parallelization via Rayon
Installation
As a Python extension (recommended)
Pre-built abi3 wheels are published to PyPI on each rust-core-v* tag.
Install directly or via the [rust] extra on stateset-agents:
# Standalone
pip install stateset-rl-core
# Bundled with the framework
pip install "stateset-agents[rust]"
One wheel per (OS, arch) covers Python 3.10–3.13 via the stable PyO3 ABI. Supported targets: Linux x86_64/aarch64 (manylinux2014), macOS x86_64/arm64, Windows x86_64.
As a Rust crate
[dependencies]
stateset-rl-core = "0.1"
From source (development)
cd rust_core
maturin develop --release
Usage
Rust
use stateset_rl_core::{compute_gae_internal, compute_advantages_for_group};
// Compute GAE
let rewards = vec![1.0, 0.0, 1.0, 0.0];
let values = vec![0.5, 0.5, 0.5, 0.5, 0.0]; // n+1 values for bootstrap
let advantages = compute_gae_internal(&rewards, &values, 0.99, 0.95);
// Compute group-relative advantages
let group_rewards = vec![1.0, 2.0, 3.0, 4.0];
let advantages = compute_advantages_for_group(&group_rewards, "mean", true);
Python
import numpy as np
import stateset_rl_core
# Compute GAE
rewards = np.array([1.0, 0.0, 1.0, 0.0])
values = np.array([0.5, 0.5, 0.5, 0.5, 0.0])
advantages = stateset_rl_core.compute_gae(rewards, values, gamma=0.99, gae_lambda=0.95)
# Batch GAE (parallel)
all_rewards = [np.random.randn(100) for _ in range(32)]
all_values = [np.random.randn(101) for _ in range(32)]
all_advantages = stateset_rl_core.batch_compute_gae(all_rewards, all_values)
# Group-relative advantages for GRPO
rewards_2d = np.random.randn(16, 4) # 16 groups, 4 samples each
advantages = stateset_rl_core.compute_group_advantages(rewards_2d, "mean", normalize=True)
# Reward normalization with running stats
rewards = np.array([1.0, 2.0, 3.0])
normalized, mean, var, count = stateset_rl_core.normalize_rewards(rewards)
# GSPO importance ratios
log_probs_new = np.array([-10.0, -12.0, -11.0])
log_probs_old = np.array([-10.5, -11.5, -11.0])
seq_lengths = np.array([50, 60, 55])
ratios = stateset_rl_core.compute_gspo_importance_ratios(log_probs_new, log_probs_old, seq_lengths)
# PPO surrogate objective
ratios = np.array([1.1, 0.9, 1.05])
advantages = np.array([1.0, -1.0, 0.5])
objectives = stateset_rl_core.compute_ppo_surrogate(ratios, advantages, clip_epsilon=0.2)
API Reference
GAE Functions
compute_gae(rewards, values, gamma=0.99, gae_lambda=0.95)- Single trajectory GAEbatch_compute_gae(all_rewards, all_values, gamma=0.99, gae_lambda=0.95)- Parallel batch GAE
Advantage Functions
compute_group_advantages(rewards_2d, baseline_type, normalize)- GRPO-style group advantagesbaseline_type:"mean","median", or"min"
Reward Functions
normalize_rewards(rewards, running_mean=0, running_var=1, count=0, epsilon=1e-8)- Online normalizationclip_rewards(rewards, min_val, max_val)- Reward clippingcompute_reward_statistics(rewards)- Compute mean, std, min, max, median
Policy Gradient Functions
compute_gspo_importance_ratios(log_probs_new, log_probs_old, sequence_lengths)- GSPO ratiosapply_gspo_clipping(ratios, advantages, clip_left=3e-4, clip_right=4e-4)- GSPO clippingcompute_ppo_surrogate(ratios, advantages, clip_epsilon=0.2)- PPO clipped objective
Performance
This crate is optimized for performance:
- LTO enabled - Link-time optimization for maximum speed
- Single codegen unit - Better optimization opportunities
- Rayon parallelization - Automatic multi-threading for batch operations
- Zero-copy Python interop - Minimal overhead when called from Python
Typical speedups over pure Python/NumPy: 10-100x for batch operations.
License
BUSL-1.1
Metadata
Release files for stateset-rl-core 0.1.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 | Actions |
|---|---|---|---|---|
| stateset_rl_core-0.1.1.tar.gz | 17.9 kB | Without provenance | Details for stateset_rl_core-0.1.1.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| stateset_rl_core-0.1.1-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details for stateset_rl_core-0.1.1-cp310-abi3-win_amd64.whl |
| stateset_rl_core-0.1.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ x86-64 | Details for stateset_rl_core-0.1.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
| stateset_rl_core-0.1.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ ARM64 | Details for stateset_rl_core-0.1.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
| stateset_rl_core-0.1.1-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details for stateset_rl_core-0.1.1-cp310-abi3-macosx_11_0_arm64.whl |
| stateset_rl_core-0.1.1-cp310-abi3-macosx_10_12_x86_64.whl | CPython 3.10 | abi3 | macOS 10.12+ x86-64 | Details for stateset_rl_core-0.1.1-cp310-abi3-macosx_10_12_x86_64.whl |
Total release size: 1.3 MB
Release files / stateset_rl_core-0.1.1.tar.gz
| Download URL | stateset_rl_core-0.1.1.tar.gz |
|---|---|
| Size | 17.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1a22d3751f8f981ee1fbbf66a45d8974dbe97ac5c7c8a0696057961c5380dfc7
|
|
BLAKE2b-256 checksum How to use checksums |
d8331db1cd26ce295f791d893294c03c453255ff9da3316a1cb42e710fd05e1f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.16
|
Release files / stateset_rl_core-0.1.1-cp310-abi3-win_amd64.whl
| Download URL | stateset_rl_core-0.1.1-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 206.8 kB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
e0f603ef349d413e466f91d1761a4305ccd0e2e4b825b29d619ce3c2650f4b40
|
|
BLAKE2b-256 checksum How to use checksums |
135f45ed3ee64073ee9c20f7c629d185afbaa2c9c882af12261dd62f3ae6c1e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.16
|
Release files / stateset_rl_core-0.1.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | stateset_rl_core-0.1.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 297.3 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
7f4528422f64dcdcd9959429296f50e79d656d0d1b1fc54bc767b529ebd9a074
|
|
BLAKE2b-256 checksum How to use checksums |
227aaa7c1d1904d1c167e5dcbcf1935ac85e29e3dfcb2d6a515f2f70637fd9e1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.16
|
Release files / stateset_rl_core-0.1.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | stateset_rl_core-0.1.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 282.4 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
2f910474d97cf1752320906122212221db5d211aeb062464a448c5f9f132934d
|
|
BLAKE2b-256 checksum How to use checksums |
9312970386e99d148753f69f17859085d56690ac8794cee6391b60415e1f92f3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.16
|
Release files / stateset_rl_core-0.1.1-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | stateset_rl_core-0.1.1-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 261.8 kB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
8b9de36ecebbda123051c5a3bcf6fcfb9a95923b9d350f5aff3dcb2872db1db4
|
|
BLAKE2b-256 checksum How to use checksums |
07d9d02859a50788962b992869827d11cb902ea60b0b5dc86a93acf90144fb38
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.16
|
Release files / stateset_rl_core-0.1.1-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | stateset_rl_core-0.1.1-cp310-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 275.7 kB |
| Tags | CPython 3.10 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
701de8400fa712ef76c00eefbffb83ba808d4b3b8322eb8f1912482d2f192ae4
|
|
BLAKE2b-256 checksum How to use checksums |
448f7190ccc4eebf8e8a835330064e2601864d0cc4c8655f8dfd2c68ce1e3e8c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.16
|
Security for stateset-rl-core 0.1.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.
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.