Skip to content

[perf] feat: Add Qwen3.5 MFU flops estimation - #6389

Merged
wuxibin89 merged 3 commits into
verl-project:mainfrom
liangxuZhang:codex/qwen35-mfu-flops
Jul 7, 2026
Merged

wuxibin89 merged 3 commits into
verl-project:mainfrom
liangxuZhang:codex/qwen35-mfu-flops

Conversation

@liangxuZhang

@liangxuZhang liangxuZhang commented May 18, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

  • Add MFU/FLOPs estimation for qwen3_5 and qwen3_5_moe.
  • Account for Qwen3.5 hybrid attention:
    • full attention projection FLOPs, including 2x q_proj output for the output gate
    • GatedDeltaNet projection and recurrence FLOPs
  • Account for dense/MoE MLPs, LM head, and Qwen3.5 ViT FLOPs.
  • Add regression cases in tests/utils/test_flops_counter.py.

Add concise overview of what this PR aims to achieve or accomplish. Reference related GitHub issues and PRs that help with the review.

Checklist Before Starting

  • Search for similar PRs. Paste at least one query link here: ...
  • Format the PR title as [{modules}] {type}: {description} (This will be checked by the CI)
    • {modules} include fsdp, megatron, veomni, sglang, vllm, rollout, trainer, ci, training_utils, recipe, hardware, deployment, ray, worker, single_controller, misc, perf, model, algo, env, tool, ckpt, doc, data, cfg, reward, fully_async, one_step_off
    • If this PR involves multiple modules, separate them with , like [megatron, fsdp, doc]
    • {type} is in feat, fix, refactor, chore, test
    • If this PR breaks any API (CLI arguments, config, function signature, etc.), add [BREAKING] to the beginning of the title.
    • Example: [BREAKING][fsdp, megatron] feat: dynamic batching

Test

For changes that can not be tested by CI (e.g., algorithm implementation, new model support), validate by experiment(s) and show results like training curve plots, evaluation results, etc.

API and Usage Example

Demonstrate how the API changes if any, and provide usage example(s) if possible.

# Add code snippet or script demonstrating how to use this

Design & Code Changes

Demonstrate the high-level design if this PR is complex, and list the specific changes.

Checklist Before Submitting

Important

Please check all the following items before requesting a review, otherwise the reviewer might deprioritize this PR for review.

@liangxuZhang liangxuZhang changed the title Add Qwen3.5 MFU flops estimation [perf] feat: Add Qwen3.5 MFU flops estimation May 18, 2026
@CLAassistant

CLAassistant commented May 18, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@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 FLOPs estimation support for Qwen3.5 and Qwen3.5-MoE models, including specialized logic for hybrid attention layers and GatedDeltaNet recurrence. The implementation covers both text and vision components, with corresponding test cases added. Feedback from the review highlights the need to include embedding parameters in the dense FLOPs calculation for consistency with other models and to adjust the causal attention factor from 12 to 6 to prevent overestimating the quadratic term in full-attention layers.

Comment thread verl/utils/flops_counter.py Outdated
Comment on lines +339 to +340
lm_head_N = vocab_size * hidden_size
dense_N_flops = 6 * (mlp_N + attn_linear_N + lm_head_N) * tokens_sum

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.

high

The current FLOPs estimation for the dense part only accounts for the LM head parameters, but it should also include the embedding parameters. In standard LLM architectures (like Qwen2/Llama), both the embedding and the LM head are counted. For consistency with other models in this file (e.g., _estimate_qwen2_flops), you should use 2 * vocab_size * hidden_size to account for both.

Suggested change
lm_head_N = vocab_size * hidden_size
dense_N_flops = 6 * (mlp_N + attn_linear_N + lm_head_N) * tokens_sum
emd_and_lm_head_N = 2 * vocab_size * hidden_size
dense_N_flops = 6 * (mlp_N + attn_linear_N + emd_and_lm_head_N) * tokens_sum

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment thread verl/utils/flops_counter.py Outdated
seqlen_square_sum = 0
for seqlen in batch_seqlens:
seqlen_square_sum += seqlen * seqlen
attn_qkv_flops = 12 * seqlen_square_sum * head_dim * num_attention_heads * num_full_attn_layers

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.

high

The factor 12 used for attn_qkv_flops is typically used for non-causal attention (like in ViT). For causal attention in decoder-only LLMs, the quadratic term is halved due to the causal mask, resulting in a factor of 6 for the forward and backward passes combined (3 * 2 * 0.5 * 4). Using 12 here will overestimate the attention FLOPs for the full-attention layers by 2x.

