Skip to content

feat(atom): GLM-5.2 ATOM on nightly_202610131505 (LMCache GTT pool, DCP pad-row fix), PP4 prefill 4P4D kit, ATOM router support - #198

Merged
xiaobochen-amd merged 12 commits into
mainfrom
dev/yaoc/glm5.3-atom-20261013
Oct 19, 2026
Merged

xiaobochen-amd merged 12 commits into
mainfrom
dev/yaoc/glm5.3-atom-20261013

Conversation

@ChengYao-amd

@ChengYao-amd ChengYao-amd commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

This PR covers three fairly independent parts:

  1. Image and patches: the ATOM nightly image moves to a new base and carries two fixes.
  2. GLM-5.2 4P4D kit: renamed; the prefill now defaults to TP1 × PP4.
  3. ATOM support in the router: DP-attention session affinity, a configurable keep-alive, and ATOM PD on the Rust router.

1. Image and patches (deploy/docker/)

The opt-in nightly build of Dockerfile.atom moves from nightly_202609221542 (ATOM d9f0720) to rocm/atom-dev:nightly_202610131505 (ATOM 661ef766, LMCache 0.5.6.dev139). The default build (ATOM_NIGHTLY=0) is unchanged.

  • Build arg renamed: ATOM_DCP_PATCHES → ATOM_NIGHTLY, and patches/atom_dcp/ → patches/atom_nightly/.
    • The old name now fails the build. Before, docker only warned about an unused arg and produced an image without the fixes.
    • ATOM_NIGHTLY=1 skips the legacy patches/atom loop (those edits are duplicate or dead code on the nightly) and runs strict patches instead: a drifted anchor fails the build.
  • Three patches dropped:
    • patch_dcp_prefill_mtp_metadata: upstreamed (ATOM #2430).
    • patch_lmcache_lookup_pin: LMCache#5098 is in the base.
    • patch_moe_eager_decode_pad: only DP-attention with eager decode triggers it, and the DCP kits do not use that.
  • New patch_lmcache_rocm_pinned_alloc.py: removes prefill stalls caused by LMCache's NUMA CPU pool on ROCm.
    • Problem: the pool was registered with hipHostRegister (KFD USERPTR). Whenever the kernel migrates one of its pages, every GPU queue of the process is evicted; stalls of 15–110 s were measured on a 256 GiB pool.
    • Fix: with HSA_USERPTR_FOR_PAGED_MEM=0, the pool comes from an exact-size hipHostMalloc (GTT, cannot migrate), as sglang#42553 does.
    • Without =0, the upstream path is kept and a warning is logged.
    • The choice is made once at import, so a pool is always freed the way it was allocated.
  • New patch_atom_dcp_sparse_pad_rows.py: fixes a Memory access fault on the prefill node under long-prefix load.
    • Problem: with sparse MLA + DCP, the DCP candidate exchange writes dcp_sparse_kv_indptr_buffer only for the scheduled rows. An eager step padded to a graph bucket therefore reads the previous step's stale offsets in its padded rows. That gives negative-length rows, and the persistent ASM decode kernel then reads out of bounds.
    • Fix: _forward_decode gives every row after scheduled_bs × max_seqlen_q an empty KV range. This is the same count the exchange writes, so plain decode and MTP verify, persistent and non-persistent, are all covered. A replayed graph runs nothing extra.
  • The AITER mha_varlen prebuild and the protobuf<7 pin are kept. The base's Mooncake version note is corrected (0.3.13, the same binary as the old nightly).
  • Upstream status is tracked in deploy/docker/patch.upstream.status.md; the conditions for dropping each patch are in patches/atom_nightly/README.md.

2. GLM-5.2 4P4D kit (examples/atom_4p4d_glm5.2/)

Renamed: atom_4p4d_glm5.2_dcp → atom_4p4d_glm5.2, along with its manual page. The default CTR changes from glm52_4p4d_dcp to glm52_4p4d.

The prefill now defaults to TP1 × PP4, following ATOM's GLM-5.2 AgentX recipe:

  • Eager mode, layer split 20,20,20,18, mem util 0.85, max-num-batched-tokens 8192, block size 16, and LMCache loads hits of any length.
  • PREFILL_PP=1 brings back the TP4 + DCP4 prefill; the README lists the settings it was validated with.
  • The decode is unchanged: TP4 + DCP4 with CUDA graphs.

New knobs: PREFILL_PP, PREFILL_PP_PARTITION, PREFILL_MAX_BATCHED_TOKENS, BLOCK_SIZE, OFFLOAD_MIN_LOAD_TOKENS, PREFILL_SEND_WORKERS (default 4, see gotcha 13) and ROUTER_BACKEND (default python).

Deployment robustness:

  • With the CPU tier on, worker.sh sets HSA_USERPTR_FOR_PAGED_MEM=0 and checks the free GTT before starting. If the pools do not fit, it fails right away instead of several minutes into the cold start.
  • wait_vram_free waits only for the GPUs the kit uses, found in KFD topology order (the HIP device order); before, it took the maximum over every GPU. A failed read counts as "not yet free" and is retried.
  • agentx takes the worker addresses from the router's /v1/workers list (parsed as JSON) and collects their server metrics, instead of hard-coding the prefill/decode ports.

3. ATOM support in the router (infera/, rust/router/)

  • Configurable keep-alive (Python router): new --timeout-keep-alive, default 900 s, also set by INFERA_TIMEOUT_KEEP_ALIVE.
    • Why: uvicorn's default is 5 s. Agentic clients reuse one connection across idle turns, and a request sent just as the server closes that connection fails with a server disconnect.
    • The Rust router never closes idle connections, so it needs no change.
  • ATOM DP-attention session affinity:
    • A mixed ATOM worker started with --enable-dp-attention registers dp_size = data_parallel_size × tp, which matches ATOM's global engine count. Without DPA, --data-parallel-size N registers N.
    • The router expands that worker into one target per rank and pins each request through the body field data_parallel_rank (ATOM does not read the X-Data-Parallel-Rank header).
    • With --session-affinity both, a session stays on one rank, so its prefix cache is reused turn after turn.
    • PD workers do not register ranks, so existing PD behaviour is unchanged.
    • Implemented in both the Python and the Rust backend.
  • ATOM PD on the Rust router (atom-mooncake, serial pull):
    • Flow: the prefill runs for one token, the router reads the kv_transfer_params it returns, and builds the decode request from them. Field for field, this matches Python's atom_mooncake.py, i.e. ATOM's own proxy.
    • A failed prefill never reaches the decode. The prefill's load is released as soon as it finishes. The decode is retried only on connect errors, so a transfer_id is never sent twice.
    • Before this change, the Rust router returned 501 for ATOM PD.
  • Docs: a new "DP-attention (ATOM)" section in manual/components/engines.md; the supported scope in rust/README.md is updated.

4. Behaviour changes and compatibility

Change Impact
ATOM_DCP_PATCHES → ATOM_NIGHTLY Old build commands fail and point to the new name
examples/atom_4p4d_glm5.2_dcp → examples/atom_4p4d_glm5.2, new default CTR Old paths and container names stop working; the new CTR uses new JIT volumes, so the first start compiles from scratch
4P4D prefill default: DCP4 → PP4 Set PREFILL_PP=1 with the settings in the README for the old layout
Python router keep-alive default 5 s → 900 s Applies to every Python router deployment; idle connections stay open for up to 15 min
Mixed ATOM workers with DP-attention get router-chosen ranks For example examples/deepseek_v4/engine/mix/atom (CONC ≥ 128): ranks used to be chosen by ATOM's least_requests, and are now chosen by the router policy (round-robin in that example). Intentional, no opt-out; see below

Mixed ATOM workers with DP-attention get router-chosen ranks

Before: a mixed ATOM worker started with -tp N --enable-dp-attention was a single target to the router. ATOM picked the rank itself through --dp-load-balance, by default least_requests (the rank with the fewest in-flight requests).

After:

  • The worker registers dp_size=N, and the router expands it into N rank targets (worker#dp0..N-1).
  • The router's policy picks one and writes it into the body field data_parallel_rank.
  • ATOM follows an explicit rank as given, so its own least_requests and ATOM_DP_SESSION_AFFINITY no longer apply.

Why:

  • With --session-affinity both, a session stays on one rank and its prefix cache is reused across turns; the measured hit rate rose from 0.50 to 0.75.
  • This is how Infera already treats SGLang's native --dp-size: expand into ranks, then let the router pick and pin.
  • So there is no opt-out.

Impact on existing deployments:

  • Without session affinity, round-robin rotates through the ranks mechanically and ignores ATOM's actual in-flight load. When request lengths vary a lot, this can balance worse than least_requests, showing up as higher TTFT and tail latency.
  • Directly affected: examples/deepseek_v4/engine/mix/atom, which uses -tp 8 --enable-dp-attention at CONC ≥ 128 with a round-robin router and no session affinity. Its performance numbers were measured with the old behaviour, and this PR has not re-run them under the new one.
  • A kv-aware policy gets no per-rank KV view (ATOM does not publish KV events per rank), so the expansion gives it nothing extra.
  • Recommendation: use round-robin + --session-affinity both for ATOM DPA deployments.

5. Validation

Unit tests at 5a7cab9f:

  • pytest tests/unit/router tests/unit/engine tests/unit/server: 786 passed.
  • cargo test (rust/) passes, and cargo clippy --all-targets -D warnings is clean.
  • Both new patches apply to the pinned upstream sources and compile.

Image + 4P4D kit: 8×MI355X, GLM-5.2-MXFP4.

Check PP4 prefill (default) DCP prefill
smoke.py (real MTP acceptance) 6/6 6/6
GSM8K (200 questions) 0.98 (16 send workers) 0.975
AgentX, 3600 s passed at C64 and C96, no transfer failure passed at C48, C64 and C96, no Memory access fault

AgentX reference numbers (same node, crsuse2-m2m-140, forced MTP acceptance AL=2.99 with K3):

CONC prefill input tok/s/GPU output tok/s/GPU TTFT p50 / p90 / p99 s errors
64 PP4 33389.60 (+8.6%) 262.13 2.09 / 5.17 / 15.74 1 / 7682
64 DCP 30739.05 242.78 3.23 / 17.81 / 49.41 1 / 7024
96 PP4 30115.94 (+44.1%) 274.59 24.98 / 51.53 / 76.31 0 / 8142
96 DCP 20902.07 193.03 51.39 / 103.55 / 161.52 0 / 5664

Router: Crusoe 140, image infera-atom:atom-router-882fcd0e.

  • 4P4D (PP4 prefill, CONC=16): 11 functional cases each for the Python and the Rust router. Rust passed all 11; Python passed all but the invalid-JSON case. The cases cover completion and chat (streaming and non-streaming), 96 mixed concurrent requests, multi-turn sessions, passthrough of a prefill rejection, a client that disconnects mid-stream, and reusing a connection after it sits idle. The Python router answers invalid JSON with 500; that bug already exists on main and is unrelated to this PR.
  • Aggregated ATOM -tp 4 --enable-dp-attention, 6 sessions × 4 turns:
    • ATOM counted 24/24 requests as explicitly routed and 0 as load-balanced.
    • With --session-affinity both, every session stayed on one rank for all 4 turns, and the prefix hit rate was 0.75, against 0.50 with affinity off (0.75 is close to the theoretical maximum).
    • The Python and Rust results are identical.
  • Keep-alive: at the default, a connection is reused after 8 s idle; with 5 s (the old behaviour), the server closes it.

6. Known limitations and follow-ups

  • Send workers (gotcha 13): with ATOM's default of 16 send workers per stage, the PP prefill hits an RDMA write that never completes (ionic CQ timeout). The root cause is unknown. 4 workers avoid the hang, but at the default settings nobody has yet checked that a ≥400k-token prompt meets the 120 s transfer deadline, and GSM8K has not been run with 4 workers.
  • Compile cache: ATOM's compile cache is not keyed on max_num_batched_tokens. After changing PREFILL_MAX_BATCHED_TOKENS, use another CTR (fresh JIT volumes), or the prefill fails at startup.
  • Session headers on Rust: the Rust router does not yet forward session headers to the engines (the Python router does).
  • PD + DP-attention: rank registration and hardware validation are left for a follow-up.
  • deepseek_v4 mixed ATOM regression: the comparison of throughput and TTFT between router-chosen ranks and ATOM's least_requests at CONC=128/256 has not been run (see section 4).

7. Merge method

Please squash-merge: the branch history contains intermediate debug commits and two merge commits without Signed-off-by, which should not land in main's history. The squashed commit message needs a Signed-off-by.

🤖 Generated with Claude Code

ChengYao-amd and others added 3 commits October 15, 2026 07:09
… ROCm pool and DCP sparse pad rows

Rebase the opt-in ATOM image from nightly_202609221542 (ATOM d9f0720) onto
rocm/atom-dev:nightly_202610131505 (ATOM 661ef766, LMCache 0.5.6.dev139).
The build arg ATOM_DCP_PATCHES / patches/atom_dcp becomes ATOM_NIGHTLY /
patches/atom_nightly: the base is an ATOM nightly, so the legacy patches/atom
loop (written for the default release base) is skipped and the strict scripts
run instead. The default build (ATOM_NIGHTLY=0) is unchanged.

- Drop patch_dcp_prefill_mtp_metadata (upstream #2430; fails on the new base),
  patch_lmcache_lookup_pin (LMCache#5098 is in the base) and
  patch_moe_eager_decode_pad (DP attention only, unused by the DCP kits).
- Keep the AITER mha_varlen prebuild and the protobuf<7 pin. On gfx950 this
  nightly loads the ASM fmha_v3 varlen module instead; the prebuild stays for
  gfx942.
- patch_lmcache_rocm_pinned_alloc.py: with LMCACHE_NUMA_MODE the LMCache CPU
  pool is mmap + mbind + hipHostRegister, a KFD USERPTR mapping whose pages the
  kernel may migrate; each migration evicts every GPU queue of the process
  (15-110 s stalls measured on a 256 GiB pool). With
  HSA_USERPTR_FOR_PAGED_MEM=0 the pool now uses LMCache's exact-size
  hipHostMalloc (GTT, not migratable), as sgl-project/sglang#42553 does for
  HiCache. Without =0 the upstream path stays and a warning says so.
- patch_atom_dcp_sparse_pad_rows.py: with sparse MLA + DCP + MTP the P/D
  producer runs an eager q_len=1 step whose padded rows keep stale
  dcp_sparse_kv_indptr_buffer offsets; a negative row length makes the
  persistent MLA kernel read past kv_indices ("Memory access fault by GPU" on
  the prefill under long-prefix load). Padded rows now get an empty KV range.
- Correct the base Mooncake version (0.3.13, same binary as the old nightly).

Co-Authored-By: Claude <[email protected]>
Signed-off-by: YaoCheng <[email protected]>
…D example

4P4D kit (atom_4p4d_glm5.2_dcp):
- The prefill with LMCache offload sets HSA_USERPTR_FOR_PAGED_MEM=0 so the
  CPU pool is GTT (one 4 x 256 GiB prefill per node fits the ~1376 GiB GTT cap).
- Backward-compatible multi-node hooks: ETCD_IP, KIT_GPUS (VRAM waits only on
  the kit's GPUs, on the docker host), REMOTE_PREFILLS and
  PREFILL_NUM_WORKERS; the libionic mount is checked on the engine's node.
- smoke: the needle cold/repeat requests share a session id, so the repeat
  lands on the same prefill; the expected prefill count follows the topology.
- agentx: scrape /metrics of the router and every worker it lists; the GPU
  count uses the validated prefill count.
- README: new image recipe and validation (smoke 6/6, GSM8K 0.975; AgentX C48
  26141.94 and C64 30579.35 input tok/s/GPU); old-base numbers kept and
  labelled.

New atom_8p4d_glm5.2_dcp: two TP4+DCP4 prefills and one TP4+DCP4 decode on
two nodes (head: prefill0 + decode + etcd/router; second node: prefill1 on
GPUs 0-3, started through DOCKER_HOST=ssh:// with the 4P4D worker.sh). Thin
kit over the 4P4D scripts. Correctness validated (router 2P/1D, smoke 6/6,
GSM8K 0.985, cross-node RDMA); AgentX C84/C96 not measured yet.

Co-Authored-By: Claude <[email protected]>
Signed-off-by: YaoCheng <[email protected]>
ChengYao-amd and others added 9 commits October 15, 2026 13:30
Image (deploy/docker/):
- patch_atom_dcp_sparse_pad_rows.py: move the clamp from
  _rebuild_sparse_dcp_persistent_metadata into _forward_decode and key it on
  the host-side row count the DCP exchange writes (scheduled_bs *
  max_seqlen_q). The padded rows of an eager step now get an empty KV range on
  q_len=1 decode and MTP verify, persistent and non-persistent alike. A
  replayed graph runs nothing extra; the previous q_len test was captured into
  the decode graphs and replayed in every indexer-owning layer each step.
- patch_lmcache_rocm_pinned_alloc.py: read HSA_USERPTR_FOR_PAGED_MEM once at
  import, so a pool is always freed by the function that allocated it.
- Dockerfile.atom: a non-empty ATOM_DCP_PATCHES (the switch's old name) fails
  the build instead of silently building without the nightly steps.

Kits (examples/atom_4p4d_glm5.2_dcp/, atom_8p4d_glm5.2_dcp/):
- worker.sh: check the docker host's free GTT before starting a prefill with
  an LMCache CPU tier, instead of failing minutes into the cold start.
- common.sh: wait_vram_free reads VRAM in KFD topology order (the order ROCr
  numbers GPUs) rather than DRM card order, and retries a failed read (an ssh
  hiccup) until the timeout. KIT_ROLES names the kit's containers on the
  docker host; prefill1.sh sets it to prefill, so a remote down touches only
  that container.
- agentx.sh: parse the router's worker list as JSON.

Validated on MI355X: 8P4D smoke 6/6, GSM8K 0.975; 4P4D AgentX C64 on the same
node and settings as before, 30739.05 input tok/s/GPU (was 30579.35), no fault.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: YaoCheng <[email protected]>
…e load and a PP prefill

New env.sh knobs, defaults unchanged (the generated docker run commands
are identical to before):
- BLOCK_SIZE (64), both legs
- PREFILL_MAX_BATCHED_TOKENS (16384)
- OFFLOAD_MIN_LOAD_TOKENS (8192)
- PREFILL_PP (1): 4 runs the prefill TP1 x PP4, eager, with
  PREFILL_PP_PARTITION layers per stage; AgentX metadata follows
- PREFILL_SEND_WORKERS (empty = ATOM's 16): Mooncake num_worker_threads

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: YaoCheng <[email protected]>
…fill

An env.sh over the 4P4D kit, as atom_8p4d_glm5.2_dcp is: the prefill
follows ATOM's GLM-5.2 AgentX recipe (TP1 x PP4, layers 20,20,20,18,
eager, chunk 8192, mem util 0.85, LMCache loads of any length), block 16
on both legs, decode unchanged otherwise. Four Mooncake send workers per
stage: ATOM's default 16 hung an RDMA write to one decode rank within
the first requests of every AgentX run on MI355X, and one missed the
120 s transfer deadline on 300k-token prompts.

On MI355X (crsuse2-m2m-140) against the 4P4D kit, input tok/s/GPU:
C64 33389.60 vs 30739.05 (+8.6%), C96 30115.94 vs 20902.07 (+44.1%).
For a comparison only; not for merge.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: YaoCheng <[email protected]>
…PP4 prefill

atom_4p4d_glm5.2_dcp and atom_4p4d_glm5.2_pp4 become atom_4p4d_glm5.2.
Its env.sh defaults are the PP4 kit's (TP1 x PP4 prefill, layers
20,20,20,18, eager, chunk 8192, mem util 0.85, block 16, LMCache loads of
any length, 4 Mooncake send workers), which beat the DCP prefill by 8.6%
at C64 and 44.1% at C96 in input tok/s/GPU. PREFILL_PP=1 still selects
the TP4 + DCP4 prefill; env.sh and the README list the settings it was
validated with. PREFILL_SEND_WORKERS now keeps an explicit empty value
(ATOM's default), so those settings can be passed from the environment.
CTR defaults to glm52_4p4d.

The 8P4D example (atom_8p4d_glm5.2_dcp) and its manual page are removed.
The kit's generic multi-node hooks (DOCKER_HOST, REMOTE_PREFILLS,
PREFILL_NUM_WORKERS, ...) stay, unused by default.

The README merges the two: PP recipe, the DCP prefill as an alternative,
validation and reference numbers of both on the current image, and the
send-worker hang as gotcha 13. The previous image's numbers are dropped.

Not run on GPUs. With docker mocked, worker.sh generates the same docker
run commands as the PP4 kit by default, and as the DCP kit with
PREFILL_PP=1 and the listed settings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: YaoCheng <[email protected]>
The Python router started uvicorn with its 5 s keep-alive default. Agentic
clients (AIPerf, agentx-harness) reuse one connection per session across idle
turns, and a client that resends just as the router closes that connection
gets ServerDisconnectedError, which AIPerf counts as a failed request.

--timeout-keep-alive (env INFERA_TIMEOUT_KEEP_ALIVE, default 900) sets
uvicorn's timeout_keep_alive. The Rust backend needs no flag: axum's serve
sets no hyper timer, so it never closes an idle client connection.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: YaoCheng <[email protected]>
An aggregated ATOM worker with --enable-dp-attention runs one engine per
attention rank, each with its own KV and prefix cache, but registered as a
single target, so the router could not keep a session on one rank.

- The ATOM launcher registers dp_size = data_parallel_size x tp under DP
  attention (ATOM's global_engine_count), for mixed workers. The router
  already expands such a worker into per-rank targets and binds sessions per
  rank.
- ATOM reads the rank from the request body (data_parallel_rank), not the
  X-Data-Parallel-Rank header. inject_dp_rank writes it for ATOM targets on
  the mixed path and on both PD legs; dp_rank_header no longer sends the
  header to ATOM.

PD workers keep registering one rank: the prefill picks its own and the
atom-mooncake hand-off reports it back.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: YaoCheng <[email protected]>
The Rust router answered 501 for ATOM PD: it only implemented the
concurrent protocols. atom-mooncake is a serial pull -- the decode body is
the prefill response's kv_transfer_params -- so it gets its own path,
mirroring the Python DisaggRouter._dispatch_serial:

- protocol.rs: prefill / hand-off / decode shaping, field for field what
  ATOM's proxy and the Python protocol send.
- disagg.rs: serial_pull POSTs the prefill for one token, releases its load
  once it answers, then POSTs (unary) or streams the decode. A failed prefill
  or a reply without a hand-off never reaches the decode and only rebinds the
  prefill session. The unary decode handling moves into finish_unary_decode,
  shared with unary_dual.
- dp.rs / proxy.rs: ATOM targets carry their DP rank in the body
  (data_parallel_rank) instead of the header, on the mixed HTTP and NATS
  paths and the ATOM PD legs.

The 4P4D GLM-5.2 kit gets ROUTER_BACKEND (python by default) to run either.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: YaoCheng <[email protected]>
@ChengYao-amd ChengYao-amd changed the title feat(atom): rebase the ATOM image on nightly_202610131505, fix LMCache ROCm pinned pool and DCP sparse pad rows; add 8P4D example feat(atom): GLM-5.2 ATOM on nightly_202610131505 (LMCache GTT pool, DCP pad-row fix), PP4 prefill 4P4D kit, ATOM router support Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants