Skip to content

[FEA] Overlap DP and MP embedding. #307

Closed

Description

@JacoCheung

Currently, due to D2H and stream sync, the dynamicemb( MP) and dense (torchrec DP) is serialized, the side stream takes no any effect.

See below timeline

Image

Activity

  1. added this to the 26.3 milestone on Feb 25, 2026
  2. shijieliu commented on Feb 25, 2026

    @shijieliu
    Collaborator

    we need to remove d2h from critical path in embedding

  3. JacoCheung commented on Mar 16, 2026

    @JacoCheung
    CollaboratorAuthor

    New foundings:
    The DP forward poses a D2H sync here

      └── KJT.split()                              # jagged_tensor.py:2331
            ├── self.length_per_key()               # jagged_tensor.py:2343
            │     └── _maybe_compute_length_per_key()  # jagged_tensor.py:1165
            │           └── torch.sum(lengths.view(len(keys), stride), dim=1).tolist()
            │                                                                 ^^^^^^^^
            │                                                          D2H memcpy
            └── self.offset_per_key()               # jagged_tensor.py:2344
                  └── _maybe_compute_offset_per_key()
    

    Good news is that in dynamic mp embedding, there is no any sync yet, and the overlap is eligible.

  4. added a commit that references this issue on Apr 2, 2026
    c1356f2
  5. JacoCheung commented on Apr 2, 2026

    @JacoCheung
    CollaboratorAuthor

    Fix: eliminate D2H sync in DP embedding forward

    PR: #340 (commit c1356f2c)

    Root cause: DataParallelEmbeddingCollection.forward() called KJT.split() and KJT.to_dict(), both of which internally invoke length_per_key() → .tolist() → D2H sync. This sync on the side stream blocked the CPU thread and serialized DP/MP embedding.

    Fix (3 changes):

    1. Replace split() with permute() — permute filters to DP-only features without triggering length_per_key() D2H. Always keep _features_order (no longer optimize to empty list).

    2. Replace KJT(...).to_dict() with manual dict build — _build_output_dict() slices lengths using Python-int stride arithmetic (all_lengths[i*stride : (i+1)*stride]) and splits values via torch.split(embeddings, length_per_key). JaggedTensor.__init__ is sync-free (pure reference assignment).

    3. compute_dp_length_per_key() — extracts per-DP-feature value counts from the input KJT's already-cached length_per_key (built by from_lengths_sync). Pure Python list indexing — zero GPU work, zero D2H.

    DP/MP overlap: ShardedEmbedding.forward() now launches DP on side stream first, then MP on default stream. The two run concurrently on GPU. wait_stream (stream-level sync, not CPU sync) ensures correctness before downstream consumption.

  6. self-assigned this
    on Apr 2, 2026
  7. JacoCheung commented on Apr 2, 2026

    @JacoCheung
    CollaboratorAuthor

    See timeline diff (sync-free dp+dp first vs mp fisrt).
    The sharded embedding forward lantency diff:

    11.266ms vs 13.867ms

    Image
  8. added 7 commits that reference this issue on Apr 2, 2026
    93b8cf4
    2d5f47e
    06660f6
    50c0919
    08d3a73
    8dde9ef
    16b64c2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions