[refactor] enable page size > 1 for fi backend - #110
Open
zzh-stable wants to merge 1 commit into
Open
Conversation
Collaborator
|
Hi @zzh-stable . Thanks for your contribution. We don't use page-size > 1 for flashinfer, because it seems that there's clear performance gain. Also, in SGLang, we also treat the page-size = 1 for flashinfer backend. Could you do some local micro benchmarks and share the results? We should not optimize too much before profiling. BTW, actually the page-size of attention backend should eventually be decoupled from the allocation page-size (attn-page-size should be no larger than alloc-page-size). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[refactor] enable page size > 1 for fi backend
Motivation:
While reviewing the code, I noticed that the
FlashInferBackend(fi.py) currently hardcodes thepage_sizeconstraint to1during attention computation. This triggers_flatten_cacheduring inference, which forcefully flattens the cache into a single-token granularity. Considering that the FlashInfer kernel actually fully supports configurable PagedAttention block sizes, I made a simple refactor to allow it to directly accept and support the system-configuredpage_size. This should make the overall data dimension reduction and transfer between the frontend and backend more natural.Main Changes:
FIMetadatathat only supportspage_size=1, and dropped the_flatten_cachedimension flattening logic forkv_cachein theforwardstage.prepare_metadata), implemented stride-based sampling usingpage_sizeto translate them into physical page numbers (Block IDs). Synchronously aligned the unit length of placeholder memory allocated during CUDAGraph capture, and added the calculation for the actual valid padding length of the last page (last_page_len_cpu).Testing Status: