rLLM Advantage Estimator API (Experimental)
Reference for the rLLM-native advantage estimator interfaces, registry APIs, and related config types.
Registry and Collection
rllm.experimental.common.advantage.register_rllm_adv_estimator
Register a rLLM advantage estimator -- either built-in or custom.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | rLLMAdvantageEstimator
|
Name of the advantage estimator. |
required |
Source code in rllm/experimental/common/advantage.py
rllm.experimental.common.advantage.get_rllm_adv_estimator
Get a rLLM advantage estimator by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | rLLMAdvantageEstimator
|
Name of the advantage estimator. |
required |
Source code in rllm/experimental/common/advantage.py
rllm.experimental.common.advantage.collect_reward_and_advantage_from_trajectory_groups
collect_reward_and_advantage_from_trajectory_groups(groups: list[TrajectoryGroup], algorithm_config: AlgorithmConfig, collect_advantage: bool = True) -> dict
Collect reward and advantage from trajectory groups. Return a dictionary of metrics. If collect_advantage is False, only collect rewards.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
groups
|
list[TrajectoryGroup]
|
List of TrajectoryGroup objects |
required |
algorithm_config
|
AlgorithmConfig
|
Algorithm configuration |
required |
collect_advantage
|
bool
|
Whether to collect advantage |
True
|
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary of metrics |
Source code in rllm/experimental/common/advantage.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
Built-in Estimators
rllm.experimental.common.advantage.calculate_grpo_advantages
calculate_grpo_advantages(rewards: list[ndarray], norm_adv_by_std_in_grpo=True, episilon=1e-06, **kwargs) -> tuple[list[np.ndarray], list[np.ndarray]]
Source code in rllm/experimental/common/advantage.py
rllm.experimental.common.advantage.calculate_reinforce_advantages
calculate_reinforce_advantages(rewards: list[ndarray], **kwargs) -> tuple[list[np.ndarray], list[np.ndarray]]
REINFORCE: advantage = reward (no baseline)
Source code in rllm/experimental/common/advantage.py
rllm.experimental.common.advantage.calculate_reinforce_plus_plus_baseline_advantages
calculate_reinforce_plus_plus_baseline_advantages(rewards: list[ndarray], epsilon=1e-06, **kwargs) -> tuple[list[np.ndarray], list[np.ndarray]]
REINFORCE++ baseline estimator.
In line with Verl's REINFORCE++ baseline logic for grouped rollouts: 1. Use per-group mean baseline when group size > 1, else baseline = 0. 2. Whiten centered scores using role-level batch statistics.
Source code in rllm/experimental/common/advantage.py
rllm.experimental.common.advantage.calculate_rloo_advantages
calculate_rloo_advantages(rewards: list[ndarray], **kwargs) -> tuple[list[np.ndarray], list[np.ndarray]]
Reinforce Leave-one-out (RLOO): https://arxiv.org/abs/2402.14740
Source code in rllm/experimental/common/advantage.py
Supporting Config Types
rllm.experimental.common.config.rLLMAdvantageEstimator
Bases: str, Enum
A unified advantage estimator for rLLM. Work with both tinker and verl backends at the expense of
losing some flexibility.
TODO(listar2000): add more estimators.
Source code in rllm/experimental/common/config.py
rllm.experimental.common.config.AlgorithmConfig
dataclass
Configuration for algorithm parameters.
Source code in rllm/experimental/common/config.py
from_config
classmethod
Create an AlgorithmConfig from a dictionary configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
DictConfig
|
Dictionary configuration. |
required |
Returns: AlgorithmConfig: The AlgorithmConfig built from the configuration.
Source code in rllm/experimental/common/config.py
Per-Group Algo Helpers
rllm.experimental.common.rl_algo.calculate_grpo_advantages_per_group
calculate_grpo_advantages_per_group(rewards: ndarray, norm_adv_by_std_in_grpo=True, episilon=1e-06) -> tuple[np.ndarray, np.ndarray]
Source code in rllm/experimental/common/rl_algo.py
rllm.experimental.common.rl_algo.calculate_rloo_advantages_per_group
Source code in rllm/experimental/common/rl_algo.py
UnifiedTrainer Entry Point
traj_group_adv_estimator_map is provided through trainer construction kwargs and
wired into AlgorithmConfig.estimator_map in UnifiedTrainer.
rllm.experimental.unified_trainer.UnifiedTrainer
Unified trainer for backend-agnostic training.
This trainer uses an async-prioritized design where the core pipeline methods are async. This accommodates backends that naturally use async operations (like Tinker) while still supporting sync backends.
The main fit() method remains sync for ease of use, but internally runs
the async training loop in a dedicated event loop thread.
Source code in rllm/experimental/unified_trainer.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 | |
__init__
__init__(backend_cls: type[BackendProtocol], config: DictConfig, workflow_class: type[Workflow], train_dataset: Dataset | None = None, val_dataset: Dataset | None = None, workflow_args: dict | None = None, backend_args: dict | None = None, *, traj_grouping_hook: Callable | None = None, traj_group_adv_estimator_map: dict | None = None, **kwargs)
Initialize the UnifiedTrainer.
Source code in rllm/experimental/unified_trainer.py
fit
fit_async
async
Public async entry point for the full training process.
Source code in rllm/experimental/unified_trainer.py
shutdown
Shutdown the trainer and cleanup resources.