Skip to content

Conversation

pansicheng
Copy link
Collaborator

@pansicheng pansicheng commented Jun 17, 2025

Motivation

This PR add hf3fs support for hicache storage (#7704)

bench_multiturn results

########## --hicache-storage-backend hf3fs ##########
#Input tokens: 3145728
#Output tokens: 98304
100%|██████████| 1536/1536 [40:33<00:00,  1.58s/it]
All requests completed
Performance metrics summary:
  Total requests: 1536 at 16 requests per second
  Average TTFT: 6.73
  P90 TTFT: 11.04
  Median TTFT: 6.90
  Average latency: 12.39
  P90 latency: 15.42
  Median latency: 12.06
  Throughput: 0.63 requests per second

########## --hicache-storage-backend none ##########
#Input tokens: 3145728
#Output tokens: 98304
100%|██████████| 1536/1536 [57:39<00:00,  2.25s/it]
All requests completed
Performance metrics summary:
  Total requests: 1536 at 16 requests per second
  Average TTFT: 10.62
  P90 TTFT: 18.13
  Median TTFT: 10.19
  Average latency: 17.71
  P90 latency: 23.70
  Median latency: 18.56
  Throughput: 0.45 requests per second

Benchmark configuration and test scripts can be found in: benchmark/hf3fs/bench.sh

Modifications

Checklist

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @pansicheng, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant enhancement to the KV cache management system by integrating disk storage into the existing HiRadixCache. This "Hidisk" feature expands the total capacity of the KV cache, allowing for larger context windows or more concurrent requests by offloading less frequently accessed KV pairs to disk. The changes include a multi-tiered caching strategy with synchronous writes to memory and disk, and intelligent reads that leverage temporal locality, resulting in improved cache hit rates and overall throughput, as demonstrated by the provided benchmarks.

Highlights

  • Disk-Backed Hierarchical Cache: Introduced a new 'Hidisk' feature that integrates disk storage with the existing HiRadixCache, significantly expanding the KV cache capacity. This allows for larger context windows and improved performance by offloading less frequently accessed KV pairs to disk.
  • Multi-Tiered Cache Management: Implemented a sophisticated multi-tiered caching strategy. KV data is synchronously written to both memory and disk, and read operations intelligently fetch data from memory or disk into GPU memory, with a portion of disk data copied back to host memory to leverage temporal locality.
  • Dedicated Disk I/O Control: Added a new HiCacheControllerDisk class with dedicated threads and queues for managing disk I/O operations (writing from device to disk, loading from disk to host, and loading from disk to device), ensuring efficient and asynchronous data transfers.
  • Configurable Disk Cache: Introduced new command-line arguments (--hicache-use-disk, --hicache-disk-path, --hicache-disk-ratio, --hicache-disk-size) to enable and configure the disk-backed hierarchical cache, providing flexibility for deployment and tuning.
  • Enhanced Memory Management and Eviction: Refactored the cache eviction and load-back policies to intelligently manage KV cache across device, host, and disk tiers. The system now proactively evicts data to lower tiers (host then disk) when GPU memory is constrained and loads data back as needed.
  • Performance Benchmarking: Included a new benchmarking script (disk.sh) and updated the multi-turn benchmark to demonstrate the performance benefits of the disk-backed cache, showing improved cache hit rates and overall throughput compared to memory-only caching.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces disk storage integration into the hierarchical KV cache, significantly expanding its capacity. The changes involve adding new classes and methods to manage disk operations, updating the cache controller and radix tree logic to handle the new disk layer, and adding configuration options via server arguments. The benchmark results provided demonstrate the potential performance benefits of this feature. The code is generally well-structured, using inheritance and helper methods to manage complexity. There are a few areas identified for potential improvement related to correctness (handling device indices with overlap schedule) and maintainability (clarity of certain logic flows and documentation).

@xiezhq-hermann xiezhq-hermann self-assigned this Jun 17, 2025
@zhyncs
Copy link
Member

zhyncs commented Jun 19, 2025

Happy to see this great work! 3FS is on the way :) cc @yizhang2077

@pansicheng pansicheng force-pushed the hidisk branch 2 times, most recently from b1e8900 to cb1433e Compare June 23, 2025 13:55
Copy link
Contributor

Warning

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

3 similar comments
Copy link
Contributor

Warning

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

Copy link
Contributor

Warning

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

Copy link
Contributor

Warning

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

Copy link
Contributor

Warning

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

2 similar comments
Copy link
Contributor

Warning

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

Copy link
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 added the ready-to-merge The PR is ready to merge after the CI is green. label Jul 29, 2025
@xiezhq-hermann xiezhq-hermann merged commit 2998033 into sgl-project:main Jul 31, 2025
53 of 64 checks passed
MahmoudAshraf97 pushed a commit to MahmoudAshraf97/sglang that referenced this pull request Aug 1, 2025
TianQiLin666666 pushed a commit to TianQiLin666666/sglang that referenced this pull request Aug 1, 2025
lifuhuang pushed a commit that referenced this pull request Aug 3, 2025
Co-authored-by: Zhiqiang Xie <xiezhq@stanford.edu>
ShangmingCai pushed a commit that referenced this pull request Aug 5, 2025
Co-authored-by: Zhiqiang Xie <xiezhq@stanford.edu>
ShangmingCai pushed a commit that referenced this pull request Aug 5, 2025
Co-authored-by: Zhiqiang Xie <xiezhq@stanford.edu>
@pansicheng pansicheng deleted the hidisk branch August 6, 2025 12:06
@ykwd
Copy link
Contributor

ykwd commented Aug 13, 2025

@pansicheng Hi, I have a question regarding the code. In storage_hf3fs.py, it seems that in functions like batch_get and batch_set, the passed-in keys are used directly for read/write operations without checking the parallel_rank. When tp is not equal to 1, could this cause key conflicts across different tp values?

@pansicheng
Copy link
Collaborator Author

@pansicheng Hi, I have a question regarding the code. In storage_hf3fs.py, it seems that in functions like batch_get and batch_set, the passed-in keys are used directly for read/write operations without checking the parallel_rank. When tp is not equal to 1, could this cause key conflicts across different tp values?

@ykwd Thanks for your review! Currently in storage_hf3fs, different ranks correspond to different 3fs files. For the same key, each rank reads and writes to its own corresponding file, so there won't be any conflicts.

narutolhy pushed a commit to narutolhy/sglang that referenced this pull request Aug 17, 2025
narutolhy pushed a commit to narutolhy/sglang that referenced this pull request Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
high priority ready-to-merge The PR is ready to merge after the CI is green.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants