[4/4] Introduce CachedKernel to reduce CSGMV kernel launch overheads #10704
[4/4] Introduce CachedKernel to reduce CSGMV kernel launch overheads #10704
Conversation
…end (#10273) Signed-off-by: Shangming Cai <csmthu@gmail.com>
Signed-off-by: Shangming Cai <csmthu@gmail.com>
…mark stats output (#10525)
Co-authored-by: fujianhao.fjh <fujianhao.fjh@antgroup.com>
Signed-off-by: Shahar Mor <smor@nvidia.com>
Co-authored-by: Jinyan Chen <jinyanc@nvidia.com>
Co-authored-by: Baizhou Zhang <sobereddiezhang@gmail.com>
Co-authored-by: a4zhangfei <a4zhangfei@qq.com> Co-authored-by: Qiaolin-Yu <liin1211@outlook.com>
…y by 10x; e2e up to 3.54% faster (#10586)
…#10319) Co-authored-by: Teng Ma <sima.mt@alibaba-inc.com> Co-authored-by: huangtingwei <141888744+huangtingwei9988@users.noreply.github.com> Co-authored-by: shicang <shicang@shicang> Co-authored-by: Shangming Cai <csmthu@gmail.com>
Summary of ChangesHello @lifuhuang, 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 enhancing the performance and modularity of the inference engine, particularly for LoRA and disaggregated setups. It introduces a new speculative decoding algorithm and expands multimodal model support, while also ensuring more predictable inference behavior through deterministic settings. The changes aim to improve efficiency, flexibility, and the range of supported models within the system. 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 is a large pull request that introduces several significant features and refactorings. The main changes include the introduction of CachedKernel to reduce kernel launch overheads, support for lookahead speculative decoding, and deterministic inference. There are also major refactorings in the disaggregation connection logic, attention backend selection, and the Rust router's worker management. Additionally, new models and attention backends are added. The code quality is generally high, with good use of design patterns like registries and builders to improve modularity and maintainability. My review focuses on potential issues and areas for improvement in the new and refactored code.
| try: | ||
| url = f"http://{self.bootstrap_addr}/route?engine_rank={-1}&target_dp_group={-1}" | ||
| url = f"http://{self.bootstrap_addr}/route?engine_rank={-1}&target_dp_group={-1}&target_pp_rank={-1}" | ||
| response = requests.get(url) |
There was a problem hiding this comment.
This requests.get call is missing a timeout. Other network requests in this file have a timeout set (e.g., line 139, 372), and adding one here would prevent the thread from hanging indefinitely if the bootstrap server is unresponsive.
| response = requests.get(url) | |
| response = requests.get(url, timeout=5) |
| else: | ||
| from vllm._custom_ops import awq_dequantize | ||
| pass |
There was a problem hiding this comment.
| def init_engine(self): | ||
| # TransferEngine initialized on ascend. | ||
| local_ip = get_local_ip_by_remote() | ||
| local_ip = get_local_ip_auto() |
There was a problem hiding this comment.
The new get_local_ip_auto function can raise a ValueError if it fails to determine the IP address and no fallback is provided. In a server context, this could prevent the service from starting in certain network environments. It would be safer to provide a fallback to bind to all interfaces.
| local_ip = get_local_ip_auto() | |
| local_ip = get_local_ip_auto(fallback="0.0.0.0") |
| def grid(META): | ||
| max_seq_len = max(seq_lens_cpu) | ||
| return ( | ||
| num_program(META, args), | ||
| len(seq_lens_cpu), # batch_size | ||
| (max_seq_len + META["BLOCK_M"] - 1) // META["BLOCK_M"], | ||
| triton.cdiv(dim, META["BLOCK_N"]), | ||
| ) |
There was a problem hiding this comment.
The new grid calculation launches kernels for every sequence up to the max_seq_len in the batch. For batches with varying sequence lengths, this will launch many empty kernels for shorter sequences, which then exit early due to the segment_len <= 0 check. This can introduce significant kernel launch overhead. It might be more efficient to compute a tighter grid, similar to the previous implementation's num_program function, to only launch kernels that will do actual work.
| # Compute common indices once to avoid duplication | ||
| last_steps_all = (accepted_length - 1).to(torch.int64) | ||
| valid_state_indices = state_indices_tensor[valid_mask].to(torch.int64) | ||
| last_steps = last_steps_all[valid_mask].to(torch.int64) | ||
|
|
||
| if valid_state_indices.numel() > 0: | ||
| chunk = 256 | ||
| num_valid = valid_state_indices.numel() | ||
|
|
||
| # SSM state updates | ||
| for i in range(0, num_valid, chunk): | ||
| idx = valid_state_indices[i : i + chunk] | ||
| steps = last_steps[i : i + chunk] | ||
| # per (cache line, step) | ||
| for j in range(idx.numel()): | ||
| ci = idx[j].item() | ||
| st = steps[j].item() | ||
| ssm_states[:, ci, :].copy_( | ||
| intermediate_state_cache[:, ci, st].to( | ||
| ssm_states.dtype, copy=False | ||
| ) | ||
| ) | ||
|
|
||
| # Conv window updates | ||
| for i in range(0, num_valid, chunk): | ||
| idx = valid_state_indices[i : i + chunk] | ||
| steps = last_steps[i : i + chunk] | ||
| for j in range(idx.numel()): | ||
| ci = idx[j].item() | ||
| st = steps[j].item() | ||
| conv_states[:, ci, :, :].copy_( | ||
| intermediate_conv_window_cache[:, ci, st].to( | ||
| conv_states.dtype, copy=False | ||
| ) | ||
| ) | ||
| valid_state_indices = state_indices_tensor[valid_mask].to(torch.int64) # [N] | ||
| last_steps = last_steps_all[valid_mask].to(torch.int64) # [N] | ||
|
|
||
| # scatter into ssm_states at the chosen cache lines | ||
| ssm_states[:, valid_state_indices, :] = intermediate_state_cache[ | ||
| :, valid_state_indices, last_steps | ||
| ].to(ssm_states.dtype, copy=False) | ||
|
|
||
| # Scatter into conv_states at the chosen cache lines | ||
| conv_states[:, valid_state_indices, :, :] = intermediate_conv_window_cache[ | ||
| :, valid_state_indices, last_steps | ||
| ].to(conv_states.dtype, copy=False) |
Motivation
TODO
Modifications
Accuracy Tests
Benchmarking and Profiling
Checklist