← Back to Pull requests

feat(gpu): add FastAFD M2N connector for SM100 #489

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Oct 22, 2026 21:09 UTC
Author

<!-- markdownlint-disable -->

Purpose

This adds FastAFDAFDConnector, a CUDA connector that runs the AFD expert exchange with the FastAFD M2N MegaMoE kernels on Blackwell (SM100), and FastAFDExpertExecutor, the fused FFN execution adapter that drives the ported FFN megakernel. It covers the connector, kernel port and comparison parts of #397, measured against P2pNcclAFDConnector on the same GPUs.

How it works:

  • Attention routes (native softmax top-k + renorm) and runs the gated shared expert. Per MoE layer, a dispatch kernel quantizes the tokens to per-32 UE8M0 FP8 and writes them to the FFN ranks that own their experts. The shared expert runs while the FFN ranks compute, then a combine kernel waits for the results and reduces the top-k.

  • FFN: FastAFDExpertExecutor loads 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; FastAFDFFNModelRunner just forwards step plans to it from today's FFN worker loop.

  • Executor contract, proposed for the #391 server: 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.

  • Ranks sync through NVLink symmetric memory on an Attention-first union group. The existing control plane carries each step plan from Attention to FFN.
  • Issue

  • Related issue(s): #397, #391

  • Closing keyword, only if fully resolved: none. #397 also wants the fused path to run inside #391's FFN Server, which hasn't landed. The executor's submit(step_plan) is meant to be that adapter; I'd like to agree its exact interface with #391 before moving it.
  • Scope

  • In scope: the connector, FastAFDExpertExecutor and FastAFDFFNModelRunner, the vendored kernels under csrc/gpu/fastafd with 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.

  • Out of scope: the #391 FFN Server integration, SM90, models other than Qwen3.5/3.6 MoE FP8, TP > 1, DBO lanes on a model that supports DBO (Qwen3.5/3.6 GDN does not), multi-node, peer-failure recovery.
  • Implementation Notes

  • Kernel source: FastAFD 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.cpp registers 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 under afd_plugin/_fastafd/licenses/.

  • Kernels JIT-compile with nvcc on first use and cache under DG_JIT_CACHE_DIR. The package still imports without the extension; the connector fails at init with a reinstall hint.

  • FFN weights: the 128x128 block scales are requantized to per-32 UE8M0 (one lossy e4m3 round trip), gate/up interleaved, and TMA descriptors built per layer.

  • torch.compile: the model's afd_fastafd_dispatch op returns a copy of its input for the shared expert, and afd_fastafd_combine takes the shared output, so the compiler keeps the shared expert between the two kernels.

  • The lane buffers serve only the split dispatch/combine launches. In a test that alternated fused and split launches on one buffer, the kernel's barrier timed out, so the probe keeps a buffer per mode.

  • Role processes usually see one GPU each, so every rank reports cuda:0. The connector checks GPU UUIDs are distinct, then sets TORCH_SYMM_MEM_ALLOW_OVERLAPPING_DEVICES=1 (unless set) for the symmetric-memory rendezvous.

  • Startup checks, before any buffer exists: SM100, bf16 activations, FP8 checkpoint with 128x128 block scales, a MoE block in every layer, TP 1, a distinct GPU per rank, and the same lanes, layer count and buffer shape on every rank. A mismatched --max-num-batched-tokens would otherwise corrupt the buffers.

  • close() frees the lane buffers and destroys the union group.

  • Qwen3.5/3.6: with this connector, gate, shared expert and shared-expert gate load on Attention, and routed experts load on FFN only.

  • e2e runner: MRV2 evidence for FastAFD checks Attention graph replays only, since the FFN runner keeps no graphs.

  • No vLLM source changes. The FFN worker picks the runner through the existing V2 construction seam.
  • Test Plan

  • Kernel parity on 2xB200 with 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 through FastAFDAFDConnector and FastAFDExpertExecutor, lane 1 at half of lane 0's tokens, empty steps between non-empty ones, then 256.
  • E2E on 2xB200 (1A1F) with the repo runner: afd-v2-eager-1a1f and afd-v2-graph-1a1f, --afd-connector FastAFDAFDConnector --compute-gate-on-attention.

  • A/B on 2xB200, 1A1F, FULL_DECODE_ONLY graphs (capture sizes 1-64), --max-num-batched-tokens 8192, same checkpoint. FastAFD and P2pNcclAFDConnector alternate 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 serve random 1024 in / 256 out at concurrency 1-64;
    - single-request TTFT at 1024 and 3072 tokens.
  • Thresholds set before measuring: GSM8K within 2 points of P2P; latency counts as a win or loss only beyond ±10%.

  • CPU: pytest tests/unit -m "not gpu and not vllm_runtime" in the vllm/vllm-openai:v0.30.0 image, and pre-commit run --files on 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-FP8 at 95a723d, main at df8d6a0.

    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-1a1f passes (graph_replays=652 on Attention); afd-v2-eager-1a1f passed 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 logged EngineDeadError.

    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=1 contains 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

  • Files updated: 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>

  • Purpose is clear and linked to public context when possible.

  • Scope is bounded.

  • Compatibility with vLLM v0.30.0 is considered.

  • No changes are made to the vLLM source checkout.

  • Plugin-owned classes or explicit dotted class paths are preferred over monkey patches.

  • Any compat shim or monkey patch is isolated, idempotent, version-guarded, documented, and tested.

  • Imports remain CPU-safe; CUDA-heavy work is delayed or GPU-gated.

  • Validation evidence is included, including skipped GPU tests when applicable.

  • Documentation impact is stated.
  • </details>

    Implementation and validation were AI-assisted.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: ischencheng Review duration: 37098m
    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
    0.57
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 57% (MEDIUM) · Higher = larger blast radius
    57%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 30.4% · Safe to merge
    30.4%