Skip to content

Conversation

@zhihaofang1017
Copy link

What does this PR do?

Add the _estimate_qwen3_vit_flop and _estimate_qwen3_vl_flops function to calculate the FLOPs of Qwen3-VL dense models. Update the test cases to verify the calculation accuracy of Qwen3-VL models.

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, 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
    • 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.

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 adds FLOPs estimation for Qwen3-VL models. While the intention is good, the current implementation has a few critical issues. First, a change in FlopsCounter.__init__ introduces a regression that breaks FLOPs calculation for other vision-language models like qwen2_vl. Second, the new _estimate_qwen3_vl_flops function is implemented in a way that the vision transformer (ViT) part of the calculation is never executed due to a problem in how arguments are passed, leading to incorrect FLOPs counting for qwen3_vl. I've also pointed out an inaccuracy in a docstring. Please address these critical issues to ensure the feature works as intended without breaking existing functionality.

return flops_achieved


def _estimate_qwen3_vl_flops(config,tokens_sum, batch_seqlens, delta_time, **kargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The **kargs argument will always be empty because the calling method FlopsCounter.estimate_flops does not accept or forward any keyword arguments. As a result, images_seqlens will always be None, and the ViT FLOPs calculation (vit_flops) will always be zero. This makes a significant part of this function's logic dead code and leads to incorrect FLOPs estimation for qwen3_vl.

To fix this, you need to update the signature of FlopsCounter.estimate_flops to accept additional arguments (e.g., **kwargs) and pass them along to the estimation function.

)

self.config = getattr(config, "text_config", config)
self.config = config
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

This change introduces a critical regression. While it is necessary for qwen3_vl to use the full config object to select the correct estimation function, it breaks FLOPs calculation for other vision-language (VL) models like qwen2_vl.

Other VL models rely on estimation functions like _estimate_qwen2_flops which expect a text_config object. By setting self.config to the full config for all models, these functions will receive the wrong config structure and fail with an AttributeError.

To fix this, we can special-case qwen3_vl to use the full config, while retaining the previous behavior for all other models. This ensures that the new functionality for qwen3_vl is added without breaking existing support for other models.

Suggested change
self.config = config
if config.model_type == "qwen3_vl":
self.config = config
else:
self.config = getattr(config, "text_config", config)


def _estimate_qwen3_vit_flop(images_seqlens, config):
"""
Estimate the FLOPS of the vision encoder for Qwen2 and Qwen2.5
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The docstring is inaccurate. This function estimates FLOPS for the Qwen3-VL vision encoder, not Qwen2 and Qwen2.5. Updating the docstring will prevent future confusion.

Suggested change
Estimate the FLOPS of the vision encoder for Qwen2 and Qwen2.5
Estimate the FLOPS of the vision encoder for Qwen3-VL

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.

1 participant