Skip to content

Commit 0854adc

Browse files
committed
replay_base: direct-evidence logs for R3 wrapper + overlap check
The previous --enable-r3-correctness-check flag turned on the overlap check but produced no log output unless an actual mismatch happened, making it impossible to distinguish "check passed" from "check never ran." Add two unconditional logs gated on enable_check_replay_result: 1. get_topk_fn / new_topk_fn replay_forward + replay_backward branches: log when the wrapper actually returns replay indices rather than falling through to old_topk_fn. Direct evidence megatron's MoE forward used the rollout indices (vs recomputing them). 2. check_replay_result: log n_tokens and mismatch_count on every call, including the mismatch_count==0 case (which previously returned silently). Direct evidence the check ran, plus the actual overlap number for cross-step / cross-rank comparison. Both logs gated on enable_check_replay_result so production training runs (which leave it False) stay quiet. Adds no overhead when off. Intended to make the LLM360/RL360 R3 regression E2E able to assert directly that R3 worked end-to-end, rather than inferring from absence of failure messages.
1 parent db437d2 commit 0854adc

1 file changed

Lines changed: 33 additions & 2 deletions

File tree

‎miles/utils/replay_base.py‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,32 @@ def new_topk_fn(scores, topk, *args, **kwargs):
151151
return result
152152

153153
elif stage == "replay_forward":
154-
return _get_replay_result(replay.pop_forward(), scores, topk, *args, **kwargs)
154+
replay_idx = replay.pop_forward()
155+
if manager.enable_check_replay_result:
156+
# Direct evidence the wrapper's replay_forward branch ran in
157+
# the megatron MoE forward path (vs falling through to
158+
# old_topk_fn). Gated on the correctness-check toggle so
159+
# production training stays quiet. replay_idx_sum is a cheap
160+
# fingerprint of the indices for cross-rank / cross-step
161+
# comparison.
162+
logger.info(
163+
f"R3 wrapper: replay_forward branch taken "
164+
f"(rank {_get_rank()}, n_tokens={replay_idx.shape[0]}, "
165+
f"topk={replay_idx.shape[1]}, "
166+
f"replay_idx_sum={int(replay_idx.sum().item())})"
167+
)
168+
return _get_replay_result(replay_idx, scores, topk, *args, **kwargs)
155169

156170
elif stage == "replay_backward":
157-
return _get_replay_result(replay.pop_backward(), scores, topk, *args, **kwargs)
171+
replay_idx = replay.pop_backward()
172+
if manager.enable_check_replay_result:
173+
logger.info(
174+
f"R3 wrapper: replay_backward branch taken "
175+
f"(rank {_get_rank()}, n_tokens={replay_idx.shape[0]}, "
176+
f"topk={replay_idx.shape[1]}, "
177+
f"replay_idx_sum={int(replay_idx.sum().item())})"
178+
)
179+
return _get_replay_result(replay_idx, scores, topk, *args, **kwargs)
158180

159181
else:
160182
return old_topk_fn(scores, topk, *args, **kwargs)
@@ -196,6 +218,15 @@ def check_replay_result(self, old_topk_fn, scores, topk, top_indices, *args, **k
196218
is_mismatch = ~has_overlap & ~is_padding
197219

198220
mismatch_count = is_mismatch.sum().item()
221+
n_tokens = orig_flat.shape[0]
222+
# Unconditional log so we have direct evidence the check actually
223+
# ran (its silent return on mismatch_count==0 is otherwise
224+
# indistinguishable from never being called).
225+
logger.info(
226+
f"R3 check (rank {_get_rank()}, stage {self.stage}): "
227+
f"n_tokens={n_tokens} mismatch={mismatch_count} "
228+
f"({100 * mismatch_count / max(n_tokens, 1):.2f}%)"
229+
)
199230
if mismatch_count == 0:
200231
return
201232

0 commit comments

Comments
 (0)