# Reasoning RL system: asynchronous sampling, training aur policy lag

> Reasoning RL system sampling, environment scoring, training aur weight publishing ko jodta hai. Asynchronous compute overlap deta hai, par policy lag bhi laata hai. Chalane yogya schedule simulation se total time, effective batch aur purani trajectories ka total nikala jata hai.

- URL: https://dmxsf.com/hi/wiki/post-training/rollout-and-training/
- [DMXSF](https://dmxsf.com/hi/about/)
- मध्यम
- अपडेट किया गया: 2026-11-21
- Tags: Reasoning, Reinforcement learning, Systems & hardware

## यह पृष्ठ पूरा करने पर आप

- Sampling से scoring, batching, policy update और weight publishing तक का पथ बनाएँ।
- एक ही card पर बारी-बारी, separated synchronous और asynchronous pipeline की resource usage में अंतर करें।
- Behavior policy probability और training policy probability के version मापदंड समझाएँ।
- Schedule simulation और bucketed metrics से lag, dropping और effective training मात्रा जाँचें।

Reasoning RL का हर update पहले जवाब generate करता है, score करता है, फिर gradient निकालता है। Sampling और training अलग devices पर रखने से एक तरफ़ train होते वक़्त दूसरी तरफ़ generation चलती रहती है। Parallelism एक algorithmic सवाल लाता है: trajectory पुराने weights से बनी, और training उसे मिलने तक policy बदल चुकी हो सकती है। System optimization को effective training samples, policy lag, memory और quality साथ गिनने पड़ते हैं।

## एक trajectory कहाँ से आती है, कहाँ जाती है

Math सवालों के verifiable reward RL (RLVR) का उदाहरण लें: sampler (Actor) सवाल और current policy पढ़ता है, जवाब और उसकी behavior log probabilities generate करता है। Environment या scorer जवाब को reward और state सूचना में बदलता है। Trainer (Learner) usable trajectories का सेट जमा करता है, advantage और loss निकालता है, और अगले weights publish करता है। [Berkeley Scalable AI के NeMo RL lecture notes](https://scalable-ai.eecs.berkeley.edu/S2026/assets/lecture_slides/lecture_16_2.pdf) generation backend, training backend, environment और weight transfer की सीमाएँ दिखाती हैं।

| पड़ाव | कम से कम रिकॉर्ड | Delay कहाँ से |
| --- | --- | --- |
| Sampling | सवाल ID, sampling params, behavior policy version, जवाब tokens और mask | Prefill, decode tail, KV Cache |
| Environment और scoring | Scorer version, final state, reward, errors और timeouts | Tool calls, multi-turn state, verification लागत |
| Batching | Group ID, available और drop कारण, wait समय | लंबी trajectories, अधूरा group |
| Update | Weight version, loss, samples और token गिनती | Forward-backward, gradient communication, optimizer |
| Weight publish | Produce, send और effective versions | Shard reorganization, transfer और generation-side reload |

Group-relative तरीक़ों को जानना होता है कि कौन से responses एक ही सवाल से आए, और group stats किसने गिने। Timeouts, truncation और पुराने हटाने से group का आकार बदल सकता है। कोई trajectory अधूरी हो तो algorithm के हिसाब से स्पष्ट तय करें: दोबारा sampling, पूरा group छोड़ना, या दोबारा batching; और सवाल distribution कैसे बदला, रिकॉर्ड करें। "Score नहीं हुआ" को सीधा math error नहीं मानना चाहिए, जब तक task reward timeout को स्पष्ट रूप से failure नहीं मानता।

## एक ही card पर बारी-बारी, separated synchronous और separated asynchronous

एक ही cards पर generation और training बारी-बारी करना weights को मिलाए रखने में आसान है, और capacity कम हो तो शुरुआती experiments के लिए सही। Switch पर generation-side KV cache और training-side states को छोड़ना या transfer करना पड़ता है। Phase लंबा होने पर कुछ devices ख़ाली रह सकते हैं।

Generation और training अलग cards पर रखकर भी sync barrier रख सकते हैं। Generation side नए weights का इंतज़ार करके अगली batch sample करती है; हर batch का policy version update point से साफ़ मिलता है। इससे पहले splitting और transfer का overhead नापा जा सकता है। कुछ barriers हटाने पर asynchronous pipeline मिलती है। Generation पहले शुरू होती है तो training का समय छिप जाता है, पर generation consume से तेज़ हो तो queue में ज़्यादा data इंतज़ार करता है। Deployment में queue length की सीमा, नए weights का इंतज़ार, या पुरानी trajectories छोड़ने से lag नियंत्रित होता है।

## पुरानी policy probability क्यों रिकॉर्ड करनी चाहिए

मान लो $mu$ actual sampling policy है, और $\pi_\theta$ training में update होने वाली policy। Prefix और input का condition $h_i$ लो, और किसी action token $y_i$ की probability ratio लिखी जा सकती है:

$$
r_i(\theta)=\exp\bigl(\log \pi_\theta(y_i\mid h_i)
-\log \mu(y_i\mid h_i)\bigr)
$$

Store की गई behavior probability actual sampling से मेल खानी चाहिए। अगर sampling में temperature या truncation उपयोग हुई हो तो probability का मापदंड training algorithm की assumptions से मिलना चाहिए; और दोनों तरफ़ के templates, token boundaries और masks जाँचें। Training के current weights से denominator दोबारा निकालने से यह छिप जाता है कि trajectory पुरानी policy से आई थी। Probability ratio clipping extreme updates को constrain करता है, फिर भी हर पुराना data सही नहीं होता। Version का अंतर सिर्फ़ सस्ता संकेत है; समान step अंतर बहुत अलग policy drift दिखा सकता है; probability ratio distribution, clipped अनुपात और independent evaluation भी जाँचें।

Policy version trajectory शुरू होने पर स्थिर होनी चाहिए, या framework की परिभाषा के अनुसार step-दर-step behavior version रिकॉर्ड हो। यह convention नहीं हो तो लंबी sequences generation के बीच versions पार कर सकती हैं, और replay समझना मुश्किल। Update के बाद नया model generation side पर स्पष्ट report करे कि कब effective हुआ; "weights भेज दिए" को "अगली trajectory ने उपयोग किया" नहीं मानना चाहिए।

एक सवाल के कई responses generate होने पर trainer को यह भी जानना होता है कि group rewards कहाँ normalize हुए। अगर चार responses पहले group stats बना चुके हैं, और बाद में सिर्फ़ दो बचे, तो पुराने advantage का उपयोग और दो से दोबारा निकालना अलग training objectives देते हैं। Storage में original trajectories, verification results और final loss batches अलग रखें; experiments reproduce करने पर selection rule और उसका version save करें। समान effective trajectory गिनती पर schedule की गति compare करना "कितने requests भेजे" से ज़्यादा algorithmic लागत के पास है।

## प्रयोग: समय बचाना और samples रखना

नीचे एक sampler और एक trainer से छह batches simulate किए हैं। हर batch का update समय fixed है; sampling में एक slow batch है। Version update पूरा होते ही publish होता है, और उसी समय पूरा हो चुका version दिखता है। Queue generation क्रम में consume होती है। Lag सीमा पार करने वाली batch training की बारी आने पर drop होती है। वास्तविक model, GPU communication, reward या convergence simulate नहीं किया। समय demo units में है; कोड Apple M2 Max पर Python 3.12.14 standard library से चला।

```python
from __future__ import annotations

from bisect import bisect_right
from dataclasses import dataclass

@dataclass(frozen=True)
class Trace:
    elapsed: int
    accepted: int
    dropped: int
    lags: tuple[int, ...]

def simulate(
    durations: list[int],
    update_time: int,
    *,
    overlap: bool,
    max_lag: int,
) -> Trace:
    """Simulate FIFO training with a fixed update time."""
    if update_time <= 0 or max_lag < 0 or min(durations, default=1) <= 0:
        raise ValueError("durations must be positive and max_lag nonnegative")
    actor_free = 0
    publish_times: list[int] = []
    lags = []
    for duration in durations:
        learner_free = publish_times[-1] if publish_times else 0
        start = actor_free if overlap else max(actor_free, learner_free)
        actor_free = start + duration
        train_start = max(actor_free, learner_free)
        actor_version = bisect_right(publish_times, start)
        train_version = bisect_right(publish_times, train_start)
        lag = train_version - actor_version
        lags.append(lag)
        if lag <= max_lag:
            publish_times.append(train_start + update_time)
    accepted = len(publish_times)
    elapsed = max(actor_free, publish_times[-1] if accepted else 0)
    return Trace(elapsed, accepted, len(durations) - accepted, tuple(lags))

durations = [3, 3, 9, 2, 2, 2]
serial = simulate(durations, 6, overlap=False, max_lag=0)
bounded = simulate(durations, 6, overlap=True, max_lag=1)
permissive = simulate(durations, 6, overlap=True, max_lag=9)
assert serial.accepted == permissive.accepted == 6
assert all(lag == 0 for lag in serial.lags)
assert bounded.elapsed < permissive.elapsed < serial.elapsed
assert bounded.dropped > 0 and max(permissive.lags) > 1
for label, trace in zip(
    ('serial', 'lag limit', 'open lag'), (serial, bounded, permissive)
):
    print(label, trace.elapsed, trace.accepted, trace.lags)
```

```text
serial 57 6 (0, 0, 0, 0, 0, 0)
lag limit 29 4 (0, 1, 2, 0, 1, 2)
open lag 39 6 (0, 1, 2, 1, 2, 3)
```

(ये संख्याएँ चीनी पृष्ठ की उसी मूल run से हैं; सिर्फ़ print labels अंग्रेज़ी में हैं, संख्याएँ वही हैं।)

Neeche widget is replay ko timeline ki tarah draw karta hai: upari lane par actor ki chhe generations, nichli lane par learner ke swikrit updates, dropped batches lal mein——teen modes badal kar kul samay, prabhavi batches aur max version gap dekhein. 

Serial mode सब batches ले लेता है और version का अंतर शून्य है। Lag constraint ढीला करने पर overlap वही छह batches जल्दी ख़त्म करता है, पर पुराना data training में घुस जाता है। Version अंतर की सीमा रखने पर समापन और भी जल्दी होता है, पर कुछ generation drop होती है और updates की गिनती अलग होती है। इसलिए total समय report करते वक़्त effective batches और effective sample throughput साथ दीजिए। Convergence तेज़ होने का निर्णय देने के लिए समान independent evaluation quality तक पहुँचने का समय या GPU घंटे compare करें।

## वास्तविक tuning से पहले एक control तुलना

1. Model, सवाल सेट, reward, अधिकतम जवाब लंबाई और hardware budget fix करें; synchronous baseline के phase utilization और verification results नापें।
2. Generation और training अलग करें, sync रखें; weight transfer और memory उपयोग अलग record करें।
3. थोड़ी parallel sampling खोलें; सवाल प्रकार और length grouping के हिसाब से version अंतर, drop rate और available tokens रखें।
4. Effective updates fix करके quality compare करें; लागत का निर्णय चाहिए तो शुरुआत से target quality तक के total GPU घंटे भी record करें।

सबसे आम ग़लती: generation tokens/s को training throughput मानना। Early stops, reward failures, sample filtering और retries दोनों को अलग करते हैं। जाँच में generated tokens, loss में शामिल tokens, और वाक़ई पूरे हुए updates अलग columns में देखें; सवाल की कठिनाई या trajectory लंबाई के हिसाब से देखें कि कोई task type बिना कारण drop तो नहीं हो रहा। Length का latency पर असर नापना हो तो sampling और scoring version fix करके सिर्फ़ length distribution बदलें।

## सारांश और अभ्यास

- Generation, scoring, batching और update के bottlenecks अलग करें; एक ही trajectory ID सारे phases में चलाएँ।
- Asynchronous policy lag के बदले device overlap लेता है; behavior probability और weight effective point traceable होने चाहिए।
- Effective training मात्रा, independent evaluation और GPU घंटे compare करें; कौन सा काम drop हुआ, साफ़ रखें।

### त्वरित self-check

**1. Generation और training वाली pipeline में कौन सा data trajectory के साथ save होना चाहिए?**

- [x] Actual behavior policy version और sampling log probabilities.
- [ ] सिर्फ़ latest training weights.

> Replay के लिए जानना होता है कि action किस distribution से आया।

**2. Training से पहले lagged trajectories filter करें तो कौन सी मात्रा दोबारा गिननी चाहिए?**

- [ ] सिर्फ़ original generation दर।
- [x] Effective batches, loss में शामिल tokens और सवाल distribution।

> Filtering training मात्रा कम करती है, और training data की संरचना भी बदल सकती है।

**3. Generation side को weights file मिलना क्या मतलब है?**

- [x] अब भी confirm करना होता है कि नया version अगली trajectory में कब effective होगा।
- [ ] बन चुकी trajectories अपने आप नए weights से sample हो गई।

> पुरानी trajectories का sampling version ऐतिहासिक fact है।

**4. Asynchronous configuration training लागत बचाता है कैसे जाँचें?**

- [ ] सिर्फ़ fixed generation requests के ख़त्म होने का समय।
- [x] समान independent evaluation goal तक पहुँचने के GPU घंटे।

> दोनों तरफ़ के effective updates और learning progress अलग हो सकते हैं।

### वही सवालों से drop bias जाँचें

मान लो लंबे सवाल version lag की वजह से ज़्यादा drop होते हैं। दो diagnostic metrics लिखें, और bias कम करने के लिए एक control experiment बताएँ।

<details>
<summary>संदर्भ उत्तर</summary>

सवाल प्रकार और generation लंबाई के हिसाब से generation batches, available batches और lag distribution गिनें; फिर हर task type loss tokens में कितना हिस्सा है यह नापें। समान सवाल सेट और budget रखें, synchronous baseline से छोटे queue वाले asynchronous config के drop rates और independent verification compare करें; बदलाव का समय लागत अलग record करें।

</details>

## आगे की पढ़ाई

- [Berkeley Scalable AI: NeMo RL lecture notes](https://scalable-ai.eecs.berkeley.edu/S2026/assets/lecture_slides/lecture_16_2.pdf), generation और training backends, separated RL और policy lag।
- [Stanford CS336](https://cs336.stanford.edu/#assignments) का reasoning RL assignment।
- [Reasoning RL](https://dmxsf.com/hi/wiki/post-training/reasoning-rl/) और [Distributed training](https://dmxsf.com/hi/wiki/pretraining/distributed-training/)।

## सहायक कोड

[Reasoning RL systems: rollout and learner scheduling](https://github.com/dmxsf/dmxsf/tree/main/labs/post-training/rollout-and-training): Replay serial and overlapping jobs, and verify policy lag and dropped batches.

- सहायक रिपॉज़िटरी में चलाएँ (--quick से तेज़ जाँच): `uv run dmxsf run post-training/rollout-and-training`
- [प्रयोग स्क्रिप्ट देखें](https://github.com/dmxsf/dmxsf/blob/main/labs/post-training/rollout-and-training/run.py)
- [प्रयोग विवरण](https://github.com/dmxsf/dmxsf/blob/main/labs/post-training/rollout-and-training/README.en.md)
- [`rollout_pipeline.py`](https://github.com/dmxsf/dmxsf/blob/main/src/dmxsf/post_training/rollout_pipeline.py)
- [सूची में देखें](https://dmxsf.com/hi/code/#rollout-and-training)

## अक्सर पूछे जाने वाले सवाल

### Sampling और training को अलग करना asynchronous है?

अलग करने का मतलब अलग devices उपयोग करना है; फिर भी हर publish के बाद sync किया जा सकता है। Asynchronous आगे जाकर sampling को updates के पार चलने देता है, जिसमें version का अंतर सँभालना पड़ता है।

### Policy lag कैसे नापा जाता है?

Sampling शुरू होने पर behavior policy version और training में sample उपयोग होने के समय का version रिकॉर्ड करें, version का अंतर निकालें, और probability ratio distribution से drift जाँचें।

### Asynchronous एक run तेज़ करता है तो क्या वह बेहतर है?

Effective updates और independent evaluation quality साथ compare करें। छोटा समय ज़्यादा काम छोड़ने से आ सकता है; convergence तेज़ होने का सीधा सबूत नहीं।
