feat(gpu): add FastAFD M2N connector for SM100 #489
All Vouch review confidence checks passed
Residual risk 0.30 = Change Risk (0.57) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.57 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #489"
general
weight: 0.35
ischencheng
<!-- markdownlint-disable -->
Purpose
This adds
FastAFDAFDConnector, a CUDA connector that runs the AFD expert exchange with the FastAFD M2N MegaMoE kernels on Blackwell (SM100), andFastAFDExpertExecutor, the fused FFN execution adapter that drives the ported FFN megakernel. It covers the connector, kernel port and comparison parts of #397, measured againstP2pNcclAFDConnectoron the same GPUs.How it works:
FastAFDExpertExecutorloads only this rank's routed experts from the FP8 checkpoint and launches one persistent kernel per step plan that serves all MoE layers. There is no per-layer recv/compute/send on the host. It holds no vLLM model, scheduler or graph state;FastAFDFFNModelRunnerjust forwards step plans to it from today's FFN worker loop.submit(step_plan)launches one step on the current stream and raises before launching if the connector can't serve the plan;drain(timeout_s)stops accepting steps and reports whether the last one finished; the caller frees the connector and executor only after a successful drain. Admission, launch and the completion event share a lock, so a drain from the shutdown thread can't miss a launch in flight. Shutdown waits up to 5 s and otherwise leaves the buffers to process exit, because a step that never finishes still owns them.Issue
submit(step_plan)is meant to be that adapter; I'd like to agree its exact interface with #391 before moving it.Scope
FastAFDExpertExecutorandFastAFDFFNModelRunner, the vendored kernels undercsrc/gpu/fastafdwith an opt-in build (AFD_BUILD_FASTAFD_OPS=1), Attention-side routing for Qwen3.5/3.6 MoE, a kernel parity probe, unit tests, e2e runner support and docs.Implementation Notes
3c7161949310b6d59d6b4cf9bf997a4935c8113b. Only the 46 files the M2N path needs are vendored, with the FastAFD and DeepGEMM MIT notices. Local differences: two env vars are renamed (AFD_FASTAFD_AG_SMS,AFD_FASTAFD_HOST_DEBUG),python_api.cppregisters only the M2N APIs, and the dispatch expert-count push uses a system-scope release atomic so the expert kernel sees the per-source counts before the ready bits. CUTLASS v4.2.1 and fmt 11.2.0 headers are fetched at build time and checked by sha256. The FastAFD, DeepGEMM, CUTLASS and fmt notices are installed underafd_plugin/_fastafd/licenses/.DG_JIT_CACHE_DIR. The package still imports without the extension; the connector fails at init with a reinstall hint.torch.compile: the model'safd_fastafd_dispatchop returns a copy of its input for the shared expert, andafd_fastafd_combinetakes the shared output, so the compiler keeps the shared expert between the two kernels.cuda:0. The connector checks GPU UUIDs are distinct, then setsTORCH_SYMM_MEM_ALLOW_OVERLAPPING_DEVICES=1(unless set) for the symmetric-memory rendezvous.--max-num-batched-tokenswould otherwise corrupt the buffers.close()frees the lane buffers and destroys the union group.Test Plan
tests/e2e/operators/fastafd_m2n_reference.py, real Qwen3.6-35B-A3B-FP8 experts, layers 0 and 1, 1 and 2 lanes, checkpoint-gate routing and skewed routing (every token on the same 8 experts). Bound: rel L2 0.01 against a reference that applies the kernel's quantization and rounding. Two runs:- default mode with
--empty: the raw kernels, fused and split, 1/7/64/256 tokens (256 = buffer capacity), plus one empty single-lane step (split, checkpoint gate);-
--production: split dispatch/combine throughFastAFDAFDConnectorandFastAFDExpertExecutor, lane 1 at half of lane 0's tokens, empty steps between non-empty ones, then 256.afd-v2-eager-1a1fandafd-v2-graph-1a1f,--afd-connector FastAFDAFDConnector --compute-gate-on-attention.FULL_DECODE_ONLYgraphs (capture sizes 1-64),--max-num-batched-tokens 8192, same checkpoint. FastAFD andP2pNcclAFDConnectoralternate in one container, two rounds each, on an earlier revision of this branch with the same dispatch, shared-expert and combine path and the same expert-kernel launch. Since then each FFN step also takes a lock and records a CUDA event (host side, once per step), and the startup checks, shutdown drain, executor split and tests were added; I didn't rerun the A/B for those.- GSM8K 5-shot, all 1319 questions, through the repo's lm-eval wrapper;
-
vllm bench serverandom 1024 in / 256 out at concurrency 1-64;- single-request TTFT at 1024 and 3072 tokens.
pytest tests/unit -m "not gpu and not vllm_runtime"in thevllm/vllm-openai:v0.30.0image, andpre-commit run --fileson the changed files.Test Result
Environment: 2xB200,
vllm/vllm-openai:v0.30.0(vLLM 0.30.0, torch 2.13.0+cu130, CUDA 13.0),Qwen/Qwen3.6-35B-A3B-FP8at95a723d, main atdf8d6a0.Kernel parity, raw kernels: 98/98 cases pass, max matched rel L2 0.0018, all outputs finite. Against the checkpoint's block-FP8 math the gap is 5.6-6.4%, which is the per-32 FP8 activation and intermediate quantization. Through the connector and executor: 84/84 cases pass (including the empty steps and uneven lanes), max matched rel L2 0.0017.
E2E:
afd-v2-graph-1a1fpasses (graph_replays=652on Attention);afd-v2-eager-1a1fpassed on an earlier revision of this branch. Every run, FastAFD and P2P alike, ends with vLLM force-killing both EngineCores after its 10 s shutdown timeout, after all requests finished; in one FastAFD A/B run the Attention API server then also loggedEngineDeadError.GSM8K (strict-match, 1319 questions), round 1 / round 2:
| FastAFD | P2P |
|---|---|
| 37.1 / 38.4 | 39.2 / 38.9 |
The means are 37.7 and 39.0. Round 1 is 2.1 points apart, slightly over the 2-point threshold; same-arm rounds move by up to 1.3 points. Native vLLM on one B200, same image and flags, scored 38.9 in a separate run. The scores are low for this model because it often starts a thinking block and hits lm-eval's 512-token cap; every arm uses the same setup.
Decode, median TPOT in ms, round 1 / round 2:
| concurrency | FastAFD | P2P | FastAFD vs P2P |
|---|---|---|---|
| 1 | 6.30 / 6.47 | 4.57 / 4.62 | +39% |
| 4 | 6.97 / 7.15 | 6.01 / 6.01 | +17% |
| 8 | 7.51 / 7.63 | 6.86 / 6.93 | +10% |
| 32 | 10.37 / 10.37 | 10.19 / 10.18 | +2% |
| 64 | 13.87 / 13.39 | 13.40 / 13.20 | +2% |
Single-request TTFT, median ms: 1024 tokens 35.7 / 33.4 vs 37.2 / 37.8; 3072 tokens 69.6 / 71.4 vs 77.8 / 77.9. That is 8-9% lower, inside the ±10% band.
On 1A1F FastAFD is slower at low decode concurrency, and on par from 32 up and for prefill. A kernel-only benchmark (40 layers in a CUDA graph, 2xB200) points at the round trip: the fused kernel takes about 90 us per layer at 1 token, 111 us at 8 and 163 us at 64. Split dispatch/combine with a shared-expert-sized MLP in between measured 91.5, 111.9 and 163.9 us, while the fused kernel followed by the same MLP measured 104.0, 126.8 and 176.7 us. The kernels are built to overlap that round trip with the other DBO lane's attention; I couldn't test that here because Qwen3.5/3.6 GDN does not support DBO in vLLM.
CPU: unit suite 1270 passed, 104 skipped, 0 failed. pre-commit passes on all changed files (the vendored sources are excluded from the whitespace hooks so they stay identical to the pin). A wheel built with
AFD_BUILD_FASTAFD_OPS=1contains the extension, the kernel headers and the four license files.Not run: more than one Attention or FFN rank (needs more than 2 GPUs), DBO lanes in vLLM, other models, SM90, NPU. Not handled: a rank that dies mid-step leaves its peers spinning in the kernel; only the kernel's NVLink barriers give up, after 300 s.
Docs Impact
docs/gpu/FASTAFD_CONNECTOR_USER_GUIDE.md(new),docs/design/module/{connector_contracts,ffn_runtime,model_integration,execution_platforms}.md,tests/e2e/README.md,tests/e2e/operators/README.md.---
<details>
<summary>Essential PR Checklist</summary>
</details>
Implementation and validation were AI-assisted.