Skip to content

feat(dspark): add offline USP training support - #725

Open
calyoung80 wants to merge 1 commit into
sgl-project:mainfrom
calyoung80:feature/dspark-long-sequence-offline-training
Open

feat(dspark): add offline USP training support#725
calyoung80 wants to merge 1 commit into
sgl-project:mainfrom
calyoung80:feature/dspark-long-sequence-offline-training

Conversation

@calyoung80

Copy link
Copy Markdown

Motivation

DSpark offline training currently processes the full sequence on every draft
sequence-parallel rank, which limits the usable sequence length and duplicates
target hidden-state storage and compute.

This PR adds a USP-backed offline training path for DSpark. It shards sequence
tensors across the draft-SP group while preserving global sequence semantics
for draft attention and loss computation.

Modifications

  • Add rank-local DSpark offline sample normalization for USP:
    • shard input_ids, loss_mask, hidden_states, and
      target_last_hidden_states;
    • pad the final shard to a static sequence length for collective
      communication;
    • carry a local attention_mask through the collator and training strategy.
  • Add an autograd-correct sequence all-gather helper:
    • reconstruct global projected target hidden states for draft attention;
    • route gradients back to the owner rank with reduce_scatter_tensor;
    • retain a Gloo-compatible reference fallback.
  • Add usp as a DSpark attention backend:
    • use SDPA only for local Transformers draft-model construction;
    • keep USP topology and sequence communication under SpecForge control;
    • avoid importing CUDA-only sequence-parallel dependencies for this path.
  • Project target hidden states before the HCCL exchange to reduce communication
    width.
  • Synchronize valid anchor width across draft-SP ranks and support empty local
    shards safely.
  • Add focused coverage for data sharding, padding, collator propagation,
    distributed gather/backward behavior, backend mapping, and empty-shard anchor
    handling.

Related Issues

N/A

Accuracy Test

This PR changes DSpark training infrastructure rather than model architecture
or inference kernels.

Accuracy validation has not been run yet. A multi-rank DSpark offline training
comparison against the non-USP baseline is required before merge.

Benchmark & Profiling

This PR is intended to enable longer offline training sequences and reduce
per-rank sequence-state memory.

Benchmark and profiling results have not been collected yet. Suggested
follow-up measurements:

  • maximum trainable sequence length;
  • peak device memory per rank;
  • HCCL communication time;
  • tokens/s versus the non-USP DSpark offline baseline.

Checklist

  • Format code with pre-commit.
  • Add focused unit tests.
  • Run the focused test suite:
    pytest tests/test_algorithms/test_dspark_usp.py tests/test_algorithms/test_model_providers.py tests/test_utils/test_dflash_losses.py
  • Update documentation / examples as needed.
  • Provide multi-rank accuracy and throughput / latency results before merge.
  • Add a DCO sign-off:
    Signed-off-by: calyoung80 <zsucal@hotmail.com>

Signed-off-by: calyoung80 <zsucal@hotmail.com>
@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.

@jiapingW

Copy link
Copy Markdown
Collaborator

Hi, can you add your results of dspark draft model that trained on long sequence?

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