Clean match_prefix and prepare_for_extend for mem cache V2#11200
Conversation
Summary of ChangesHello @cctry, 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 focuses on internal code cleanup and refactoring, primarily within the Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request refactors init_next_round and prepare_for_extend to improve code structure and separate memory operations. The changes are generally good and improve code clarity. I've provided a few suggestions to further enhance maintainability and performance, including simplifying tensor creation logic and optimizing a Triton kernel by pre-computing a cumulative sum.
Motivation
Preparation for mem_cache V2.
This PR tries to clean the existing code to seperate memory operations from other procedures.
Modifications
Two function implementations are changed
init_next_round: removeadjust_max_prefix_idsto make most field setting beforematch_prefixprepare_for_extend:req_to_token_poolto include both the setting ofprefix_indicesandout_cache_loc.get_last_locfunction is replaced by a simpler implementation without searching thereq_to_token_poolAlso
req.prefix_indices, the default value is changed from[]totorch.empty((0,), dtype=torch.int64)to respect type hintchunk_cachewith correct token indices dtype (int64)Accuracy Tests
Benchmarking and Profiling
Checklist