Skip to content

fix(sft): scope deterministic training randomness - #102

Merged
zhihengy merged 4 commits into
feat/sftfrom
fix/sft-rng-scoping
Aug 8, 2026
Merged

fix(sft): scope deterministic training randomness#102
zhihengy merged 4 commits into
feat/sftfrom
fix/sft-rng-scoping

Conversation

@zhihengy

@zhihengy zhihengy commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Stack (3/3, top): stacked on #90 (feat/sft), which is stacked on #96 (feat/encoder-hub). Merge order: #96#90 → this PR.

Summary

  • Seed expert choice by rollout and microbatch so every rank selects the same expert.
  • Add logical DP rank to timestep/noise sampling so SP ranks match while DP replicas differ.
  • When training one Wan expert, sample only its high- or low-noise range.

Test plan

  • pytest -q tests/fast/backends/fsdp_utils/test_loss_hub_sft.py

@zhihengy
zhihengy force-pushed the fix/sft-rng-scoping branch from 98a0003 to 4fd5362 Compare August 7, 2026 11:43
@zhihengy
zhihengy force-pushed the fix/sft-rng-scoping branch 3 times, most recently from a53e706 to 26f52a0 Compare August 7, 2026 20:02
Keep expert selection rank-aligned while giving each logical DP replica an independent sample stream, and constrain single-expert Wan runs to their timestep range.

Co-authored-by: Cursor <cursoragent@cursor.com>
@zhihengy
zhihengy force-pushed the fix/sft-rng-scoping branch from 26f52a0 to 026a87d Compare August 7, 2026 20:11
Comment thread miles/backends/fsdp_utils/actor.py Outdated
zhihengy and others added 3 commits August 7, 2026 23:58
pair_lo // micro_bs only identifies a micro-batch while every micro-batch
starts at a multiple of micro_bs; under dynamic micro-batch sizes it would
silently collide and hand two micro-batches identical noise. Seed with the
enumerated (optim_step_idx, microbatch_idx) instead, offsetting the
old-log-prob recompute loop by one step so both passes keep drawing the
same noise/timesteps for the same micro-batch.

Co-authored-by: Cursor <cursoragent@cursor.com>
…tch_id

The loss hub only needs an opaque RNG-stream identity, so fold
(optim_step_idx, microbatch_idx) into a single ordinal inside the actor
via cumulative per-step counts, which stays unique under dynamic
micro-batch sizes and keeps recompute/train passes aligned.

Co-authored-by: Cursor <cursoragent@cursor.com>
A plain counter enumerates micro-batches in schedule order; the
recompute loop starts past window 0's micro-batches so both passes
give the same micro-batch the same id.

Co-authored-by: Cursor <cursoragent@cursor.com>
@zhihengy
zhihengy merged commit 9aa1a5f into main Aug 8, 2026
15 checks passed
@zhihengy
zhihengy deleted the fix/sft-rng-scoping branch August 8, 2026 01:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants