Skip to content

fix: first hash of prefix cache with same model name #1341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions pkg/epp/scheduling/framework/plugins/multi/prefix/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,12 @@ func hashPrompt(ctx context.Context, request *types.LLMRequest, cacheBlockSize i
// If the last block is smaller than cacheBlockSize, it will be ignored.
res := make([]BlockHash, 0, 1+len(prompt)/cacheBlockSize)
// Add the model to the first block hash so that different models have different hashes even with the same body.
res = append(res, BlockHash(xxhash.Sum64String(request.TargetModel)))
for i := 0; i+cacheBlockSize <= len(prompt); i += cacheBlockSize {
if len(prompt) >= cacheBlockSize {
firstBlock := prompt[0:cacheBlockSize]
combined := append([]byte(request.TargetModel), firstBlock...)
res = append(res, BlockHash(xxhash.Sum64(combined)))
}
for i := cacheBlockSize; i+cacheBlockSize <= len(prompt); i += cacheBlockSize {
block := prompt[i : i+cacheBlockSize]
prevBlockHash := res[len(res)-1]
block = append(block, toBytes(prevBlockHash)...)
Expand Down