Skip to content

Race condition: NaN in generation_logprobs when in_flight_weight_updates=true with vLLM PP>1 #2180

Closed

Description

@sharonyu-115

Describe the bug

When using async GRPO with in_flight_weight_updates=true and vLLM pipeline_parallel_size > 1, weight updates can execute concurrently with vLLM forward passes on the same GPU worker, producing NaN values in generation_logprobs. This corrupts 6 training metrics (gen_kl_error, policy_kl_error, js_divergence_error, token_mult_prob_error, max_seq_mult_prob_error, approx_entropy) at ~2% of training steps in my test run.

Root cause: vLLM's RayDistributedExecutor dispatches forward passes via Ray compiled DAGs (background thread) and weight updates via regular .remote() calls (main thread). These can execute concurrently on the same Ray actor. With PP>1, the EngineCore uses step_with_batch_queue which returns before the forward pass completes, allowing a weight update to overlap with an in-flight forward pass. The forward pass reads partially-updated model weights, producing NaN logprobs.

PP=1 is safe because the EngineCore's blocking step() serializes everything.

Steps/Code to reproduce bug

  1. Run async GRPO with vLLM PP=2 and in_flight_weight_updates=true:
grpo:
  async_grpo:
    enabled: true
    max_trajectory_age_steps: 1
    in_flight_weight_updates: true

policy:
  generation:
    colocated:
      enabled: false
    vllm_cfg:
      async_engine: true
      pipeline_parallel_size: 2
  1. Monitor train/gen_kl_error in wandb or grep for Generation KL Error: nan in the driver log.

e.g. wandb metrics with nan values:

Image
  1. To confirm, run the same config with in_flight_weight_updates: false (safe) or pipeline_parallel_size: 1 (control) — both produce zero NaN.

Experimental results (Qwen3-8B-Base, 300 steps):

Run vLLM PP in_flight NaN steps NaN rate
Safe 2 false 0 / 278 0%
Race 2 true 5 / 300 1.7%
Control 1 true 0 / 300 0%
Race run2 2 true 3 / 155 1.9%

Logprob forensics on the JSONL training data at NaN steps confirmed:

  • NaN is exclusively in generation_logprobs (computed by vLLM at generation time), never in prev_logprobs (recomputed after weight update)
  • Each affected step has 2-4 NaN tokens out of ~2M, in 2-4 samples out of 512
  • Neighboring clean steps and safe/control runs: zero NaN

Additionally, the concurrency issue between compiled DAG tasks and regular .remote() calls on the same Ray actor can be confirmed by the following test script:

test_ray_dag_concurrency.py

Expected behavior

Zero NaN in generation_logprobs and all derived metrics (gen_kl_error, etc.) regardless of pipeline_parallel_size setting.

Weight updates should not overlap with vLLM forward passes. When in_flight_weight_updates=true, NeMo-RL skips waiting for pending generations at the trajectory collector level, but the vLLM engine internally should still ensure forward passes and weight copies are serialized.

Additional context

Proposed fix: Pause the vLLM engine before weight updates using pause_generation(mode="keep") and resume after:

# In VllmAsyncGenerationWorker.update_weights_via_ipc_zmq_async()
await self.llm.pause_generation(mode="keep", clear_cache=False)
try:
    await self.llm.collective_rpc("update_weights_via_ipc_zmq", args=tuple())
finally:
    await self.llm.resume_generation()

mode="keep" freezes the scheduler without aborting requests or clearing KV cache.

A prototype fix is implemented on the inflight-weights-update.

With the fix, a test run with vLLM PP=2 and in_flight_weight_updates=true no longer has nan data points.

Image

Why PP=1 is safe: With PP=1, max_concurrent_batches=1, so the EngineCore uses the blocking step() function which calls refs[0].get() and waits for the compiled DAG to complete before processing any utility requests (including weight updates).

Why PP>1 triggers the race: With PP>1, max_concurrent_batches=pp_size>1, so the EngineCore uses step_with_batch_queue which dispatches forward passes with non_block=True and returns to the input queue before they complete.

Related: vllm-project/vllm#32103 (RFC: Pause/Resume API for RLHF weight updates)

Activity

  1. added
    bug
    on Mar 31, 2026
  2. self-assigned this
    on Mar 31, 2026
  3. terrykong commented on Mar 31, 2026

    @terrykong
    Collaborator

    @sharonyu-115 Good catch! Do you think we should try with something higher like TP=4 + PP=4 (multinode) and then force multiple in-flight-weight updates to happen to test:

    1. if a hang will happen
    2. a corruption still happens (but needs higher parallelism to exhibit)
      ?
  4. sharonyu-115 commented on Apr 1, 2026

    @sharonyu-115
    ContributorAuthor

    @sharonyu-115 Good catch! Do you think we should try with something higher like TP=4 + PP=4 (multinode) and then force multiple in-flight-weight updates to happen to test:

    1. if a hang will happen
    2. a corruption still happens (but needs higher parallelism to exhibit)
      ?

    @terrykong It makes sense. Thanks for the comments. I will run the test and update the findings.

  5. sharonyu-115 commented on Apr 2, 2026

    @sharonyu-115
    ContributorAuthor

    Hi @terrykong do we have the "hang" log from from a previous run that I can take a look?

  6. terrykong commented on Aug 28, 2026

    @terrykong
    Collaborator

    closing this issue for now since #3839 will land soon. this was the suspected reason for the hang and nan in the first place. can re-open if reproducible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions