Skip to content

fix: expose trigger_completion_at_end through unified API - #2894

Merged
nv-yunzheq merged 6 commits into
flashinfer-ai:mainfrom
nv-yunzheq:fix_2887
Mar 31, 2026
Merged

nv-yunzheq merged 6 commits into
flashinfer-ai:mainfrom
nv-yunzheq:fix_2887

Conversation

@nv-yunzheq

@nv-yunzheq nv-yunzheq commented Mar 25, 2026 •

Copy link
Copy Markdown
Collaborator

📌 Description

Fix issue #2887, original logic of trigger_completion_at_end equals to enable_pdl is wrong. Expose as a separate parameter in the unified API.

🔍 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

Summary by CodeRabbit

  • New Features

    • Added an optional control to choose when kernel completion is signaled, enabling early signaling to allow overlap with follow-up work or deferring until kernels finish for safety; execution paths now respect this option to improve collective communication flexibility and performance.
  • Documentation

    • Clarified API semantics and updated wording around programmatic dependent launch and completion behavior.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

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 refines the allreduce_fusion function by introducing a dedicated parameter, trigger_completion_at_end, to explicitly manage the signaling of Programmatic Dependent Launch (PDL) completion. This change resolves an issue where the completion trigger was incorrectly tied to enable_pdl, providing greater control for performance optimization and ensuring correct behavior in advanced usage scenarios.

Highlights

  • New Parameter for PDL Completion: Introduced a new trigger_completion_at_end parameter to the allreduce_fusion function, providing explicit control over when Programmatic Dependent Launch (PDL) completion is signaled.
  • Corrected PDL Logic: Resolved issue [DeepSeek][Perf] Post-MoE AllReduce trigger_completion_at_end=False #2887 by separating the trigger_completion_at_end logic from enable_pdl, which was previously incorrectly coupled, enhancing flexibility and correctness.
  • Potential Performance Gains: Enabled potential performance improvements (up to 4%+ E2E speedup for models like DeepSeek) by allowing early completion signaling for PDL-aware kernels, facilitating better overlap of operations.

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

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.

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

@coderabbitai

coderabbitai Bot commented Mar 25, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

allreduce_fusion adds a new boolean parameter trigger_completion_at_end: bool = True to control when Programmatic Dependent Launch (PDL) completion is signaled; True preserves completion-after-kernel behavior, False signals completion early to allow overlap, and the setting is ignored by the MNNVL backend.

Changes

Cohort / File(s) Summary
PDL Completion Control
flashinfer/comm/allreduce.py
Added trigger_completion_at_end: bool = True to allreduce_fusion signature and updated docstring to describe Programmatic Dependent Launch semantics and the True/False behavior. TensorRT-LLM execution path now forwards the new parameter directly instead of deriving it from launch_with_pdl.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hop through lines of code and cheer,

A toggle set, the signal's near.
True waits, False lets overlaps play—
Kernels hum and bounce away. 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description provides context by referencing issue #2887 and explaining the fix, though the related issues section and reviewer notes section lack content, and pre-commit/testing checklists are unchecked.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Title check ✅ Passed The title accurately describes the main change: exposing a new parameter through the unified API, which is the core modification in the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 introduces a new trigger_completion_at_end parameter to the allreduce_fusion function in flashinfer/comm/allreduce.py. This parameter provides more granular control over Programmatic Dependent Launch (PDL) completion signaling, enabling potential kernel overlap and performance improvements. The review feedback suggests enhancing the docstring to explicitly state that this parameter is specific to the trtllm backend, ensuring clarity for users regarding its applicability.

Comment thread flashinfer/comm/allreduce.py Outdated
Comment thread flashinfer/comm/allreduce.py Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@flashinfer/comm/allreduce.py`:
- Around line 499-505: The parameter trigger_completion_at_end is documented as
part of the unified contract but is not forwarded/validated in the MNNVL code
path (specifically where MNNVLAllReduceFusionWorkspace is constructed/used),
causing silent no-op behavior; update the code to explicitly reject/raise on any
call that passes trigger_completion_at_end when the workspace is an
MNNVLAllReduceFusionWorkspace (or when backend == "MNNVL") and adjust the
docstring to state that trigger_completion_at_end is TRTLLM-only until MNNVL
implements equivalent support so callers get an immediate error rather than
silent behavior.
- Around line 455-456: The allreduce_fusion signature must make
trigger_completion_at_end keyword-only to avoid breaking positional args: change
the signature in allreduce_fusion so trigger_completion_at_end is declared after
a * (e.g., ..., launch_with_pdl: bool = False, *, trigger_completion_at_end:
Optional[bool] = None, output: Tensor, ...) so existing positional calls keep
binding correctly. In the MNNVL-specific branches inside allreduce_fusion that
currently ignore this parameter, either forward trigger_completion_at_end to the
underlying MNNVL call if you implement support, or add validation that raises
NotImplementedError when trigger_completion_at_end is not None with a clear
message indicating MNNVL does not support it (the TRTLLM path already correctly
forwards the param). Ensure the change references the allreduce_fusion signature
and the MNNVL handling blocks so callers get consistent behavior or a clear
error.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 10857c3a-03b6-4d15-8716-417bb6a348ad

📥 Commits

Reviewing files that changed from the base of the PR and between aacc355 and df8154d.

📒 Files selected for processing (1)
  • flashinfer/comm/allreduce.py

Comment thread flashinfer/comm/allreduce.py Outdated
Comment thread flashinfer/comm/allreduce.py Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

♻️ Duplicate comments (2)
flashinfer/comm/allreduce.py (2)

498-505: ⚠️ Potential issue | 🟠 Major

Reject trigger_completion_at_end on MNNVL until backend support exists.

Lines 498-505 document this as part of the unified API, but the MNNVL branch (Lines 667-699) neither forwards nor validates it, causing a silent no-op. Add explicit validation for MNNVL and clarify docs as TRTLLM-only for now.

Proposed fix
     elif isinstance(workspace, MNNVLAllReduceFusionWorkspace):
+        if trigger_completion_at_end is not None:
+            raise ValueError(
+                "trigger_completion_at_end is only supported with TRTLLMAllReduceFusionWorkspace"
+            )
         if (
             pattern != AllReduceFusionPattern.kARResidualRMSNorm
             and pattern != AllReduceFusionPattern.kAllReduce
         ):

Also applies to: 648-699

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@flashinfer/comm/allreduce.py` around lines 498 - 505, The MNNVL code path
silently ignores the new trigger_completion_at_end flag; update the MNNVL branch
in allreduce.py to explicitly reject/validate trigger_completion_at_end when
backend == "MNNVL" by raising a clear error (or ValueError) if it is not
None/unsupported, and update the docstring/comment near
launch_with_pdl/trigger_completion_at_end to state that
trigger_completion_at_end is TRTLLM-only for now; look for the backend dispatch
/ MNNVL-specific block (the code handling MNNVL in the allreduce implementation)
and add the validation there referencing trigger_completion_at_end and
launch_with_pdl.

