Skip to content

Store expert weights across prefill workers ​

--moe-weight-sharing-size N enables distributed weight data parallelism (DWDP): each prefill worker stores one of N immutable expert shards and fetches remote weights while executing its own batch. Execution remains TP1/EP1; attention DP still identifies the serving workers. Omitting the option keeps resident expert weights.

Check configuration requirements ​

DWDP supports the CUDA 12.8 and 13 toolkits.

The initial K3 configuration supports NVFP4 or MXFP4 experts on the FlashInfer TRT-LLM kernels. For MXFP4, pass --moe-backend flashinfer_trtllm because auto may select another kernel. This configuration requires --attn-tp-size 1 --moe-tp-size 1 --ep-size 1 --all2all-backend none, --disaggregation-mode prefill, and a fixed prefill token budget. Eager execution and ordinary breakable prefill graphs are supported.

The routed experts run on FlashInfer's TRT-LLM-Gen kernels (--moe-backend flashinfer_trtllm) or, for NVFP4, its CuTe DSL kernels (--moe-backend flashinfer_cutedsl). The weight-sharing size must divide the instance size. Shared-expert and attention-projection TP overrides must also remain local. The additional staging memory is allocated before KV cache sizing. Live checkpoint replacement requires restarting these workers.

For more information about storage ownership and stream-ordering invariants, see distributed immutable weights.

Start the K3 DWDP16 prefill role ​

This example reproduces the supported AgentX DWDP16 prefill launcher. It uses K3 NVFP4, four prefill nodes with four GPUs each, 16 attention-DP ranks, and --moe-weight-sharing-size 16. The gateway and decode role remain separate parts of the PD deployment.

