[runtime][vm] Add LoRA adapter metadata to paged KV cache by MagellaX · Pull Request #18890 · apache/tvm
Summary of Changes
Hello, 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 establishes the foundational runtime support for LoRA adapter metadata within the paged KV cache. It provides the necessary plumbing to track and manage LoRA adapter IDs at the sequence level, which is a crucial building block for future multi-LoRA serving capabilities. The changes are focused purely on runtime state management and do not yet include frontend request handling, LoRA execution in model operations, or specialized batching logic.
Highlights
- LoRA Adapter ID in Sequence: The
Sequencestruct now includes alora_adapter_idfield to associate a LoRA adapter with each sequence in the KV cache. - New KV Cache APIs: Introduced new runtime APIs to set and get the LoRA adapter ID for a specific sequence, and to retrieve the LoRA adapter IDs for the current batch after
BeginForward. - LoRA ID Inheritance: When a sequence is forked, the child sequence now inherits the
lora_adapter_idfrom its parent. - Batch LoRA ID Population: The
current_lora_adapter_ids_host_is populated with the adapter IDs of the sequences in the current batch duringBeginForward. - Python Runtime Tests: Added comprehensive Python runtime tests to validate the default adapter ID, set/get functionality, fork inheritance, and correct ordering of current-batch adapter IDs.
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.
Changelog
- src/runtime/vm/attn_utils.h
- Added
lora_adapter_idto theSequencestruct.
- Added
- src/runtime/vm/kv_state.cc
- Registered new FFI methods for setting, getting, and retrieving current batch LoRA adapter IDs.
- src/runtime/vm/kv_state.h
- Declared virtual methods
SetSequenceLoraAdapter,GetSequenceLoraAdapter, andGetCurrentLoraAdapterIdsinAttentionKVCacheObj.
- Declared virtual methods
- src/runtime/vm/paged_kv_cache.cc
- Added
current_lora_adapter_ids_host_member to store LoRA adapter IDs for the current batch. - Initialized
current_lora_adapter_ids_host_during object construction. - Modified
ForkSequenceto ensure child sequences inherit the parent'slora_adapter_id. - Populated
current_lora_adapter_ids_host_with sequence LoRA adapter IDs duringBeginForward. - Implemented
SetSequenceLoraAdapterto update a sequence's LoRA adapter ID. - Implemented
GetSequenceLoraAdapterto retrieve a sequence's LoRA adapter ID. - Implemented
GetCurrentLoraAdapterIdsto return the LoRA adapter IDs of the current batch.
- Added
- tests/python/relax/test_runtime_builtin_paged_attention_kv_cache_cpu.py
- Declared and assigned global function variables for the new LoRA adapter APIs.
- Added
test_lora_adapter_metadatato verify LoRA adapter ID functionality, including default values, setting/getting, fork inheritance, and current batch ordering.
Activity
- No human activity (comments, reviews) has been recorded on this pull request yet.
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.
-
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. ↩