Skip to content

perf: build KV slot mappings by page ranges - #577

Open
T4t4KAU wants to merge 2 commits into
InfiniTensor:InfiniLM-v0.2.9cfrom
T4t4KAU:perf/kv-slot-ranges
Open

T4t4KAU wants to merge 2 commits into
InfiniTensor:InfiniLM-v0.2.9cfrom
T4t4KAU:perf/kv-slot-ranges

Conversation

@T4t4KAU

@T4t4KAU T4t4KAU commented Sep 17, 2026

Copy link
Copy Markdown

Summary

Build KV slot mappings one physical-page range at a time, and reuse the mapping helper for allocation and speculative append. Keep a dedicated single-token path. This removes repeated division/modulo for tokens within the same page.

Motivation

Long prefill and speculative intervals previously calculated each physical slot separately. The new implementation produces identical lists for partial pages and reordered physical blocks with fewer Python iterations.

Type of Change

  • perf — performance improvement with unchanged behavior

Test Results of Involved Models on Supported Platforms

Local CPU validation covered boundary intervals, 2,000 seeded randomized intervals, cached-prefix allocation, speculative append/rollback, and allocation failure. These checks were performed during development; no unit-test or test-support files are included in the final PR diff. Repository formatting checks and git diff --check passed.

Full-model single-request, offline, sanity, and service tests were not run: this validation isolates Python cache metadata and has no local model weights. No accelerator throughput claim is made.

Benchmark / Performance Impact

Intel Core i5-14600KF, Python 3.12.13; Python integer metadata (dtype N/A). Baseline: 270feb3. Timed update_blocks_slot with reversed physical-page order and logical start offset 7; fixture creation excluded. Five warmup calls, median of seven rounds, max(10, 100000 // token_count) calls per round, perf_counter_ns; CPU not pinned. Outputs checked against baseline before timing. Temporary local harness, not committed.

Page size Tokens Before (µs/call) After (µs/call)
16 128 3.719 1.703
16 4096 151.945 63.430
256 1 0.099 0.081
256 128 3.754 0.430
256 4096 153.170 26.265
256 32768 1258.954 190.769

These are CPU microbenchmarks, not end-to-end model results; gains depend on interval and page sizes.

Notes for Reviewers

Branch starts directly at 270feb3 on InfiniLM-v0.2.9c. Allocation, ownership, hash publication, and eviction behavior are unchanged.

CI / ChatOps

CI has not been triggered. Accelerator/model validation remains for maintainers with a configured environment.

Checklist

  • Conventional Commits title and commit; matching perf/ branch; squashable commit history; no merge/fixup/WIP commits.
  • Based directly on the requested InfiniLM-v0.2.9c release branch (instead of main).
  • N/A — legacy issue-format exception.
  • Minimal scope; no debug/dead code or unrelated formatting.
  • Public signatures remain compatible.
  • English comments/docstrings, trailing newlines, and whitespace checked.
  • Python files checked with scripts/format.py; no changes to auto_config.py.
  • N/A — C++ checks and native build: Python-only changes.
  • Local correctness checks and before/after CPU benchmarks completed; omitted model/platform tests explained above.
  • Additional platform validation and reviewer assignment.
  • Manual CI run.
  • N/A — user documentation and breaking-change notice: behavior and workflow unchanged.
  • No secrets, new third-party code, or unsafe memory operations.

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.

1 participant