Before launching, prepare the same checkpoint, container, and shared paths on every prefill node. Set AGENTX_HEAD, GATEWAY_ADDR, MODEL_PATH, TOKENIZER_PATH, DRAFT_MODEL_PATH, and DISAGGREGATION_IB_DEVICE for your deployment. Run through the Slurm launcher so that SLURM_NODEID identifies each prefill node.

  1. From the repository root, prepare the environment and start one prefill engine per node. This command retains the supported launcher's settings, including its fixed prefill token budget and eager execution:

    bash
    : "${AGENTX_HEAD:?}" "${GATEWAY_ADDR:?}" "${MODEL_PATH:?}" "${TOKENIZER_PATH:?}" "${DRAFT_MODEL_PATH:?}"
    : "${DISAGGREGATION_IB_DEVICE:?}" "${SLURM_NODEID:?}"
    
    shared_l2_config=$(sed "s/@HEAD@/$AGENTX_HEAD/" \
      "test/agentic_benchmark/kimi_k3/tokenspeed_agentx/configs/shared_l2.json")
    
    export TOKENSPEED_KIMI_K3_QKV_PROJ_TP_SIZE=1
    export TOKENSPEED_KIMI_K3_O_PROJ_TP_SIZE=1
    export TOKENSPEED_KIMI_K3_SHARED_EXPERT_TP_SIZE=1
    export TOKENSPEED_DISAGGREGATION_WAITING_TIMEOUT=3600
    export TOKENSPEED_DISAGGREGATION_BOOTSTRAP_TIMEOUT=3600
    export PYTORCH_ALLOC_CONF=pinned_max_round_threshold_mb:1024
    unset PYTORCH_CUDA_ALLOC_CONF TOKENSPEED_SPEC_SIMULATED_ACCEPT_LEN
    export LD_LIBRARY_PATH=/usr/local/lib:/usr/local/cuda/lib64:${LD_LIBRARY_PATH:-}
    export NO_PROXY='*' no_proxy='*'
    export MOONCAKE_LOCAL_HOSTNAME="$(hostname -s)"
    export OMP_NUM_THREADS=4
    export MAX_JOBS=8
    ulimit -c 0
    
    exec python3 -m tokenspeed.runtime.entrypoints.engine \
        --model "$MODEL_PATH" \
        --tokenizer "$TOKENIZER_PATH" \
        --served-model-name kimi-k3-agentx-pd \
        --world-size 16 --nprocs-per-node 4 --nnodes 4 --node-rank "$SLURM_NODEID" --base-gpu-id 0 --gpu-id-step 1 \
        --dist-init-addr "$AGENTX_HEAD:29401" \
        --data-parallel-address "$GATEWAY_ADDR" --data-parallel-rpc-port 31000 --zmq-engine-index 0 \
        --attn-tp-size 1 --data-parallel-size 16 --moe-tp-size 1 \
        --ep-size 1 --moe-weight-sharing-size 16 --all2all-backend none \
        --max-model-len 1048576 --max-num-seqs 1024 --gpu-memory-utilization 0.88 \
        --max-prefill-tokens 24576 --chunked-prefill-size 24576 --prefill-chunk-yield-tokens 12288 \
        --enforce-eager --disable-prefill-graph --prefill-graph-max-tokens 0 \
        --disable-overlap-schedule \
        --disable-kvstore --mamba-ssm-dtype bfloat16 \
        --shared-l2-config "$shared_l2_config" \
        --checkpoint-retention-leaf-distance 1 \
        --trust-remote-code --language-model-only --mm-encoder-tp-mode weights \
        --attention-backend tokenspeed_mla --kda-backend cutedsl_kda \
        --moe-backend flashinfer_cutedsl \
        --kv-cache-dtype fp8 --min-kv-split 8 --mla-chunk-multiplier 4 \
        --kv-events-config '{"enable_kv_cache_events": true, "publisher": "zmq", "endpoint": "tcp://*:20300"}' \
        --disaggregation-mode prefill \
        --disaggregation-transfer-backend mooncake \
        --disaggregation-decode-allocation-policy deferred \
        --disaggregation-layerwise-interval 0 \
        --disaggregation-ib-device "$DISAGGREGATION_IB_DEVICE" \
        --disaggregation-bootstrap-port 8998 \
        --speculative-algorithm EAGLE3 \
        --speculative-draft-model-path "$DRAFT_MODEL_PATH" \
        --speculative-num-steps 3 --speculative-num-draft-tokens 4 --speculative-eagle-topk 1 \
        --drafter-attention-backend tokenspeed_mla --sampling-backend greedy \
        --seed 42 --host 0.0.0.0 --port 18446 \
        --enable-metrics --metrics-port 19090 --enable-nvtx \
        --enable-log-request-stats
  2. Confirm that every prefill rank finalizes DWDP. Replace PREFILL_LOG with the path to a rank's captured standard output, and then check its startup log:

    bash
    grep 'DWDP weights ready' PREFILL_LOG

    The log line must contain DWDP weights ready: owners=16 and report owned_experts, layers, physical_bytes, and staging_bytes. Repeat the check for all 16 ranks. Do not benchmark until every rank has emitted this line and the deployment is ready.

  3. Complete the parallel deployment validation, including gateway readiness, inference, and output correctness.

Size the prefill budget and timeouts ​

Every forward streams the expert shards the worker does not own, so a DWDP prefill forward takes seconds whether it carries one token or the whole budget; the per-forward cost is paid in full by forwards well below the budget. Choose the chunk size and admission so forwards stay near the budget. Every timeout between the frontend and the decode side must then cover at least one full forward plus queueing: the gateway's per-worker silence bound (SMG --worker-wedge-secs, 3 s by default, after which every request on the worker returns 504), and in prefill/decode disaggregation TOKENSPEED_DISAGGREGATION_BOOTSTRAP_TIMEOUT (120 s) and TOKENSPEED_DISAGGREGATION_WAITING_TIMEOUT (300 s), which otherwise drop requests queued behind a saturated decode instance as KV transfer failed; the client's stream then ends with no content and no error. A larger token budget also grows the MoE activation workspace, which must fit beside the staging pools; if startup runs out of memory there, lower --gpu-memory-utilization rather than the budget.

Check feature support ​

DWDP supports local Device and Host L2 caches and auto, safetensors, or dummy checkpoint loading. K3 DWDP supports memory-saver sleep/wake with --weight-memory-policy cpu_backup; the discard policy is unsupported. Shared L3 cache control and online expert rebalancing are unsupported: L3 flushes coordinate across DP ranks, and rebalancing changes immutable expert ownership.

After startup, validate the parallel deployment and verify output correctness before benchmarking. Include the complete weight-sharing configuration with the benchmark results.

TokenSpeed documentation