Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -46,7 +46,7 @@ pipeline_tag: reinforcement-learning
|
|
| 46 |
- [Asynchronous Sequence Diagram](#asynchronous-sequence-diagram)
|
| 47 |
- [Zero-Copy In-VRAM vs. Traditional Host-Device Roundtrip](#zero-copy-in-vram-vs-traditional-host-device-roundtrip)
|
| 48 |
- [3. Theoretical Foundations & Mathematical Formulations](#3-theoretical-foundations--mathematical-formulations)
|
| 49 |
-
- [3.1 Policy Gradient under Asynchronous Staleness
|
| 50 |
- [3.2 Proximal Policy Optimization (PPO)](#32-proximal-policy-optimization-ppo)
|
| 51 |
- [3.3 Second-Moment Trust Region Optimization (M2PO)](#33-second-moment-trust-region-optimization-m2po)
|
| 52 |
- [3.4 Group Relative Policy Optimization (GRPO)](#34-group-relative-policy-optimization-grpo)
|
|
@@ -59,15 +59,10 @@ pipeline_tag: reinforcement-learning
|
|
| 59 |
- [5.5 Orchestration & Version Management (`src/orchestrator/`)](#55-orchestration--version-management-srcorchestrator)
|
| 60 |
- [6. Installation & Environment Setup](#6-installation--environment-setup)
|
| 61 |
- [7. Verification & Benchmarking](#7-verification--benchmarking)
|
| 62 |
-
- [7.1 Running the 41-Test Comprehensive Suite](#71-running-the-41-test-comprehensive-suite)
|
| 63 |
-
- [7.2 Hardware Benchmarks on NVIDIA RTX 4070 GPU](#72-hardware-benchmarks-on-nvidia-rtx-4070-gpu)
|
| 64 |
- [8. Developer Cookbook: Extending the Framework](#8-developer-cookbook-extending-the-framework)
|
| 65 |
-
|
| 66 |
-
- [Recipe 2: Implementing Custom In-VRAM Reward Logic](#recipe-2-implementing-custom-in-vram-reward-logic)
|
| 67 |
-
- [Recipe 3: Distributed Multi-GPU Execution with Ray](#recipe-3-distributed-multi-gpu-execution-with-ray)
|
| 68 |
-
- [9. Configuration Dictionary](#9-configuration-dictionary)
|
| 69 |
- [10. Frequently Asked Questions (FAQ) & Troubleshooting](#10-frequently-asked-questions-faq--troubleshooting)
|
| 70 |
-
- [11.
|
| 71 |
- [12. License](#12-license)
|
| 72 |
|
| 73 |
---
|
|
@@ -76,7 +71,7 @@ pipeline_tag: reinforcement-learning
|
|
| 76 |
|
| 77 |
### The Traditional Synchronous RLHF Bottleneck
|
| 78 |
|
| 79 |
-
Reinforcement Learning from Human Feedback (RLHF)
|
| 80 |
|
| 81 |
1. **The CPU-GPU Memory Wall (SerDes Overhead)**:
|
| 82 |
Rollout generates token sequences on the GPU. Standard reward computation then:
|
|
@@ -84,11 +79,15 @@ Reinforcement Learning from Human Feedback (RLHF) has emerged as the standard pa
|
|
| 84 |
- Decodes IDs into UTF-8 strings (`tokenizer.decode()`).
|
| 85 |
- Runs Python string matching, regular expressions, or rule-based scoring on the host CPU.
|
| 86 |
- Converts scalar scores back into PyTorch tensors and transfers them across PCIe back into GPU memory (`.cuda()`).
|
| 87 |
-
In high-throughput generation regimes (batch size
|
| 88 |
|
| 89 |
2. **The Synchronous Lockstep Barrier (GPU Underutilization)**:
|
| 90 |
In synchronous PPO, rollout generation and trainer parameter optimization run in strict lockstep:
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
While the trainer runs backpropagation, rollout GPU workers sit completely idle. Conversely, while rollout workers generate tokens autoregressively, training GPUs idle waiting for batches. This lockstep barrier causes severe GPU idle time ("bubble overhead"), frequently exceeding 40–60% of total cluster compute time.
|
| 93 |
|
| 94 |
```
|
|
@@ -108,8 +107,8 @@ Trainer GPU: [...... IDLE ......] [==== TRAIN ====] [...... IDLE ......] [====
|
|
| 108 |
|
| 109 |
2. **Asynchronous Continuous Rollout with Second-Moment Staleness Control (M2PO)**:
|
| 110 |
Rollout workers continuously generate responses into a non-blocking, thread-safe experience replay buffer. The trainer continuously samples from the buffer and optimizes the policy. To handle the resulting off-policy divergence $\theta - \theta_{\text{old}}$, the framework incorporates:
|
| 111 |
-
- Dynamic staleness eviction: Experiences with age $\tau = v_{\text{current}} - v_{\text{data}}
|
| 112 |
-
- M2PO Second-Moment Trust Region Loss: Dynamically bounds the second moment of the importance weight $\mathbb{E}[r
|
| 113 |
- Group-Aware Buffers for GRPO: Standardizes advantage estimates across groups of candidate generations per prompt.
|
| 114 |
|
| 115 |
```
|
|
@@ -201,15 +200,25 @@ Rollout Engine Buffer Trainer VersionManag
|
|
| 201 |
|
| 202 |
## 3. Theoretical Foundations & Mathematical Formulations
|
| 203 |
|
| 204 |
-
### 3.1 Policy Gradient under Asynchronous Staleness
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
|
| 206 |
-
|
|
|
|
|
|
|
| 207 |
|
| 208 |
-
|
| 209 |
-
$$g(\theta) = \mathbb{E}_{(x,y) \sim \mathcal{D}}\left[ \frac{\nabla_\theta \pi_\theta(y|x)}{\pi_{\theta_{\text{old}}}(y|x)} A^{\pi_{\theta_{\text{old}}}}(x, y) \right]$$
|
| 210 |
|
| 211 |
-
|
| 212 |
-
|
|
|
|
| 213 |
|
| 214 |
If $\tau$ grows without constraint, standard PPO clipping $\text{clip}(r_t(\theta), 1-\epsilon, 1+\epsilon)$ saturates, causing vanishing gradient updates on fresh tokens and destructive updates on stale outliers.
|
| 215 |
|
|
@@ -217,21 +226,33 @@ If $\tau$ grows without constraint, standard PPO clipping $\text{clip}(r_t(\thet
|
|
| 217 |
|
| 218 |
AsyncTensorRLHF implements clipped PPO with per-token importance weighting:
|
| 219 |
|
| 220 |
-
$$
|
|
|
|
|
|
|
| 221 |
|
| 222 |
-
where:
|
| 223 |
-
|
|
|
|
|
|
|
|
|
|
| 224 |
|
| 225 |
### 3.3 Second-Moment Trust Region Optimization (M2PO)
|
| 226 |
|
| 227 |
To guarantee stability under asynchronous rollout where $\tau \in [1, \tau_{\text{max}}]$, AsyncTensorRLHF incorporates **M2PO** (Second-Moment Trust Region Policy Optimization). M2PO constrains the empirical second moment of the importance weight:
|
| 228 |
|
| 229 |
-
$$
|
|
|
|
|
|
|
| 230 |
|
| 231 |
Tokens whose importance weight violates the second-moment threshold $r_{b,t}(\theta)^2 \ge \gamma_{\text{threshold}}$ are masked:
|
| 232 |
|
| 233 |
-
$$
|
| 234 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
|
| 236 |
This eliminates destructive gradient spikes caused by stale off-policy rollouts without stalling generation.
|
| 237 |
|
|
@@ -239,11 +260,19 @@ This eliminates destructive gradient spikes caused by stale off-policy rollouts
|
|
| 239 |
|
| 240 |
For mathematical, programmatic, and structured reasoning tasks (e.g. DeepSeek-Math, DeepSeek-R1), AsyncTensorRLHF implements **GRPO**. GRPO foregoes a learned critic model and instead normalizes advantages within a group of $G$ responses generated for the identical prompt $x$:
|
| 241 |
|
| 242 |
-
$$
|
| 243 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
|
| 245 |
The GRPO objective is:
|
| 246 |
-
|
|
|
|
|
|
|
|
|
|
| 247 |
|
| 248 |
When all responses in a group receive identical rewards (e.g., all correct $R_i=1$ or all wrong $R_i=0$), $\sigma_g \to 0$. AsyncTensorRLHF's implementation adds numerical smoothing ($\epsilon = 10^{-8}$) to ensure $\hat{A}_{g,i} \to 0$ without `NaN` or `Inf` divergence.
|
| 249 |
|
|
@@ -496,10 +525,10 @@ ALL VERIFICATIONS AND BENCHMARKS COMPLETED SUCCESSFULLY (EXIT 0)
|
|
| 496 |
|
| 497 |
#### Detailed Hardware Benchmark Profiles:
|
| 498 |
|
| 499 |
-
##### A. Policy Loss & Backpropagation Throughput (
|
| 500 |
| Algorithm | Forward + Backward Latency | Effective Throughput | Status |
|
| 501 |
|---|:---:|:---:|:---:|
|
| 502 |
-
| **GRPO (
|
| 503 |
| **PPO (Standard Clipped)** | **2.42 ms** | **6,763,177 tokens / sec** | **PASSED** |
|
| 504 |
| **M2PO (Second-Moment Trust Region)** | **5.98 ms** | **2,739,289 tokens / sec** | **PASSED** |
|
| 505 |
|
|
@@ -509,15 +538,15 @@ ALL VERIFICATIONS AND BENCHMARKS COMPLETED SUCCESSFULLY (EXIT 0)
|
|
| 509 |
| **Push (`BoundedReplayBuffer`)** | 20,000 experience items | **312,283 ops / sec** | 0.0032 ms / push |
|
| 510 |
| **Sample Batch (`batch_size=64`)** | 20,000 experience items | **411,691 items / sec** | 0.0024 ms / item |
|
| 511 |
|
| 512 |
-
##### C. Asynchronous Staleness (
|
| 513 |
-
| Policy Staleness (
|
| 514 |
|:---:|:---:|:---:|:---:|
|
| 515 |
-
|
|
| 516 |
-
|
|
| 517 |
-
|
|
| 518 |
-
|
|
| 519 |
-
|
|
| 520 |
-
|
|
| 521 |
|
| 522 |
|
| 523 |
---
|
|
@@ -607,8 +636,8 @@ Sample configuration file from `configs/phase2_async.yaml`:
|
|
| 607 |
| `rollout.batch_size` | `int` | `64` | Number of concurrent prompts processed per rollout worker |
|
| 608 |
| `rollout.max_new_tokens` | `int` | `512` | Maximum generation length |
|
| 609 |
| `trainer.loss_type` | `str` | `"m2po"` | Policy optimization loss: `"ppo"`, `"m2po"`, or `"grpo"` |
|
| 610 |
-
| `trainer.clip_eps` | `float` | `0.2` | PPO clipping parameter
|
| 611 |
-
| `trainer.m2_threshold` | `float` | `2.0` | M2PO second-moment trust-region constraint
|
| 612 |
| `trainer.learning_rate` | `float` | `1.0e-5` | AdamW learning rate |
|
| 613 |
|
| 614 |
---
|
|
@@ -625,7 +654,7 @@ Sample configuration file from `configs/phase2_async.yaml`:
|
|
| 625 |
**A:** `VLLMEngineWrapper` automatically falls back to `HFEngine` (which runs autoregressive inference using native PyTorch/Transformers on CUDA or CPU) or `StubEngine` (for testing).
|
| 626 |
|
| 627 |
**Q: How does M2PO prevent training collapse with stale data?**
|
| 628 |
-
**A:** Stale data produces outlier importance ratios $r_t(\theta) \gg 1$. M2PO tracks the second moment $\mathbb{E}[r_t(\theta)^2]$ across tokens and masks out elements exceeding
|
| 629 |
|
| 630 |
---
|
| 631 |
|
|
|
|
| 46 |
- [Asynchronous Sequence Diagram](#asynchronous-sequence-diagram)
|
| 47 |
- [Zero-Copy In-VRAM vs. Traditional Host-Device Roundtrip](#zero-copy-in-vram-vs-traditional-host-device-roundtrip)
|
| 48 |
- [3. Theoretical Foundations & Mathematical Formulations](#3-theoretical-foundations--mathematical-formulations)
|
| 49 |
+
- [3.1 Policy Gradient under Asynchronous Staleness (τ)](#31-policy-gradient-under-asynchronous-staleness-τ)
|
| 50 |
- [3.2 Proximal Policy Optimization (PPO)](#32-proximal-policy-optimization-ppo)
|
| 51 |
- [3.3 Second-Moment Trust Region Optimization (M2PO)](#33-second-moment-trust-region-optimization-m2po)
|
| 52 |
- [3.4 Group Relative Policy Optimization (GRPO)](#34-group-relative-policy-optimization-grpo)
|
|
|
|
| 59 |
- [5.5 Orchestration & Version Management (`src/orchestrator/`)](#55-orchestration--version-management-srcorchestrator)
|
| 60 |
- [6. Installation & Environment Setup](#6-installation--environment-setup)
|
| 61 |
- [7. Verification & Benchmarking](#7-verification--benchmarking)
|
|
|
|
|
|
|
| 62 |
- [8. Developer Cookbook: Extending the Framework](#8-developer-cookbook-extending-the-framework)
|
| 63 |
+
- [9. Configuration Reference](#9-configuration-reference)
|
|
|
|
|
|
|
|
|
|
| 64 |
- [10. Frequently Asked Questions (FAQ) & Troubleshooting](#10-frequently-asked-questions-faq--troubleshooting)
|
| 65 |
+
- [11. Research Paper & BibTeX Citation](#11-research-paper--bibtex-citation)
|
| 66 |
- [12. License](#12-license)
|
| 67 |
|
| 68 |
---
|
|
|
|
| 71 |
|
| 72 |
### The Traditional Synchronous RLHF Bottleneck
|
| 73 |
|
| 74 |
+
Modern Reinforcement Learning from Human Feedback (RLHF) for Large Language Models (LLMs)—including Proximal Policy Optimization (PPO) and Group Relative Policy Optimization (GRPO)—faces two critical engineering bottlenecks:
|
| 75 |
|
| 76 |
1. **The CPU-GPU Memory Wall (SerDes Overhead)**:
|
| 77 |
Rollout generates token sequences on the GPU. Standard reward computation then:
|
|
|
|
| 79 |
- Decodes IDs into UTF-8 strings (`tokenizer.decode()`).
|
| 80 |
- Runs Python string matching, regular expressions, or rule-based scoring on the host CPU.
|
| 81 |
- Converts scalar scores back into PyTorch tensors and transfers them across PCIe back into GPU memory (`.cuda()`).
|
| 82 |
+
In high-throughput generation regimes (batch size ≥ 64, sequence length ≥ 1024), CPU serialization and PCIe roundtrips introduce severe throughput degradation, consuming up to 30–50% of the entire pipeline duration.
|
| 83 |
|
| 84 |
2. **The Synchronous Lockstep Barrier (GPU Underutilization)**:
|
| 85 |
In synchronous PPO, rollout generation and trainer parameter optimization run in strict lockstep:
|
| 86 |
+
|
| 87 |
+
```
|
| 88 |
+
Rollout(π_θ_t) ──▶ Reward Evaluation ──▶ Train Step(θ_t+1) ──▶ Wait for Rollout
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
While the trainer runs backpropagation, rollout GPU workers sit completely idle. Conversely, while rollout workers generate tokens autoregressively, training GPUs idle waiting for batches. This lockstep barrier causes severe GPU idle time ("bubble overhead"), frequently exceeding 40–60% of total cluster compute time.
|
| 92 |
|
| 93 |
```
|
|
|
|
| 107 |
|
| 108 |
2. **Asynchronous Continuous Rollout with Second-Moment Staleness Control (M2PO)**:
|
| 109 |
Rollout workers continuously generate responses into a non-blocking, thread-safe experience replay buffer. The trainer continuously samples from the buffer and optimizes the policy. To handle the resulting off-policy divergence $\theta - \theta_{\text{old}}$, the framework incorporates:
|
| 110 |
+
- Dynamic staleness eviction: Experiences with age $\tau = v_{\text{current}} - v_{\text{data}} \gt \tau_{\text{max}}$ are immediately discarded.
|
| 111 |
+
- M2PO Second-Moment Trust Region Loss: Dynamically bounds the second moment of the importance weight $\mathbb{E}[r(\theta)^2]$, preventing policy collapse under asynchronous drift.
|
| 112 |
- Group-Aware Buffers for GRPO: Standardizes advantage estimates across groups of candidate generations per prompt.
|
| 113 |
|
| 114 |
```
|
|
|
|
| 200 |
|
| 201 |
## 3. Theoretical Foundations & Mathematical Formulations
|
| 202 |
|
| 203 |
+
### 3.1 Policy Gradient under Asynchronous Staleness (τ)
|
| 204 |
+
|
| 205 |
+
In a distributed asynchronous RLHF pipeline, an experience tuple $(x, y, r, \log \pi_{\theta_{\text{old}}}(y \mid x))$ collected at policy version $\theta_{\text{old}}$ is consumed by the trainer at parameter version $\theta_{\text{current}}$, where staleness is defined as:
|
| 206 |
+
|
| 207 |
+
$$
|
| 208 |
+
\tau = \text{version}(\theta_{\text{current}}) - \text{version}(\theta_{\text{old}}) \ge 0
|
| 209 |
+
$$
|
| 210 |
+
|
| 211 |
+
The policy gradient under importance sampling is:
|
| 212 |
|
| 213 |
+
$$
|
| 214 |
+
g(\theta) = \mathbb{E}_{(x,y) \sim \mathcal{D}}\left[ \frac{\nabla_\theta \pi_\theta(y \mid x)}{\pi_{\theta_{\text{old}}}(y \mid x)} A^{\pi_{\theta_{\text{old}}}}(x, y) \right]
|
| 215 |
+
$$
|
| 216 |
|
| 217 |
+
When staleness $\tau \gt 0$, the importance sampling weight $r_t(\theta) = \frac{\pi_\theta(y_t \mid x, y_{\lt t})}{\pi_{\theta_{\text{old}}}(y_t \mid x, y_{\lt t})}$ exhibits high variance:
|
|
|
|
| 218 |
|
| 219 |
+
$$
|
| 220 |
+
\text{Var}_{y \sim \pi_{\theta_{\text{old}}}}[r_t(\theta)] \approx \exp\left( D_{\chi^2}(\pi_\theta \parallel \pi_{\theta_{\text{old}}}) \right) - 1
|
| 221 |
+
$$
|
| 222 |
|
| 223 |
If $\tau$ grows without constraint, standard PPO clipping $\text{clip}(r_t(\theta), 1-\epsilon, 1+\epsilon)$ saturates, causing vanishing gradient updates on fresh tokens and destructive updates on stale outliers.
|
| 224 |
|
|
|
|
| 226 |
|
| 227 |
AsyncTensorRLHF implements clipped PPO with per-token importance weighting:
|
| 228 |
|
| 229 |
+
$$
|
| 230 |
+
\mathcal{L}_{\text{PPO}}(\theta) = -\frac{1}{B \cdot L} \sum_{b=1}^B \sum_{t=1}^L \min\left( r_{b,t}(\theta) A_{b,t}, \; \text{clip}(r_{b,t}(\theta), 1-\epsilon, 1+\epsilon) A_{b,t} \right)
|
| 231 |
+
$$
|
| 232 |
|
| 233 |
+
where the per-token importance weight ratio is:
|
| 234 |
+
|
| 235 |
+
$$
|
| 236 |
+
r_{b,t}(\theta) = \exp\left( \log \pi_\theta(y_{b,t} \mid x_b, y_{b, \lt t}) - \log \pi_{\theta_{\text{old}}}(y_{b,t} \mid x_b, y_{b, \lt t}) \right)
|
| 237 |
+
$$
|
| 238 |
|
| 239 |
### 3.3 Second-Moment Trust Region Optimization (M2PO)
|
| 240 |
|
| 241 |
To guarantee stability under asynchronous rollout where $\tau \in [1, \tau_{\text{max}}]$, AsyncTensorRLHF incorporates **M2PO** (Second-Moment Trust Region Policy Optimization). M2PO constrains the empirical second moment of the importance weight:
|
| 242 |
|
| 243 |
+
$$
|
| 244 |
+
M_2 = \frac{1}{B \cdot L} \sum_{b=1}^B \sum_{t=1}^L r_{b,t}(\theta)^2
|
| 245 |
+
$$
|
| 246 |
|
| 247 |
Tokens whose importance weight violates the second-moment threshold $r_{b,t}(\theta)^2 \ge \gamma_{\text{threshold}}$ are masked:
|
| 248 |
|
| 249 |
+
$$
|
| 250 |
+
m_{b,t} = \mathbb{I}\left( r_{b,t}(\theta)^2 \lt \gamma_{\text{threshold}} \right)
|
| 251 |
+
$$
|
| 252 |
+
|
| 253 |
+
$$
|
| 254 |
+
\mathcal{L}_{\text{M2PO}}(\theta) = -\frac{\sum_{b=1}^B \sum_{t=1}^L m_{b,t} \cdot \min\left( r_{b,t}(\theta) A_{b,t}, \; \text{clip}(r_{b,t}(\theta), 1-\epsilon, 1+\epsilon) A_{b,t} \right)}{\max\left(1, \sum_{b=1}^B \sum_{t=1}^L m_{b,t}\right)}
|
| 255 |
+
$$
|
| 256 |
|
| 257 |
This eliminates destructive gradient spikes caused by stale off-policy rollouts without stalling generation.
|
| 258 |
|
|
|
|
| 260 |
|
| 261 |
For mathematical, programmatic, and structured reasoning tasks (e.g. DeepSeek-Math, DeepSeek-R1), AsyncTensorRLHF implements **GRPO**. GRPO foregoes a learned critic model and instead normalizes advantages within a group of $G$ responses generated for the identical prompt $x$:
|
| 262 |
|
| 263 |
+
$$
|
| 264 |
+
\mu_g = \frac{1}{G} \sum_{i=1}^G R_{g,i}, \qquad \sigma_g = \sqrt{\frac{1}{G} \sum_{i=1}^G (R_{g,i} - \mu_g)^2} + \epsilon_{\text{eps}}
|
| 265 |
+
$$
|
| 266 |
+
|
| 267 |
+
$$
|
| 268 |
+
\hat{A}_{g,i} = \frac{R_{g,i} - \mu_g}{\sigma_g}
|
| 269 |
+
$$
|
| 270 |
|
| 271 |
The GRPO objective is:
|
| 272 |
+
|
| 273 |
+
$$
|
| 274 |
+
\mathcal{L}_{\text{GRPO}}(\theta) = -\frac{1}{B \cdot G \cdot L} \sum_{b=1}^B \sum_{i=1}^G \sum_{t=1}^L \min\left( r_{b,i,t}(\theta) \hat{A}_{b,i}, \; \text{clip}(r_{b,i,t}(\theta), 1-\epsilon, 1+\epsilon) \hat{A}_{b,i} \right)
|
| 275 |
+
$$
|
| 276 |
|
| 277 |
When all responses in a group receive identical rewards (e.g., all correct $R_i=1$ or all wrong $R_i=0$), $\sigma_g \to 0$. AsyncTensorRLHF's implementation adds numerical smoothing ($\epsilon = 10^{-8}$) to ensure $\hat{A}_{g,i} \to 0$ without `NaN` or `Inf` divergence.
|
| 278 |
|
|
|
|
| 525 |
|
| 526 |
#### Detailed Hardware Benchmark Profiles:
|
| 527 |
|
| 528 |
+
##### A. Policy Loss & Backpropagation Throughput (Batch = 64, Length = 256)
|
| 529 |
| Algorithm | Forward + Backward Latency | Effective Throughput | Status |
|
| 530 |
|---|:---:|:---:|:---:|
|
| 531 |
+
| **GRPO (Group Size G = 4)** | **2.03 ms** | **8,058,669 tokens / sec** | **PASSED** |
|
| 532 |
| **PPO (Standard Clipped)** | **2.42 ms** | **6,763,177 tokens / sec** | **PASSED** |
|
| 533 |
| **M2PO (Second-Moment Trust Region)** | **5.98 ms** | **2,739,289 tokens / sec** | **PASSED** |
|
| 534 |
|
|
|
|
| 538 |
| **Push (`BoundedReplayBuffer`)** | 20,000 experience items | **312,283 ops / sec** | 0.0032 ms / push |
|
| 539 |
| **Sample Batch (`batch_size=64`)** | 20,000 experience items | **411,691 items / sec** | 0.0024 ms / item |
|
| 540 |
|
| 541 |
+
##### C. Asynchronous Staleness (τ) vs. Gradient Variance Reduction
|
| 542 |
+
| Policy Staleness (τ) | PPO Gradient Norm | M2PO Gradient Norm | Variance Reduction (%) |
|
| 543 |
|:---:|:---:|:---:|:---:|
|
| 544 |
+
| τ = 0 (On-policy synchronous) | 0.0218 | 0.0218 | **0.0%** |
|
| 545 |
+
| τ = 1 | 0.0212 | 0.0212 | **0.0%** |
|
| 546 |
+
| τ = 2 | 0.0202 | 0.0201 | **0.3%** |
|
| 547 |
+
| τ = 3 | 0.0221 | 0.0204 | **7.7%** |
|
| 548 |
+
| τ = 5 | 0.0265 | 0.0198 | **25.6%** |
|
| 549 |
+
| τ = 8 (Extreme asynchronous drift) | 0.0502 | 0.0190 | **62.1%** |
|
| 550 |
|
| 551 |
|
| 552 |
---
|
|
|
|
| 636 |
| `rollout.batch_size` | `int` | `64` | Number of concurrent prompts processed per rollout worker |
|
| 637 |
| `rollout.max_new_tokens` | `int` | `512` | Maximum generation length |
|
| 638 |
| `trainer.loss_type` | `str` | `"m2po"` | Policy optimization loss: `"ppo"`, `"m2po"`, or `"grpo"` |
|
| 639 |
+
| `trainer.clip_eps` | `float` | `0.2` | PPO clipping parameter ε (epsilon) |
|
| 640 |
+
| `trainer.m2_threshold` | `float` | `2.0` | M2PO second-moment trust-region constraint γ (gamma) |
|
| 641 |
| `trainer.learning_rate` | `float` | `1.0e-5` | AdamW learning rate |
|
| 642 |
|
| 643 |
---
|
|
|
|
| 654 |
**A:** `VLLMEngineWrapper` automatically falls back to `HFEngine` (which runs autoregressive inference using native PyTorch/Transformers on CUDA or CPU) or `StubEngine` (for testing).
|
| 655 |
|
| 656 |
**Q: How does M2PO prevent training collapse with stale data?**
|
| 657 |
+
**A:** Stale data produces outlier importance ratios $r_t(\theta) \gg 1$. M2PO tracks the second moment $\mathbb{E}[r_t(\theta)^2]$ across tokens and masks out elements exceeding the `m2_threshold`, bounding gradient variance.
|
| 658 |
|
| 659 |
---
|
| 660 |
|