Skip to content

EAGLE cache fix for HiCache#11215

Merged
zhyncs merged 3 commits intomainfrom
ke/fix-eagle-hicache
Oct 4, 2025
Merged

EAGLE cache fix for HiCache#11215
zhyncs merged 3 commits intomainfrom
ke/fix-eagle-hicache

Conversation

@ispobock
Copy link
Copy Markdown
Collaborator

@ispobock ispobock commented Oct 4, 2025

Motivation

#10846

Accept Length

python3 -m sglang.launch_server --model meta-llama/Llama-3.1-8B-Instruct --speculative-algo EAGLE3 \
    --speculative-draft-model-path lmsys/sglang-EAGLE3-LLaMA3.1-Instruct-8B  \
    --speculative-num-steps 2 --speculative-eagle-topk 1 --speculative-num-draft-tokens 3 \
    --dtype float16 --page-size 1 --enable-hierarchical-cache --hicache-ratio 1.2

python3 bench_sglang_eagle.py --parallel 1 --num-questions 10

main:

#questions: 10, Throughput: 333.37 token/s, Acceptance length: 2.25

this PR:

#questions: 10, Throughput: 351.13 token/s, Acceptance length: 2.39

Cache Hit Rate

 python3 benchmark/hicache/bench_multiturn.py --model-path meta-llama/Llama-3.1-8B-Instruct --disable-random-sample \
--output-length 1 --request-length 2048 \
--num-clients 80 --num-rounds 10 --max-parallel 4 --request-rate 16 \
--ready-queue-policy random --disable-auto-run --enable-round-barrier

main (page_size 1):

Performance metrics summary:
  Total requests: 800 at 16.0 requests per second
  Average Prompt Length: 11687.11 tokens
  Average Output Length: 1.00 tokens
  Average TTFT: 0.39
  P90 TTFT: 1.00
  Median TTFT: 0.22
  Average latency: 0.39
  P90 latency: 1.01
  Median latency: 0.22
  Input token throughput: 89428.71 tokens per second
  Output token throughput: 7.65 tokens per second
  Request Throughput: 7.65 requests per second
  Cache Hit Rate: 0.680656
Per-round metrics:
  Round 0: Average TTFT = 0.07s, Cache Hit Rate = 0.000461 (80 requests)
  Round 1: Average TTFT = 0.11s, Cache Hit Rate = 0.500241 (80 requests)
  Round 2: Average TTFT = 0.14s, Cache Hit Rate = 0.665864 (80 requests)
  Round 3: Average TTFT = 0.17s, Cache Hit Rate = 0.750331 (80 requests)
  Round 4: Average TTFT = 0.20s, Cache Hit Rate = 0.800206 (80 requests)
  Round 5: Average TTFT = 0.25s, Cache Hit Rate = 0.833090 (80 requests)
  Round 6: Average TTFT = 0.32s, Cache Hit Rate = 0.856926 (80 requests)
  Round 7: Average TTFT = 0.54s, Cache Hit Rate = 0.820319 (80 requests)
  Round 8: Average TTFT = 0.81s, Cache Hit Rate = 0.637789 (80 requests)
  Round 9: Average TTFT = 1.25s, Cache Hit Rate = 0.410064 (80 requests)

main (page_size 64):

Performance metrics summary:
  Total requests: 800 at 16.0 requests per second
  Average Prompt Length: 11732.38 tokens
  Average Output Length: 1.00 tokens
  Average TTFT: 0.37
  P90 TTFT: 0.91
  Median TTFT: 0.19
  Average latency: 0.37
  P90 latency: 0.91
  Median latency: 0.19
  Input token throughput: 93484.75 tokens per second
  Output token throughput: 7.97 tokens per second
  Request Throughput: 7.97 requests per second
  Cache Hit Rate: 0.687901
Per-round metrics:
  Round 0: Average TTFT = 0.07s, Cache Hit Rate = 0.000000 (80 requests)
  Round 1: Average TTFT = 0.10s, Cache Hit Rate = 0.492531 (80 requests)
  Round 2: Average TTFT = 0.13s, Cache Hit Rate = 0.661020 (80 requests)
  Round 3: Average TTFT = 0.16s, Cache Hit Rate = 0.746481 (80 requests)
  Round 4: Average TTFT = 0.19s, Cache Hit Rate = 0.797145 (80 requests)
  Round 5: Average TTFT = 0.21s, Cache Hit Rate = 0.830513 (80 requests)
  Round 6: Average TTFT = 0.29s, Cache Hit Rate = 0.855021 (80 requests)
  Round 7: Average TTFT = 0.55s, Cache Hit Rate = 0.832119 (80 requests)
  Round 8: Average TTFT = 0.83s, Cache Hit Rate = 0.630734 (80 requests)
  Round 9: Average TTFT = 1.17s, Cache Hit Rate = 0.461394 (80 requests)

this PR (page_size 1):

Performance metrics summary:
  Total requests: 800 at 16.0 requests per second
  Average Prompt Length: 11737.81 tokens
  Average Output Length: 1.00 tokens
  Average TTFT: 0.38
  P90 TTFT: 0.95
  Median TTFT: 0.20
  Average latency: 0.38
  P90 latency: 0.95
  Median latency: 0.20
  Input token throughput: 91844.92 tokens per second
  Output token throughput: 7.82 tokens per second
  Request Throughput: 7.82 requests per second
  Cache Hit Rate: 0.684252