Suggested change
attn_qkv_flops = 12 * seqlen_square_sum * head_dim * num_attention_heads * num_full_attn_layers
attn_qkv_flops = 6 * seqlen_square_sum * head_dim * num_attention_heads * num_full_attn_layers

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Co-authored-by: Codex <codex@openai.com>

Signed-off-by: liangxuZhang <1028292586@qq.com>
@liangxuZhang
liangxuZhang force-pushed the codex/qwen35-mfu-flops branch from aef7612 to e818cb2 Compare May 18, 2026 10:23
@ArronHZG
ArronHZG requested review from ArronHZG and ISEEKYAN May 25, 2026 03:28
@liangxuZhang

Copy link
Copy Markdown
Contributor Author

@ISEEKYAN @ArronHZG PTAL at this PR, thanks!

@wuxibin89
wuxibin89 merged commit dbd307e into verl-project:main Jul 7, 2026
gxlvera pushed a commit to gxlvera/verl that referenced this pull request Jul 10, 2026
### What does this PR do?

- Add MFU/FLOPs estimation for `qwen3_5` and `qwen3_5_moe`.
- Account for Qwen3.5 hybrid attention:
- full attention projection FLOPs, including 2x `q_proj` output for the
output gate
  - GatedDeltaNet projection and recurrence FLOPs
- Account for dense/MoE MLPs, LM head, and Qwen3.5 ViT FLOPs.
- Add regression cases in `tests/utils/test_flops_counter.py`.

> Add **concise** overview of what this PR aims to achieve or
accomplish. Reference related GitHub issues and PRs that help with the
review.

### Checklist Before Starting

- [x] Search for similar PRs. Paste at least one query link here: ...
- [x] Format the PR title as `[{modules}] {type}: {description}` (This
will be checked by the CI)
- `{modules}` include `fsdp`, `megatron`, `veomni`, `sglang`, `vllm`,
`rollout`, `trainer`, `ci`, `training_utils`, `recipe`, `hardware`,
`deployment`, `ray`, `worker`, `single_controller`, `misc`, `perf`,
`model`, `algo`, `env`, `tool`, `ckpt`, `doc`, `data`, `cfg`, `reward`,
`fully_async`, `one_step_off`
- If this PR involves multiple modules, separate them with `,` like
`[megatron, fsdp, doc]`
  - `{type}` is in `feat`, `fix`, `refactor`, `chore`, `test`
- If this PR breaks any API (CLI arguments, config, function signature,
etc.), add `[BREAKING]` to the beginning of the title.
  - Example: `[BREAKING][fsdp, megatron] feat: dynamic batching`

### Test

> For changes that can not be tested by CI (e.g., algorithm
implementation, new model support), validate by experiment(s) and show
results like training curve plots, evaluation results, etc.

### API and Usage Example

> Demonstrate how the API changes if any, and provide usage example(s)
if possible.

```python
# Add code snippet or script demonstrating how to use this
```

### Design & Code Changes

> Demonstrate the high-level design if this PR is complex, and list the
specific changes.

### Checklist Before Submitting

> [!IMPORTANT]
> Please check all the following items before requesting a review,
otherwise the reviewer might deprioritize this PR for review.

- [x] Read the [Contribute
Guide](https://github.com/verl-project/verl/blob/main/CONTRIBUTING.md).
- [x] Apply [pre-commit
checks](https://github.com/verl-project/verl/blob/main/CONTRIBUTING.md#code-linting-and-formatting):
`pre-commit install && pre-commit run --all-files --show-diff-on-failure
--color=always`
- [x] Add / Update [the
documentation](https://github.com/verl-project/verl/tree/main/docs).
- [x] Add unit or end-to-end test(s) to [the CI
workflow](https://github.com/verl-project/verl/tree/main/.github/workflows)
to cover all the code. If not feasible, explain why: ...
- [x] Once your PR is ready for CI, send a message in [the `ci-request`
channel](https://verl-project.slack.com/archives/C091TCESWB1) in [the
`verl` Slack
workspace](https://join.slack.com/t/verl-project/shared_invite/zt-3855yhg8g-CTkqXu~hKojPCmo7k_yXTQ).
(If not accessible, please try [the Feishu group
(飞书群)](https://applink.larkoffice.com/client/chat/chatter/add_by_link?link_token=772jd4f1-cd91-441e-a820-498c6614126a).)
- [ ] If your PR is related to the `recipe` submodule, please also
update the reference to the submodule commit via `git submodule update
--remote` or `cd recipe && git pull origin main`.

Signed-off-by: liangxuZhang <1028292586@qq.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.

4 participants