ZMC2019's picture
Reorganise: group 313 tasks into 17 families under tasks/, generators under tools/ (part 9)
42832bf verified
Raw History Blame Contribute Delete
1.67 kB
"""Your implementation goes here.
Replace the body of `node_dispatch_pack` with a FAST implementation that reproduces the output of /app/reference.py
(same signature, same numerics within tolerance) but is much faster — see /app/instruction.md.
Run `python /app/measure.py` to check your correctness and achieved GB/s.
You may add helper modules, Triton kernels, CUDA extensions, caches, etc. — only this function's name,
signature and returned value are fixed by the contract.
"""
def node_dispatch_pack(x, topk_ids, num_nodes, experts_per_node):
"""Node-limited MoE dispatch: dedup to node sets and pack the all-to-all send buffer.
Args:
x: (T, H) bfloat16 — token hidden states.
topk_ids: (T, K) int32 — the K expert ids chosen for each token (distinct within a row).
num_nodes: int — N, the number of expert-parallel nodes.
experts_per_node: int — EPN; expert e lives on node e // EPN.
Returns:
(send_buf, src_token, node_counts, node_offsets) where
send_buf: (T*M, H) bfloat16 — hidden states in NODE-MAJOR order, tokens ascending inside a node
src_token: (T*M,) int32 — the token each packed row came from
node_counts: (N,) int32 — rows destined for each node
node_offsets: (N+1,) int32 — node n owns rows [node_offsets[n], node_offsets[n+1])
M is the (fixed) number of distinct nodes every token's experts span, so T*M rows are always
produced.
"""
raise NotImplementedError("Implement a fast node_dispatch_pack in /app/dispatch_pack.py")