verl icon indicating copy to clipboard operation
verl copied to clipboard

[QUESTION] Inconsistent Log Prob Calculation in Megatron When Using Chunked vs Padded Inputs

Open xuhang-2 opened this issue 1 year ago • 9 comments

📝 Issue Description:

⚠️ Note: This is not a bug in verl — we’re posting here to gather community opinions and experiences on this subtle but critical numerical behavior in mcore during chunked generation. Any insights or similar observations are highly appreciated!

Summary

We are using partial rollout for LLM + RL. i.e.: 20k max response_length,generate 10k token per round. If EOS in first generate 10k chunk in first round, train this sample; else, generate next 10k chunk in next round.

When computing old_logprob for the first chunk (chunk1) using MCore, we observe inconsistent results:

  • chunk1 + padding (padded to full context length), or
  • chunk1 + chunk2 (full sequence without padding).

Using the same model (Qwen3-1.7B, dense), same weights, and same position IDs for chunk1, the computed log probabilities for chunk1 differ significantly — especially on low-probability tokens and even starting from the first token of the response.

This issue does not occur in Transformer native forward passes - chunked and padded runs produce identical logits for chunk1.


Observed Issues

1. MCore Self-Consistency (Single Chunk)

  • When generating in one chunk, recomputing log probs twice yields identical results (with temperature=1 and 0.6) — so MCore is deterministic in isolation.

2. Chunk + Padding vs Chunk + Chunk Inconsistency (Main Issue)

All experiments use Qwen3-1.7B (dense).

  • Exp 1:
    • output_weight, rotary_pos_emb (first 10360), and decoder_input (first 2590 tokens) are identical.
    • But hidden states diverge in the first half — resembling precision/numerical instability, not logical error.

in: megatron/core/models/gpt/gpt_model.py Image

chunk 1+ chunk 2:

Image

chunk 1 + padding:

Image

Expected Behavior

Log probabilities for chunk1 should be identical regardless of whether it is:

  • Run standalone + padding, or
  • Run as prefix to chunk2.

This is fundamental for RLHF/RLAIF training where old_logprob must remain consistent across rollouts and re-computations.

xuhang-2 avatar Sep 16 '25 02:09 xuhang-2

Hi @xuhang-2, did you use TP or other parallelism in the exps? Would you please share a minimal code to reproduce this issue if convenient?

ISEEKYAN avatar Sep 16 '25 05:09 ISEEKYAN

I noticed that you are using packed_seq_params, which means you are using sequence packing to remove the padding. How did you produce experiment with padding? Did you treat padding as normal tokens?

ISEEKYAN avatar Sep 16 '25 05:09 ISEEKYAN

Hi @xuhang-2, did you use TP or other parallelism in the exps? Would you please share a minimal code to reproduce this issue if convenient?

We use megatron.tensor_model_parallel_size=4, mcore will split total seq into 4 part(i.e.: seq_len=10360, we will have 2590 token per part). We compare the first part tokens' logits.

xuhang-2 avatar Sep 16 '25 05:09 xuhang-2

I noticed that you are using packed_seq_params, which means you are using sequence packing to remove the padding. How did you produce experiment with padding? Did you treat padding as normal tokens?

Yes, we use packed_seq_params.

For chunk 1 experiments , we will have prompt_ids(120 token) + response_chunk1_tokens(10240)=10360 tokens. TP=4, will have 2590 token per part. For chunk 1 + chunk2 experiments, we will have prompt_ids(120 token) + response_chunk1_tokens(10240) + response_chunk2_tokens = 19040 tokens. TP=4, will have 4760 token per part.

We just compare the first 2590 vs first 4760 parts

xuhang-2 avatar Sep 16 '25 05:09 xuhang-2

Hi @xuhang-2, did you use TP or other parallelism in the exps? Would you please share a minimal code to reproduce this issue if convenient?

We use megatron.tensor_model_parallel_size=4, mcore will split total seq into 4 part(i.e.: seq_len=10360, we will have 2590 token per part). We compare the first part tokens' logits.

Are you using TP+SP?

piood avatar Sep 16 '25 14:09 piood

Hi @xuhang-2, did you use TP or other parallelism in the exps? Would you please share a minimal code to reproduce this issue if convenient?

We use megatron.tensor_model_parallel_size=4, mcore will split total seq into 4 part(i.e.: seq_len=10360, we will have 2590 token per part). We compare the first part tokens' logits.

Are you using TP+SP?

Yes, I wonder how to close sp to control variables

xuhang-2 avatar Sep 17 '25 01:09 xuhang-2

@xuhang-2

actor_rollout_ref.actor.megatron.sequence_parallel=False actor_rollout_ref.ref.megatron.sequence_parallel=False

piood avatar Sep 17 '25 02:09 piood

@HaochenYuan

ISEEKYAN avatar Oct 16 '25 10:10 ISEEKYAN

定时清理检查结论:本 issue 最近一次非当前运行账号(Kirrito-k423)的公开回复或公开引用是 2025-10-16T10:59:22Z(actor: HaochenYuan),早于 2026-01-19T00:00:00Z,已经超过 6 个月。根据项目的定时 issue 清理规则,本轮先发布说明并关闭。

可追溯证据:

  • Issue: https://github.com/verl-project/verl/issues/3487
  • Latest non-self public reply/reference: https://github.com/verl-project/verl/issues/3487
  • Comments API: https://api.github.com/repos/verl-project/verl/issues/3487/comments
  • Timeline API: https://api.github.com/repos/verl-project/verl/issues/3487/timeline

如果作者或社区成员仍能提供新的复现、证据或需求背景,请继续评论请求重开,或创建一个包含当前版本信息和最小复现的新 issue。


Scheduled cleanup conclusion: the latest public reply or public reference by an account other than the current automation account (Kirrito-k423) was 2025-10-16T10:59:22Z (actor: HaochenYuan), which is earlier than 2026-01-19T00:00:00Z and therefore more than 6 months old. Under the scheduled issue cleanup rule, this task is posting the explanation first and then closing the issue.

Traceable evidence:

  • Issue: https://github.com/verl-project/verl/issues/3487
  • Latest non-self public reply/reference: https://github.com/verl-project/verl/issues/3487
  • Comments API: https://api.github.com/repos/verl-project/verl/issues/3487/comments
  • Timeline API: https://api.github.com/repos/verl-project/verl/issues/3487/timeline

If the author or community can still provide a fresh reproduction, evidence, or requirement context, please comment to request reopening, or open a new issue with current version details and a minimal reproduction.

This response was generated by a scheduled Codex GPT5.5 issue processing task.

Kirrito-k423 avatar Jul 19 '26 01:07 Kirrito-k423