-
Notifications
You must be signed in to change notification settings - Fork 578
refactor: communication module #1162
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @yyihuang, 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 refactors the communication module within FlashInfer to logically separate communication kernels based on their origin or intended framework, specifically for vLLM and NVIDIA's TensorRT-LLM. This change enhances modularity and ensures that only the relevant communication kernels are compiled and loaded for each specific use case, improving code organization and potentially reducing build times or memory footprint for specific deployments.
Highlights
- Module Separation: The generic
commmodule has been split into two distinct modules:vllm_commandtrtllm_comm, each responsible for loading its respective set of communication kernels. - Function Renaming: The
gen_comm_moduleandget_comm_modulefunctions were renamed togen_vllm_comm_moduleandget_vllm_comm_modulerespectively, now exclusively handling vLLM-related kernels. - New TRT-LLM Module: New functions
gen_trtllm_comm_moduleandget_trtllm_comm_modulewere introduced to manage the compilation and loading of communication kernels specific to TensorRT-LLM. - Call Site Updates: All existing calls to communication functions (
init_custom_ar,all_reduce,trtllm_lamport_initialize, etc.) have been updated to correctly reference either thevllm_commortrtllm_commmodule based on their functionality.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| 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 issue 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 is currently in preview and 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 to provide feedback.
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
-
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. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request refactors the communication module to separate vLLM and TRT-LLM kernels into distinct modules, improving modularity and maintainability. The changes are well-structured and the use of caching is appropriate. Suggestions are provided to improve code readability and consistency.
| def gen_vllm_comm_module() -> JitSpec: | ||
| return gen_jit_spec( | ||
| "comm", | ||
| "vllm_comm", | ||
| [ | ||
| jit_env.FLASHINFER_CSRC_DIR / "comm_pybind.cu", | ||
| jit_env.FLASHINFER_CSRC_DIR / "custom_all_reduce.cu", | ||
| ], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider renaming gen_vllm_comm_module to gen_comm_module_vllm for better consistency with gen_trtllm_comm_module.
| def gen_vllm_comm_module() -> JitSpec: | |
| return gen_jit_spec( | |
| "comm", | |
| "vllm_comm", | |
| [ | |
| jit_env.FLASHINFER_CSRC_DIR / "comm_pybind.cu", | |
| jit_env.FLASHINFER_CSRC_DIR / "custom_all_reduce.cu", | |
| ], | |
| def gen_comm_module_vllm() -> JitSpec: | |
| return gen_jit_spec( | |
| "vllm_comm", | |
| [ | |
| jit_env.FLASHINFER_CSRC_DIR / "comm_pybind.cu", | |
| jit_env.FLASHINFER_CSRC_DIR / "custom_all_reduce.cu", | |
| ], | |
| ) |
| return SimpleNamespace( | ||
| init_custom_ar=init_custom_ar, | ||
| dispose=dispose, | ||
| get_graph_buffer_ipc_meta=get_graph_buffer_ipc_meta, | ||
| register_buffer=register_buffer, | ||
| register_graph_buffers=register_graph_buffers, | ||
| meta_size=meta_size, | ||
| all_reduce=all_reduce, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider extracting the common arguments passed to SimpleNamespace into a dictionary or a separate function to reduce redundancy and improve readability.
| return SimpleNamespace( | |
| init_custom_ar=init_custom_ar, | |
| dispose=dispose, | |
| get_graph_buffer_ipc_meta=get_graph_buffer_ipc_meta, | |
| register_buffer=register_buffer, | |
| register_graph_buffers=register_graph_buffers, | |
| meta_size=meta_size, | |
| all_reduce=all_reduce, | |
| ) | |
| common_args = { | |
| "init_custom_ar": init_custom_ar, | |
| "dispose": dispose, | |
| "get_graph_buffer_ipc_meta": get_graph_buffer_ipc_meta, | |
| "register_buffer": register_buffer, | |
| "register_graph_buffers": register_graph_buffers, | |
| "meta_size": meta_size, | |
| "all_reduce": all_reduce, | |
| } | |
| return SimpleNamespace(**common_args) |
| return get_vllm_comm_module().init_custom_ar( | ||
| ipc_tensors, rank_data, rank, full_nvlink | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using named arguments for improved readability, e.g., return get_vllm_comm_module().init_custom_ar(ipc_tensors=ipc_tensors, rank_data=rank_data, rank=rank, full_nvlink=full_nvlink).
return get_vllm_comm_module().init_custom_ar(ipc_tensors=ipc_tensors, rank_data=rank_data, rank=rank, full_nvlink=full_nvlink)| num_ctas: The number of CTAs to use for the all reduce. | ||
| CTA upper bounds: 36. Generally, we can saturate the bandwidth even with small amount the SMs. | ||
| """ | ||
| get_comm_module().all_reduce( | ||
| get_vllm_comm_module().all_reduce( | ||
| fa, inp, out, reg_buffer, reg_buffer_sz_bytes, num_ctas | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using descriptive variable names for fa, inp, out, reg_buffer, reg_buffer_sz_bytes, and num_ctas to improve code clarity. For example, registered_allocator, input_tensor, output_tensor, registered_buffer, registered_buffer_size_bytes, and number_of_ctas.
get_vllm_comm_module().all_reduce(
registered_allocator, input_tensor, output_tensor, registered_buffer, registered_buffer_size_bytes, num_ctas
)
yzh119
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should further split the file into several python files under comm/ module. Let's do that in the next PR.
<!-- .github/pull_request_template.md --> ## 📌 Description Separate communication kernels from different sources. ## 🔍 Related Issues <!-- Link any related issues here --> ## 🚀 Pull Request Checklist Thank you for contributing to FlashInfer! Before we review your pull request, please make sure the following items are complete. ### ✅ Pre-commit Checks - [x] I have installed `pre-commit` by running `pip install pre-commit` (or used your preferred method). - [x] I have installed the hooks with `pre-commit install`. - [x] I have run the hooks manually with `pre-commit run --all-files` and fixed any reported issues. > If you are unsure about how to set up `pre-commit`, see [the pre-commit documentation](https://pre-commit.com/). ## 🧪 Tests - [x] Tests have been added or updated as needed. - [x] All tests are passing (`unittest`, etc.). ## Reviewer Notes <!-- Optional: anything you'd like reviewers to focus on, concerns, etc. -->
📌 Description
Separate communication kernels from different sources.
🔍 Related Issues
🚀 Pull Request Checklist
Thank you for contributing to FlashInfer! Before we review your pull request, please make sure the following items are complete.
✅ Pre-commit Checks
pre-commitby runningpip install pre-commit(or used your preferred method).pre-commit install.pre-commit run --all-filesand fixed any reported issues.🧪 Tests
unittest, etc.).Reviewer Notes