Skip to content

[feat] Add SITU trtllmgen MOE - #4180

Merged
jiahanc merged 10 commits into
flashinfer-ai:mainfrom
jiahanc:jiahanc/trtllmgen-SITU-moe
Jul 29, 2026
Merged

jiahanc merged 10 commits into
flashinfer-ai:mainfrom
jiahanc:jiahanc/trtllmgen-SITU-moe

Conversation

@jiahanc

@jiahanc jiahanc commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

📌 Description

Add SiTU activation support for TRTLLM-Gen MoE for MXFP4 × MXFP8 and NVFP4 × NVFP4

🔍 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 SiTU gated activation support for FP4 MoE in routed and non-routed execution, with configurable per-expert gemm1_alpha, gemm1_beta, and gemm1_clamp_limit.
    • Extended FP4 MoE trace templates with an activation_type input to select SiTU.
  • Bug Fixes
    • Improved activation-type mapping/validation so SiTU uses the correct gated behavior.
    • Made MoE kernel/tile selection dtype-aware (activation + weight) and corrected per-token scaling eligibility during config generation.
  • Tests
    • Expanded MoE coverage for SiTU and optional per-expert parameters, including additional routed-logit and autotune regression checks.
  • Chores
    • Updated the remote BMM artifact reference and checksum.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

FP4 block-scale MoE now supports SiTU activation with validated GEMM1 parameters, updated activation mappings, dtype-aware tile selection, trace propagation, artifact metadata updates, and regression tests.

Changes

FP4 SiTU MoE support

Layer / File(s) Summary
Activation contracts and kernel mappings
include/flashinfer/trtllm/..., flashinfer/tllm_enums.py, csrc/trtllm_fused_moe_runner.cu
Adds SiTU activation enums, serialization, gated-activation handling, and fused GEMM mapping.
FP4 activation parameters and tile dispatch
flashinfer/fused_moe/core.py, csrc/trtllm_fused_moe_kernel_launcher.cu, csrc/trtllm_batched_gemm_runner.cu, flashinfer/artifacts.py
Validates and materializes SiTU parameters, updates dtype-dependent FP4 tiles and scaling filters, and changes BMM artifact metadata.
Trace schemas and reference execution
flashinfer/trace/templates/moe.py
Propagates activation type and per-expert parameters through FP4 schemas, routing references, initialization, and SiTU computation.
Runtime references and regression tests
tests/moe/*
Adds SiTU reference math, parameter wiring, routed and non-routed coverage, and NVFP4 tactic regression checks.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant FP4MoEEntryPoint
  participant TraceOrReference
  participant FP4Kernel
  participant Autotuner
  Caller->>FP4MoEEntryPoint: select activation_type=Situ
  FP4MoEEntryPoint->>FP4MoEEntryPoint: validate GEMM1 parameters
  FP4MoEEntryPoint->>TraceOrReference: provide activation parameters
  TraceOrReference->>FP4Kernel: compute or launch SiTU activation
  Autotuner->>FP4Kernel: query dtype-aware tile configurations
Loading

Possibly related PRs

Suggested labels: op: moe

Suggested reviewers: yzh119, nv-yunzheq, samuellees, iwakurarein, feih-nv

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 56.25% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding SiTU support for TRTLLM-Gen MoE.
Description check ✅ Passed The description matches the template and includes the required sections, checklist items, and test status.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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.

@jiahanc
jiahanc force-pushed the jiahanc/trtllmgen-SITU-moe branch 2 times, most recently from 80e911e to 92ead86 Compare July 27, 2026 17:52

@aleozlx aleozlx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

code review: looks good

@aleozlx aleozlx self-assigned this Jul 27, 2026
Comment thread flashinfer/trace/templates/moe.py Outdated
@flashinfer-bot

Copy link
Copy Markdown
Collaborator

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

@jiahanc

jiahanc commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run tests/moe

@flashinfer-bot

Copy link
Copy Markdown
Collaborator

GitLab MR !1062 has been updated with latest changes, and the CI pipeline #59981718 is currently running. I'll report back once the pipeline job completes.

Comment thread flashinfer/fused_moe/core.py Outdated
Comment thread flashinfer/trace/templates/moe.py Outdated
Comment thread flashinfer/trace/templates/moe.py Outdated
Signed-off-by: Siyuan Fu <siyuanf@nvidia.com>
@IwakuraRein

Copy link
Copy Markdown
Collaborator

/bot run tests/moe

@flashinfer-bot

Copy link
Copy Markdown
Collaborator

GitLab MR !1062 has been updated with latest changes, and the CI pipeline #60004670 is currently running. I'll report back once the pipeline job completes.

@jiahanc

jiahanc commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run tests/moe

@flashinfer-bot

Copy link
Copy Markdown
Collaborator

GitLab MR !1062 has been updated with latest changes, and the CI pipeline #60055550 is currently running. I'll report back once the pipeline job completes.

@jiahanc
jiahanc merged commit a34a735 into flashinfer-ai:main Jul 29, 2026
30 of 31 checks passed
jimmyzho added a commit that referenced this pull request Jul 30, 2026
…ion (#4252)

<!-- .github/pull_request_template.md -->

Add SiTU activation support for TRTLLM-Gen MoE for MXFP4 × MXFP8 and
NVFP4 × NVFP4

<!-- Link any related issues here -->

Thank you for contributing to FlashInfer! Before we review your pull
request, please make sure the following items are complete.

- [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/).

- [x] Tests have been added or updated as needed.
- [x] All tests are passing (`unittest`, etc.).

<!-- Optional: anything you'd like reviewers to focus on, concerns, etc.
-->

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

* **New Features**
* Added SiTU gated activation support for FP4 MoE in routed and
non-routed execution, with configurable per-expert `gemm1_alpha`,
`gemm1_beta`, and `gemm1_clamp_limit`.
* Extended FP4 MoE trace templates with an `activation_type` input to
select SiTU.
* **Bug Fixes**
* Improved activation-type mapping/validation so SiTU uses the correct
gated behavior.
* Made MoE kernel/tile selection dtype-aware (activation + weight) and
corrected per-token scaling eligibility during config generation.
* **Tests**
* Expanded MoE coverage for SiTU and optional per-expert parameters,
including additional routed-logit and autotune regression checks.
* **Chores**
  * Updated the remote BMM artifact reference and checksum.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------



(cherry picked from commit a34a735)

<!-- .github/pull_request_template.md -->

## 📌 Description

<!-- What does this PR do? Briefly describe the changes and why they’re
needed. -->

## 🔍 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

- [ ] 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](https://pre-commit.com/).

## 🧪 Tests

- [ ] Tests have been added or updated as needed.
- [ ] All tests are passing (`unittest`, etc.).

## Reviewer Notes

<!-- Optional: anything you'd like reviewers to focus on, concerns, etc.
-->

---------

Signed-off-by: Siyuan Fu <siyuanf@nvidia.com>
Co-authored-by: Jiahan Chang (Cyrus) <173873397+jiahanc@users.noreply.github.com>
Co-authored-by: Siyuan Fu <siyuanf@nvidia.com>
Co-authored-by: Vinnie6167 <Vinnie6167@users.noreply.github.com>
aleozlx pushed a commit that referenced this pull request Aug 21, 2026
…4460)

<!-- .github/pull_request_template.md -->

## 📌 Description

Adds SiTU-GLU activation support to the CUTLASS fused-MoE backend,
covering all SM variants (SM89/90/100/103/120) via the shared activation
kernel code.

- Adds `ActivationType::Situ = 10` enum value (consistent with the
TRT-LLM Gen path in #4180)
- Implements `SituAdaptor` with `beta` (default 4.0) and `linear_beta`
(default 25.0) per the SiTU paper (Kimi-K3)
- Uses `2·sigmoid(2z)−1` for tanh (matching the CuTe-DSL path in #4009)
— avoids `tanh.approx.f32` error amplification at `linear_beta=25`
  - Supports per-expert `situ_beta` / `situ_linear_beta` tensors
- Refactors per-expert activation param dispatch into
`setPerExpertActivationParams()` / `hasPerExpertActivationParams()`
helpers (reduces duplication across `doGatedActivationKernel` and
`doActivationKernel`)
  - Tests both default and per-expert parameters in BF16 and FP8

## 🚀 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] `pytest tests/moe/test_trtllm_cutlass_fused_moe.py` — SiTU cases
in both `test_moe` (BF16) and `test_moe_fp8`

## Reviewer Notes

<!-- Optional: anything you'd like reviewers to focus on, concerns, etc.
-->


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Added SiTU-GLU activation support for fused Mixture-of-Experts
operations.
  - Added optional global or per-expert SiTU scaling parameters.
- Added support across standard, low-latency, and FP8 MoE execution
paths.
- Added default SiTU scaling values when custom parameters are not
provided.
  - Added validation for per-expert scaling inputs.

- **Tests**
- Added coverage for default and per-expert SiTU scales, including FP8
execution.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Mickael Seznec <mickael@mistral.ai>
Co-authored-by: Claude <noreply@anthropic.com>
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.

6 participants