Skip to content

perf(serving): batch DeepSeek V4 cache metadata preparation - #216

Merged
superxf merged 1 commit into
hw-native-sys:mainfrom
high-cloud:optimize-deepseek-v4-cache-metadata-preparation
Sep 4, 2026
Merged

superxf merged 1 commit into
hw-native-sys:mainfrom
high-cloud:optimize-deepseek-v4-cache-metadata-preparation

Conversation

@high-cloud

Copy link
Copy Markdown
Contributor

Summary

Batch DeepSeek V4 cache-table and slot-mapping preparation across requests and ranks instead of constructing many small tensors per row. Decode writes table data and block counts directly into shared staging buffers, while prefill builds metadata for all requests together. The aligned GBS32 profile reduced median decode prepare_early from 12.74 ms to 5.85 ms and prefill prepare_inputs from 22.44 ms to 11.10 ms.

Changes

  • DeepSeekV4CacheMetadataBuilder: bucket compatible rows and populate block tables and slot mappings with batched NumPy operations.
  • Decode preparation: arrange active and padding rows in rank-major order and write metadata directly into shared output tensors.
  • Prefill preparation: construct block tables and slot mappings once per cache group across the request batch.
  • Existing decode metadata test: update the expected ring-table builder call count for batched construction; no new unit test is added.

Verification

  • /data/yangyaodong/code/pypto-serving/.venv-dsv4-cb49/bin/python -m pytest tests/unit/model/deepseek/test_model_components.py -q -k "cache_metadata_maps_scheduler_block_ids or prepare_prefill_inputs or prepare_decode_inputs": exit 0, 18 passed, 90 deselected.
  • /data/yangyaodong/code/pypto-serving/.venv-dsv4-cb49/bin/python tests/lint/check_headers.py: exit 0.
  • /data/yangyaodong/code/pypto-serving/.venv-dsv4-cb49/bin/python tests/lint/check_english_only.py: exit 0.
  • git ls-files -z -- "*.py" "*.pyi" | xargs -0 /data/yangyaodong/.cache/pre-commit/repowkh36_43/py_env-python3.10/bin/ruff check --config ruff.toml: exit 0.

Build prefill and decode cache tables and slot mappings in batched NumPy
operations instead of creating and copying many small tensors. Decode now
writes tables and block counts directly into shared staging buffers.

In the aligned GBS32 profile, median decode prepare_early fell from 12.74 ms
to 5.85 ms and prefill prepare_inputs fell from 22.44 ms to 11.10 ms.
@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: eb9c0a6b-040d-46e3-b8d9-7286c061ef96


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@high-cloud high-cloud closed this Sep 3, 2026
@high-cloud high-cloud reopened this Sep 3, 2026
@superxf
superxf merged commit 3368c0e into hw-native-sys:main Sep 4, 2026
10 of 11 checks passed
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