451-459: ⚠️ Potential issue | 🟠 Major

Make trigger_completion_at_end keyword-only to avoid positional API breakage.

Line 456 inserts a new positional parameter before output, so existing positional calls can bind tensors to the wrong argument. Move this new arg to keyword-only at the end of the signature.

Proposed fix
 def allreduce_fusion(
     input: torch.Tensor,
     workspace: AllReduceFusionWorkspace,
     pattern: int,
     launch_with_pdl: bool = False,
-    trigger_completion_at_end: Optional[bool] = None,
     # ===== OUTPUT tensors (pre-allocated, will be filled) =====
     output: Optional[torch.Tensor] = None,
     residual_out: Optional[torch.Tensor] = None,
     norm_out: Optional[torch.Tensor] = None,
@@
     # ===== Control parameters =====
     use_oneshot: Optional[bool] = None,
     fp32_acc: bool = False,
+    *,
+    trigger_completion_at_end: Optional[bool] = None,
 ) -> torch.Tensor:
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@flashinfer/comm/allreduce.py` around lines 451 - 459, The new parameter
trigger_completion_at_end should be made keyword-only to avoid breaking existing
positional calls to allreduce_fusion; move trigger_completion_at_end after the
output and residual_out parameters and introduce a bare * before it (e.g. ...,
residual_out: Optional[torch.Tensor] = None, *, trigger_completion_at_end:
Optional[bool] = None) so only trigger_completion_at_end is keyword-only, then
update any internal references and the function signature in allreduce_fusion
accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@flashinfer/comm/allreduce.py`:
- Around line 498-505: The MNNVL code path silently ignores the new
trigger_completion_at_end flag; update the MNNVL branch in allreduce.py to
explicitly reject/validate trigger_completion_at_end when backend == "MNNVL" by
raising a clear error (or ValueError) if it is not None/unsupported, and update
the docstring/comment near launch_with_pdl/trigger_completion_at_end to state
that trigger_completion_at_end is TRTLLM-only for now; look for the backend
dispatch / MNNVL-specific block (the code handling MNNVL in the allreduce
implementation) and add the validation there referencing
trigger_completion_at_end and launch_with_pdl.
- Around line 451-459: The new parameter trigger_completion_at_end should be
made keyword-only to avoid breaking existing positional calls to
allreduce_fusion; move trigger_completion_at_end after the output and
residual_out parameters and introduce a bare * before it (e.g. ...,
residual_out: Optional[torch.Tensor] = None, *, trigger_completion_at_end:
Optional[bool] = None) so only trigger_completion_at_end is keyword-only, then
update any internal references and the function signature in allreduce_fusion
accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b3adf7e1-2e15-41e9-abc5-632e31b4efc2

📥 Commits

Reviewing files that changed from the base of the PR and between df8154d and f0e3178.

📒 Files selected for processing (1)
  • flashinfer/comm/allreduce.py

@nv-yunzheq

Copy link
Copy Markdown
Collaborator Author

/bot run

@flashinfer-bot

Copy link
Copy Markdown
Collaborator

GitLab MR !462 has been created, and the CI pipeline #47004057 is currently running. I'll report back once the pipeline job completes.

@nv-yunzheq nv-yunzheq changed the title expose trigger_completion_at_end through unified API fix: expose trigger_completion_at_end through unified API Mar 25, 2026
@flashinfer-bot

Copy link
Copy Markdown
Collaborator

[FAILED] Pipeline #47004057: 13/20 passed

@nv-yunzheq
nv-yunzheq enabled auto-merge (squash) March 30, 2026 17:02
@nv-yunzheq
nv-yunzheq merged commit 81406d9 into flashinfer-ai:main Mar 31, 2026
34 of 50 checks passed
@nv-yunzheq
nv-yunzheq deleted the fix_2887 branch March 31, 2026 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants