Skip to content

fix: degrade empty anchor sampling to a masked batch to avoid multi-r… - #737

Open
Boreas618 wants to merge 2 commits into
sgl-project:mainfrom
Boreas618:fix/anchor-sampling-multi-rank-hang
Open

fix: degrade empty anchor sampling to a masked batch to avoid multi-r…#737
Boreas618 wants to merge 2 commits into
sgl-project:mainfrom
Boreas618:fix/anchor-sampling-multi-rank-hang

Conversation

@Boreas618

Copy link
Copy Markdown
Contributor

Motivation

When a micro-batch has no valid anchor positions, _sample_anchor_positions used to raise. In multi-rank training that exit happens before the loss-denominator all-reduce, so peer ranks block on the collective until NCCL timeout.

This shows up when sanitization or sparse supervision leaves a rank with an empty candidate set (including DSpark cases where tokens exist but no adjacent supervised pair). The sampler should still participate in the collective instead of aborting the step.

Modifications

  • Split anchor sampling into _anchor_candidates (eligibility / width) and _select_anchors (random pick); mark the shared path @final.
  • On empty candidates, log a warning and return a fully-masked micro-batch (keep_mask all False) that contributes zero supervision but still reaches the collective.
  • Move DSpark’s stricter rule into an @override of _anchor_candidates; drop the duplicated Domino sampler override so it inherits the shared path.
  • Add unit tests that empty / non-adjacent supervision degrades to a fully-masked batch for DFlash and DSpark.

Related Issues

N/A

Accuracy Test

N/A — training control-flow only; empty batches contribute zero loss rather than changing the model or loss formulation for valid anchors.

Benchmark & Profiling

N/A — no expected throughput/latency impact on the happy path; only the rare empty-candidate case changes from hang/raise to a no-op step.

Checklist

…ank hang

Raising when a micro-batch has no valid anchors skips the loss-denominator
all-reduce and hangs peer ranks until NCCL timeout. Factor candidate selection
into `_anchor_candidates` so DSpark can override eligibility without duplicating
the sampler.
@Boreas618
Boreas618 requested a review from FrankLeeeee as a code owner August 1, 2026 16:55
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@maocheng23

Copy link
Copy Markdown
Collaborator

Overall LGTM, please rebase and pass CI.

…ulti-rank-hang

# Conflicts:
#	specforge/algorithms/common/dflash_family_model.py
#	tests/test_utils/test_dflash_losses.py
@jiapingW
jiapingW self-requested a review August 18, 2026 02:44
@jiapingW

Copy link
Copy Markdown
Collaborator

@Boreas618 @maocheng23 I have fixed the conflicts.

@jiapingW

Copy link
Copy Markdown
Collaborator

help cc.

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.

3 participants