Skip to content

[Perf] hicache: Unify PP prefetch hit queries and buffer allocation - #43344

Merged
huangtingwei9988 merged 6 commits into
sgl-project:mainfrom
antgroup:pp_hicache_opt
Oct 20, 2026
Merged

huangtingwei9988 merged 6 commits into
sgl-project:mainfrom
antgroup:pp_hicache_opt

Conversation

@huangtingwei9988

@huangtingwei9988 huangtingwei9988 commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Query each PP rank’s local storage and allocate prefetch buffers before synchronizing the usable prefix. Combine storage hits and allocation success in the existing MIN reduction, enabling file and other storage backends to use the same PP prefetch flow.
Remove Mooncake’s cross-rank query path and trim surplus buffers after synchronization, preserving the existing prefetch admission and completion interfaces.

Modifications

Accuracy Tests

Speed Tests and Profiling

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

CI States

Latest PR Test (Base): ✅ Run #39187608720
Latest PR Test (Extra): ✅ Run #39187608707
Latest PR Test (AMD ROCm 10): ❌ Run #39187608715

@github-actions github-actions Bot added the hicache Hierarchical Caching for SGLang label Oct 9, 2026
@huangtingwei9988 huangtingwei9988 added run-ci CI: run the baseline test suite on this PR run-ci-extra CI: also run the extra suite (requires run-ci) labels Oct 9, 2026
@huangtingwei9988

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

Cap local PP prefetch allocation to page-aligned available KV slots before
the existing MIN reduction, preserving a common hit under host pressure.

Add a file-backend regression for 8192/2048 hits with 4096/4097 capacity.
@huangtingwei9988

Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

1 similar comment
@huangtingwei9988

Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

@huangtingwei9988

Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

@huangtingwei9988

Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

@huangtingwei9988

Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

@huangtingwei9988

Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@huangtingwei9988

Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

1 similar comment
@huangtingwei9988

Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

@github-actions

This comment has been minimized.

@huangtingwei9988 huangtingwei9988 changed the title [HiCache] Unify PP prefetch hit queries and buffer allocation [Perf][HiCache] Unify PP prefetch hit queries and buffer allocation Oct 20, 2026
@github-actions

This comment has been minimized.

@huangtingwei9988 huangtingwei9988 changed the title [Perf][HiCache] Unify PP prefetch hit queries and buffer allocation [Perf] Unify PP prefetch hit queries and buffer allocation Oct 20, 2026
@github-actions

This comment has been minimized.

@huangtingwei9988 huangtingwei9988 changed the title [Perf] Unify PP prefetch hit queries and buffer allocation [Perf] hicache: Unify PP prefetch hit queries and buffer allocation Oct 20, 2026
@huangtingwei9988
huangtingwei9988 merged commit 3eb4bd5 into sgl-project:main Oct 20, 2026
207 of 227 checks passed
xiezhq-hermann added a commit that referenced this pull request Oct 28, 2026
Resolves the rebase against #43344 (the PP ticket thread now runs the hit
query itself, so the scheduler-thread reduce this branch guarded is gone and
the ticket-thread failure hook moves to its unconditional exit), #44614 (the
degrade cut reuses the deadline_expired machinery) and the shared-memory
count exchange in _sync_hicache_ready_counts (the health bit is split out on
that path too). Test fixtures gain the attributes main added.
detain pushed a commit to detain/sglang that referenced this pull request Oct 30, 2026
…liveness

A gloo timeout inside the HiCache storage worker collectives (the query
thread's hit MIN, the sync thread's ack MIN) killed the worker on every
rank, so one rank stuck in its backend left every rank unable to publish
L3 queries or acks: under wait_complete every later L3-hit request waited
forever, under timeout every one paid the full deadline. sgl-project#43550 guards the
backend call only, not the collective, and nothing checked worker liveness.

Wrap every worker-thread collective: on failure log once, flag the
controller (storage_sync_failed), publish the operation as FAILED (0 hits,
0 completed tokens) and keep the thread alive; after the first failure the
broken groups are skipped so the per-rank publication sequence stays
intact for the queue-count drain. Fold a rank-local health bit (no sync
failure and all storage workers alive) into the MIN-reduce the scheduler
thread drain already issues; when the agreed bit drops, apply
storage_failure_policy: "disable" (default) degrades to no-L3 until the
backend is re-attached (no new prefetch/backup, in-flight prefetches cut
like a deadline, drained hits read as misses, progress frozen, gauge
sglang:hicache_storage_healthy -> 0), "raise" fails the scheduler. A new
storage_sync_timeout extra-config key bounds the sync groups' gloo
timeout so a hung peer is detected before torch's 30-minute default.

LIVE premise on this stack at 78783f0 (quoted from
python/sglang/srt/managers/cache_controller.py:1505-1529) -- the bare,
unprotected hit reduce on the query thread:

    # Outside the guarded query on purpose: every rank must run the
    # same number of hit-count all_reduces or the sync threads
    # deadlock, so a locally failed query still participates (with
    # a zero) instead of skipping the collective.
    storage_hit_count = self._sync_prefetch_hit_query(
        operation, storage_hit_count
    )
    ...
    def _sync_prefetch_hit_query(self, operation, storage_hit_count: int) -> int:
        """Rank-reduce a hit query (MIN) so every rank agrees on the usable
        prefix. Runs for every operation, hit or miss."""
        hit_count = torch.tensor(storage_hit_count, dtype=torch.int)
        self._all_reduce(
            hit_count,
            torch.distributed.ReduceOp.MIN,
            self.prefetch_hits_sync_groups,
        )
        return int(hit_count.item())

Port adaptations (cherry-pick -x of 6fa9f21 with conflicts resolved
against the post-MERGE-sgl-project#5 + B3 re-plant tree):

- The fork's rank-invariant mask payload (entries 209/290, B3's
  mask-packs-only-when-TRAILING_PAGES refinement) is KEPT on
  hybrid_cache_controller._sync_prefetch_hit_query; the wrapper only
  converts a failed reduce into "no agreed boundary" ({} verdicts, 0
  hits), so the collective PAYLOAD contract is unchanged. Verified
  against the tests' reduce mocks (trailing_endpoint,
  buffer_mode_sidecar).
- Upstream's guarded scheduler-thread reduce inside get_prefetch_submission
  does not exist on this tree (sgl-project#43344 shape, which the PR's own
  60c5f3e rebase resolved the same way): the ticket thread runs the
  hit query, so the failure hook lands on its unconditional except-exit,
  and the fork's test_command_failure keeps later submissions ticketed.
- The health bit folds into _sync_hicache_ready_counts AFTER the queue-
  size reads (flag-published-before-item order: a counted failed item
  implies the 0 bit in the same round), keeping the entry-293
  pending_storage_hits park/drain and identity guard in
  _drain_and_alloc_storage_hit between the PR's degraded inserts; the
  entry-294 deferred ready-sync stays a no-op path (it refuses
  storage-attached setups).
- The PR's shm-exchange split-out of the health bit (its 60c5f3e
  merge resolution) FOLDS IN HERE: this tree already carries the shm
  exchange, so a 4-tuple return from the mins path would break the
  5-tuple unpack at this commit. Row width stays 8, so storage-enabled
  rounds take the gloo reduce until the PR's shm-width commit lands
  (test_shm_tag_exchange expectations track that).
- parse_storage_backend_extra_config REGISTERS storage_failure_policy
  and storage_sync_timeout (non-consuming validate; attach stays the
  application point), so a bad extra-config fails at parse time on both
  the boot and runtime PUT paths.
- check_prefetch_progress degrades via the entry-217 deadline machinery
  WITHOUT retry re-arm (poll_miss stays un-armed exactly like the
  deadline branch; the shared retry cap of entry 293 is untouched).
- Fork-only test stubs that bypass __init__ memoize the new attribute in
  the same convention: test_hybrid_storage_sparse_allocation's
  TestSparseCheckpointCacheDrain cache gains storage_unavailable=False
  (its drain reaches the new degraded reads; the file does not exist
  upstream so the PR could not adapt it).

Gate at this commit (CVD=9, prod venv, PYTHONPATH=wt/python): trailing_
endpoint 17P, pp_prefetch_ticket 17P/19sub, buffer_mode_sidecar 6P/6sub,
storage_prefetch_lifecycle 28P/31sub, sparse_allocation (entry-290)
13P/14sub, pp_sync_drain 4P, async_ready 7P,
shm_tag_exchange green, NEW test_hicache_storage_sync_recovery 4P/4sub
(2-rank gloo spawn, CPU-honest), managers trio green; import sglang
proven from the tree.

(cherry picked from commit 6fa9f21)
(cherry picked from commit e63240993bd528a90d0d323035f08217de07a9b6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hicache Hierarchical Caching for SGLang run-ci CI: run the baseline test suite on this PR run-ci-extra CI: also run the extra suite (requires run-ci)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants