project6 c1936a55cb arch(moe): translate CCCL block_histogram.cuh — segment size histogram for expert load analysis
block_histogram.cuh entire design:
  Two algorithms for counting observations per bin:
  1. BLOCK_HISTO_SORT: sort → detect discontinuities → run lengths = bin counts
     Consistent throughput regardless of distribution.
  2. BLOCK_HISTO_ATOMIC: atomicAdd per bin.
     Fast for uniform, slow for skewed (atomic contention).
  Template param selects algorithm at compile time.

Translation: We already do HISTO_SORT (argsort by expert_id → segment detect).
Added: compute seg_sizes histogram (seg_ends - seg_starts) which enables:
  - Understanding expert load balance (skewed = some experts get 100 tokens,
    others get 1 → HISTO_ATOMIC contention equivalent: Python loop overhead
    for 1-token F.linear calls dominates)
  - Future: batch 1-token segments into padded GEMM (HISTO_SORT guaranteed
    consistent throughput, matches batch-friendly GEMM patterns)

+ dispatch_copy_mdspan contiguous-check in same commit area.

CCCL source: cub/cub/block/block_histogram.cuh (full 412-line file)
Maps to: qwen3_6_scripts/qwen3_5.py (_pure_pytorch_experts)
2026-08-07 09:12:24 +00:00
2026-08-07 08:43:51 +00:00
2026-07-30 17:03:23 +08:00
2026-08-07 07:47:01 +00:00

project_6

Description
No description provided
Readme 427 MiB
Languages
C++ 41.8%
Cuda 31.6%
Python 22.2%
C 2.1%
CMake 1.1%
Other 1.1%