8000 implement paged attention by undefined-c0der · Pull Request #367 · mirage-project/mirage · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

implement paged attention #367

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 2 commits into
base: mpk
Choose a base branch
from

Conversation

undefined-c0der
Copy link
Collaborator

**Description of change

Divide the KV Cache into pages to enable more fine-grained and efficient memory management

Related Issues:

Linked Issues:

Copy link
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements a paged attention mechanism by dividing the KV cache into fixed-size pages and adds corresponding wrappers and tests.

  • Introduce paged_attention CUDA kernel and host wrapper to manage paged KV caches
  • Update Python bindings in runtime_kernel_wrapper.cu and expose new API
  • Add and adjust Python unit tests for paged attention and decoding with normalization

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/runtime_python/test_paged_attention.py New test to compare paged_attention kernel against a Torch ref
tests/runtime_python/test_decoding_w_norm.py Updated decoding test to include RMSNorm and rotary arguments
tests/runtime_python/runtime_kernel_wrapper.cu Added paged_attention & updated single_batch_decoding wrappers
include/mirage/persistent_kernel/tasks/paged_attention.cuh Full implementation of the paged attention device task
include/mirage/persistent_kernel/tasks/kernel.h Exposed the new paged_attention task in the kernel header
Comments suppressed due to low confidence (3)

tests/runtime_python/test_paged_attention.py:162

  • [nitpick] This test only prints random ratios without any assertions. Consider adding deterministic checks (e.g., assert torch.allclose(mirage_output, torch_out, atol=1e-2)) to automatically validate correctness.
    if torch.rand(1).item() < 0.05:

tests/runtime_python/test_decoding_w_norm.py:141

  • [nitpick] This prints the output ratio but lacks assertions. Adding assert statements to compare mirage_output and torch_output within tolerance will make the test fail on regressions.
    print(torch_output / mirage_output)

tests/runtime_python/runtime_kernel_wrapper.cu:116

  • [nitpick] The parameter name rotary_emd appears to be a typo. Consider renaming it to rotary_emb or rotary_embed for consistency and clarity.
                                              bool rotary_emd,

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.

1 participant
0