Skip to content

Conversation

@yyihuang
Copy link
Collaborator

📌 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

  • I have installed pre-commit by running pip install pre-commit (or used your preferred method).
  • I have installed the hooks with pre-commit install.
  • 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.

🧪 Tests

  • Tests have been added or updated as needed.
  • All tests are passing (unittest, etc.).

Reviewer Notes

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 comm module has been split into two distinct modules: vllm_comm and trtllm_comm, each responsible for loading its respective set of communication kernels.
  • Function Renaming: The gen_comm_module and get_comm_module functions were renamed to gen_vllm_comm_module and get_vllm_comm_module respectively, now exclusively handling vLLM-related kernels.
  • New TRT-LLM Module: New functions gen_trtllm_comm_module and get_trtllm_comm_module were 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 the vllm_comm or trtllm_comm module 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

  1. 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.

@yyihuang yyihuang requested a review from yzh119 June 20, 2025 01:25
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

Comment on lines +267 to +273
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",
],
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Consider renaming gen_vllm_comm_module to gen_comm_module_vllm for better consistency with gen_trtllm_comm_module.

Suggested change
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",
],
)

Comment on lines +344 to +352
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,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Consider extracting the common arguments passed to SimpleNamespace into a dictionary or a separate function to reduce redundancy and improve readability.

Suggested change
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)

Comment on lines +614 to +616
return get_vllm_comm_module().init_custom_ar(
ipc_tensors, rank_data, rank, full_nvlink
)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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)

Comment on lines 639 to 644
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
)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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
    )

Copy link
Collaborator

@yzh119 yzh119 left a 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.

@yzh119 yzh119 merged commit 15b3e65 into flashinfer-ai:main Jun 20, 2025
2 checks passed
Anerudhan pushed a commit to Anerudhan/flashinfer that referenced this pull request Jun 28, 2025
<!-- .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.
-->
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.

2 participants