Per-round metrics:
  Round 0: Average TTFT = 0.07s, Cache Hit Rate = 0.000000 (80 requests)
  Round 1: Average TTFT = 0.11s, Cache Hit Rate = 0.500007 (80 requests)
  Round 2: Average TTFT = 0.14s, Cache Hit Rate = 0.665707 (80 requests)
  Round 3: Average TTFT = 0.16s, Cache Hit Rate = 0.750213 (80 requests)
  Round 4: Average TTFT = 0.19s, Cache Hit Rate = 0.800117 (80 requests)
  Round 5: Average TTFT = 0.22s, Cache Hit Rate = 0.833013 (80 requests)
  Round 6: Average TTFT = 0.31s, Cache Hit Rate = 0.856861 (80 requests)
  Round 7: Average TTFT = 0.54s, Cache Hit Rate = 0.820166 (80 requests)
  Round 8: Average TTFT = 0.83s, Cache Hit Rate = 0.628042 (80 requests)
  Round 9: Average TTFT = 1.23s, Cache Hit Rate = 0.442725 (80 requests)

this PR (page_size 64):

Performance metrics summary:
  Total requests: 800 at 16.0 requests per second
  Average Prompt Length: 11692.25 tokens
  Average Output Length: 1.00 tokens
  Average TTFT: 0.38
  P90 TTFT: 0.93
  Median TTFT: 0.21
  Average latency: 0.38
  P90 latency: 0.93
  Median latency: 0.22
  Input token throughput: 91342.23 tokens per second
  Output token throughput: 7.81 tokens per second
  Request Throughput: 7.81 requests per second
  Cache Hit Rate: 0.684098
Per-round metrics:
  Round 0: Average TTFT = 0.07s, Cache Hit Rate = 0.000000 (80 requests)
  Round 1: Average TTFT = 0.10s, Cache Hit Rate = 0.492344 (80 requests)
  Round 2: Average TTFT = 0.13s, Cache Hit Rate = 0.660773 (80 requests)
  Round 3: Average TTFT = 0.16s, Cache Hit Rate = 0.746779 (80 requests)
  Round 4: Average TTFT = 0.20s, Cache Hit Rate = 0.797447 (80 requests)
  Round 5: Average TTFT = 0.24s, Cache Hit Rate = 0.830512 (80 requests)
  Round 6: Average TTFT = 0.31s, Cache Hit Rate = 0.854866 (80 requests)
  Round 7: Average TTFT = 0.52s, Cache Hit Rate = 0.821278 (80 requests)
  Round 8: Average TTFT = 0.83s, Cache Hit Rate = 0.615397 (80 requests)
  Round 9: Average TTFT = 1.21s, Cache Hit Rate = 0.460686 (80 requests)

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @ispobock, 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 crucial fixes and enhancements to integrate the EAGLE speculative decoding algorithm with the HiCache (Hierarchical Radix Cache) system. The changes ensure that the cache correctly handles EAGLE-specific key formats and value insertions, improving the overall compatibility and efficiency of the system. A new comprehensive test suite has also been added to verify the proper functioning of this integration.

Highlights

  • EAGLE Integration with HiCache: The HiRadixCache now explicitly supports the EAGLE speculative decoding algorithm, adapting its behavior based on an is_eagle flag passed during initialization.
  • EAGLE-Specific Key Handling: The match_prefix and insert methods within HiRadixCache now apply a key_convert_fn to key.token_ids, which is crucial for correctly processing EAGLE's bigram keys.
  • Value Truncation for EAGLE Inserts: When operating in EAGLE mode, the insert method in HiRadixCache ensures that the length of the inserted value is truncated to match the length of the key, maintaining data consistency for bigram keys.
  • Prefix Length Tracking: A new attribute, req.last_matched_prefix_len, has been introduced in the scheduling policy to accurately track the length of the last matched prefix for a request.
  • New Test Suite for HiCache EAGLE: A dedicated test file, test_hicache_eagle.py, has been added to validate the functionality and performance of HiCache when used in conjunction with EAGLE3 speculative decoding, including an MMLU evaluation.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

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
Copy Markdown
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 a fix to make HiCache compatible with EAGLE speculative decoding. The changes correctly propagate an is_eagle flag to the cache implementations and handle the EAGLE-specific bigram key conversion during cache matching and insertion. A new test case is also added to verify the functionality.

My feedback focuses on improving code quality by avoiding side effects. Specifically, I've suggested changes in HiRadixCache to prevent in-place modification of input arguments, which is a safer programming practice. The rest of the changes look good and address the intended issue.

@ispobock ispobock added the run-ci label Oct 4, 2025
@zhyncs zhyncs merged commit 31b49c0 into main Oct 4, 2025
131 of 142 checks passed
@zhyncs zhyncs deleted the ke/fix-eagle-hicache branch October 4, 2025 23:53
0xtoward pushed a commit to 0xtoward/sglang that referenced this pull request Oct 5, 2025
ch-tiger1 pushed a commit to ch-tiger1/sglang that referenced this pull request Oct 9, 2025
lpc0220 pushed a commit to lpc0220/sglang that referenced this pull request Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants