Skip to content

moe_scatter_dy: one thread per slot serializes a 3072-float row copy + dot #45

Closed

Description

@feitreim

moe_scatter_dy: one thread per slot serializes a 3072-float row copy + dot

Profile (B200, L=12 B=8 T=2048 D=3072 E=8 K=2 C=4096, §10.1; 12-block sums):

span ms launch bytes moved
backward.router.scatter_dy 20.82 for_num_elems(N·K) = 32,768 threads ≈ 1.2 GB → ≈ 58 GB/s, ~1% of HBM
(compare) forward.router.scatter 5.59 for_num_elems(N·K·D) — thread per element same order of traffic

moe_scatter_dy gives each (token, slot) pair a single thread that (a) copies the token's D=3072 gradient row into the expert bin and (b) accumulates the gate gradient Σ_d dy·bin_output over the same 3072 elements — a serial, stride-1-per-thread loop with no coalescing across the row. The forward scatter of the very same tensor shape is thread-per-element and still 4× cheaper while doing comparable traffic; the backward variant is only shaped this way because of the fused dot.

At ≈ 21 ms this is 5% of the ~410 ms non-attention step for what is bandwidth-wise a sub-millisecond operation.

Sketch

Split the two concerns, or restructure around a block per slot:

  • Block-per-(token, slot): block-wide coalesced copy of the D row (vectorized), plus a block reduction for the gate dot — one kernel, both outputs, full coalescing. N·K = 32k blocks is plenty of grid.
  • Or two kernels: thread-per-element scatter (exactly mirroring moe_scatter) + a separate warp-per-slot dot for gate_gradients. Simpler, two launches.

Either way backward.router.zero_dy_bins (2.5 ms full-buffer fill) can likely fold in: a block-per-slot kernel that also zeroes unassigned capacity slots removes the separate E·C·D fill pass (needs the assignment counts to enumerate dead slots, which the routing acts already hold).

Gates

  • MoE model parity with forced drops and underfull experts (gate-gradient reduction order changes → existing fp32 tolerances; token/slot write disjointness must be preserved exactly).
  • §10.1 same-container profile: scatter_dy from ≈ 20.8 ms to ≈ 1 ms or below.

Activity

  1. added
    enhancement
    on Jul 23, 2026
  2. added a commit that references this issue on Jul 23, 2026
    a60b65c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions