Skip to content

[HiCache] fix: clear storage reset state - #26009

Merged
xiezhq-hermann merged 2 commits into
sgl-project:mainfrom
alphabetc1:fix/hicache-release
Jun 13, 2026
Merged

xiezhq-hermann merged 2 commits into
sgl-project:mainfrom
alphabetc1:fix/hicache-release

Conversation

@alphabetc1

@alphabetc1 alphabetc1 commented May 21, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

HiCacheController.reset() is expected to bring the controller back to a clean state after /flush_cache or other reset paths. However, when HiCache storage is enabled, the base controller did not clear host_mem_release_queue or reset prefetch_tokens_occupied.

This can leave stale host-memory release entries from before reset. Since HiRadixCache.reset() clears the host KV pool after resetting the controller, those stale entries may later be drained and freed again, causing duplicated indices in the host pool free list. It can also leave stale prefetch accounting behind, making prefetch_rate_limited() reject future storage prefetches even though there is no active prefetch operation.

HybridCacheController.reset() already clears both states. This PR applies the same cleanup to the base HiCacheController.reset() path so base HiCache and Hybrid HiCache have consistent reset semantics.

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 #27051318911
Latest PR Test (Extra): ❌ Run #27051318881

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@xiezhq-hermann xiezhq-hermann self-assigned this May 21, 2026
@alphabetc1 alphabetc1 added the run-ci CI: run the baseline test suite on this PR label Jun 6, 2026
@xiezhq-hermann
xiezhq-hermann merged commit f4029d0 into sgl-project:main Jun 13, 2026
136 of 150 checks passed
@alphabetc1
alphabetc1 deleted the fix/hicache-release branch June 13, 2026 08:19
hzwzwzw added a commit to hzwzwzw/sglang that referenced this pull request Jul 13, 2026
…gg abort + double-free + DSv4 PP SWA + HiSparse tail

Seven upstream-merged bug/stability fixes for HiCache and DSv4 PP.
All adapted where our fork's structure differs (HostKVCache lives
inline in memory_pool_host.py rather than pool_host/base.py; some
fill_ids semantics differ).

- sgl-project#29823 (1e80d93) fix draft host pool allocator type
  kv_cache_builder.py: pass allocator_type=server_args.hicache_storage_backend
  into the draft host pool kwargs so the draft path uses the same
  allocator kind as target (was defaulting to None -> wrong allocator
  under storage-backed setups).

- sgl-project#26009 (f4029d0) clear storage reset state
  cache_controller.py reset(): also clear host_mem_release_queue and
  reset prefetch_tokens_occupied so no stale credit / stale slots survive
  a scheduler reset.

- sgl-project#27291 (b7ae714) fix SWA L3 cache miss due to prefetch/hit len mismatch
  scheduler.py: prefetch computes new_input_tokens up to
  _compute_max_prefix_len(len(fill_ids)) rather than the raw tail --
  the storage prefetch key was overshooting SWA-window match_prefix by
  up to page_size, causing systematic L3 misses on full-prefix reuse.
  Upstream uses full_untruncated_fill_ids; our fork uses fill_ids
  (equivalent surface, no _untruncated variant).

- sgl-project#30053 (48ba79c) release HiCache prefetch resources on disagg-prefill
  bootstrap-queue abort
  scheduler.py: when aborting a bootstrap-queued disagg-prefill req,
  also call tree_cache.release_aborted_request(req.rid) so its
  in-flight L2/L3 prefetch resources are released. Previously they
  leaked until process shutdown.

- sgl-project#29310 (bd2a5db) detect double-free / double-alloc in HostKVCache
  memory_pool_host.py HostKVCache: track a per-slot slot_used bool
  tensor; alloc asserts none of the returned slots is already used,
  free asserts every freed slot is currently used. Turns silent
  double-free (which corrupts the free_slots list and eventually
  causes phantom slot reuse) into a loud assertion at the call site.

- sgl-project#29106 (c1b5c7e) fix DSv4 PP HiCache SWA allocation and layer mapping
  deepseek_v4_memory_pool.py: size the SWA sub-pool by stage_layer_num
  (= len(stage_ratios)) instead of the model-global layer_num, matching
  the c4/c128 sub-pools which are already stage-local; add
  get_swa_raw_buffer(layer_id) helper that goes through _swa_local_layer_id
  for consistency.
  hybrid_pool_assembler.py: assert that swa_kv_pool.kv_buffer length
  matches transfer_layer_num (catches the mismatch that sgl-project#29106 fixes at
  the source); rename the misnamed c4_state_global_layers list --
  previously it held LOCAL layer ids but was later indexed with
  compress_state_pools[layer_id + start_layer]. Introduce a proper
  c4_state_local_layers (for c4_state_mapping keys) and a true
  c4_state_global_layers list, and index compress_state_pools /
  indexer_compress_state_pools by the real global id (no offset). Drop
  unused c128_state_mapping / c128_state_global_layers now that C128 is
  not registered with HiCache (upstream sgl-project#27293, already in base).

- sgl-project#30408 (1d8e3c2) fix DSV4 HiSparse SWA tail allocation forwarding
  disaggregation/decode.py DecodePreallocQueue:
  - Admission-control available_size for hisparse now uses
    logical_attn_allocator.full_available_size() when the SWA-tail
    prealloc path is active and that method exists, matching the
    allocation actually issued below.
  - _pre_alloc direct-to-host branch now routes through
    alloc_extend_swa_tail (with swa_tail_len and swa_evicted_seqlen
    bookkeeping) when the SWA-tail path is active; falls back to the
    original alloc_logical_only otherwise. Keeps our fork's
    mem_pool_host.alloc(fill_len) call (upstream uses
    alloc_paged_token_slots but our host pool exposes .alloc()).

Verified: AST parse OK, compileall OK across managers + mem_cache trees.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants