Skip to content

fix(scheduler): PD decode admission cap and remote-KV backpressur#1647

Open
Jasen2201 wants to merge 9 commits into
mainfrom
Jasen/custom_data
Open

fix(scheduler): PD decode admission cap and remote-KV backpressur#1647
Jasen2201 wants to merge 9 commits into
mainfrom
Jasen/custom_data

Conversation

@Jasen2201

Copy link
Copy Markdown
Contributor

Motivation

Technical Details

Test Plan

Test Result

Submission Checklist

Production replay payloads contain tool-call arguments with invalid JSON
escape sequences (\k, \p, broken \uXXXX from data redaction). The
existing _normalize_tool_call_arguments would silently leave these as
raw strings, causing Jinja chat templates to crash on .items().

Add _fix_invalid_json_escapes() to double lone backslashes before
invalid escape chars, and fall back to wrapping unparseable arguments
in {"_raw": ...} so the template never receives a plain string.
- Gate waiting→running promotion on len(running) < max_num_seqs to prevent
  unbounded growth that caused KV thrash livelock on decode consumers
- Add ATOM_PD_MAX_INFLIGHT_LOADS env var to cap concurrent remote-KV park
  slots, preventing HSA resource exhaustion under burst traffic
- Propagate prefix_cache_hit_tokens through kv_transfer_params so PD
  decode consumers inherit the producer's genuine cache-hit count
- Throttle PD backpressure log to every 100 schedule ticks (~2s)
Copilot AI review requested due to automatic review settings July 20, 2026 13:19
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every eligible PR before approval:

  • ✅ Pre Checkin: Black, Ruff, catalog schema validation, non-GPU unit tests

Heavy model tests:

  • ✅ Run after the PR is approved and Pre Checkin passes
  • ✅ Run immediately when an approval review is submitted
  • ✅ Can be requested before approval with labels
Label Tests
ci:full Run all heavy PR model tests: native ATOM, vLLM, and SGLang
ci:atom Run native ATOM model accuracy tests
ci:vllm Run ATOM vLLM OOT model accuracy tests
ci:sglang Run ATOM SGLang model accuracy tests

Heavy jobs are skipped when the PR is not approved and no matching ci:* label is present.
Add labels via the sidebar or gh pr edit 1647 --add-label <label>

@Jasen2201 Jasen2201 changed the title Jasen/custom data fix(scheduler): PD decode admission cap and remote-KV backpressur Jul 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens scheduler admission/backpressure behavior for remote-KV (prefill/decode disaggregation) so “ready-for-first-decode” consumers don’t overflow max_num_seqs, adds a prefix_cache_hit_tokens metadata field to KV-transfer handoff, and hardens OpenAI tool-call argument normalization against invalid JSON escapes.

Changes:

  • Add a scheduler regression test ensuring remote-KV decode promotion does not exceed max_num_seqs.
  • Track “parked for remote KV” sequences in the scheduler and apply admission backpressure; propagate prefix_cache_hit_tokens through KV-transfer connectors.
  • Add a fallback path for parsing model-generated tool-call arguments that contain invalid JSON escape sequences.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/test_scheduler.py Adds a regression test for remote-KV decode promotion respecting max_num_seqs.
atom/model_engine/sequence.py Initializes prefix_cache_hit_tokens from incoming kv_transfer_params.
atom/model_engine/scheduler.py Adds remote-KV parking accounting/backpressure and extra logging; adjusts remote-KV state transitions.
atom/kv_transfer/disaggregation/moriio/moriio_connector.py Includes prefix_cache_hit_tokens in KV-transfer completion metadata.
atom/kv_transfer/disaggregation/mooncake/mooncake_connector.py Includes prefix_cache_hit_tokens in KV-transfer completion metadata.
atom/entrypoints/openai/protocol.py Adds invalid-escape repair + safer fallback when deserializing tool-call arguments JSON.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 890 to 894
if seq.status == SequenceStatus.ABORTED:
self._uncount_inflight_load(seq)
seq.status = SequenceStatus.FINISHED
seq.leave_reason = "aborted"
self._rejected.append(seq)
Comment on lines +31 to +60
def _fix_invalid_json_escapes(s: str) -> str:
"""Fix invalid JSON escapes in model-generated tool-call arguments.

Models occasionally produce invalid escape sequences like ``\\k`` or
``\\p`` in function.arguments JSON. ``json.loads`` rejects these. This
helper doubles any backslash not followed by a valid JSON escape char.
"""
_VALID = frozenset('"\\bfnrtu/')
out: list[str] = []
i = 0
while i < len(s):
if s[i] == "\\":
if i + 1 >= len(s):
out.append("\\\\")
i += 1
elif s[i + 1] == "\\":
out.append("\\\\")
i += 2
elif s[i + 1] in _VALID:
out.append("\\")
out.append(s[i + 1])
i += 2
else:
out.append("\\\\")
out.append(s[i + 1])
i += 2
else:
out.append(s[i])
i += 1
return "".join(out)
@zufayu
zufayu requested a review from ZhangLirong-amd July 21, 2026 01:40
Copilot AI review requested due to automatic review settings July 24, 2026 01:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment on lines 1302 to 1307
seq.status = SequenceStatus.WAITING
if self._connector_flag("is_offload"):
self._mark_offload_load_ready(seq)
return False
self._uncount_inflight_load(seq)
return True
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.

3 participants