Skip to content

Conversation

@bangshengtang
Copy link
Collaborator

@bangshengtang bangshengtang commented Sep 4, 2025

Summary:
break down the main execute_model() function into multiple parts so that we can have better latency breakdown in profiles:

  • preprocess
  • forward
  • postprocess
  • bookkeep (includes sync)
  • draft (if spec decoding is enabled)

this is meant to be a refactor + some new function scopes, there's no functionality difference

Test Plan:
CI

run the vLLM predictor runbook and take a trace
image

Differential Revision: D81009244

@github-actions
Copy link

github-actions bot commented Sep 4, 2025

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors.

You ask your reviewers to trigger select CI tests on top of fastcheck CI.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

If you have any questions, please reach out to us on Slack at https://slack.vllm.ai.

🚀

@facebook-github-bot
Copy link

This pull request was exported from Phabricator. Differential Revision: D81009244

@mergify mergify bot added the v1 label Sep 4, 2025
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 execute_model function by breaking it down into smaller, more focused sub-functions, each wrapped in a profiling scope. This is a great improvement for code readability, maintainability, and performance profiling. The refactoring appears to be logically sound. I've identified a couple of issues with incorrect type hints in the new function signatures that should be addressed to ensure code correctness from a static analysis perspective.

Comment on lines 1461 to 1471
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 return type hint for _preprocess is incorrect. It specifies 9 elements in the tuple, but the function returns 8. Additionally, several of the types are mismatched with the actual returned values (e.g., the 3rd element is Optional[torch.Tensor] but hinted as int). This should be corrected to match the returned tuple for type consistency and to help static analysis tools.

    ) -> tuple[
        int,
        int,
        Optional[torch.Tensor],
        Optional[torch.Tensor],
        Optional[torch.Tensor],
        torch.Tensor,
        Optional[IntermediateTensors],
        dict[str, Any],
    ]:

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 type hint for logprobs_lists in the return tuple is LogprobsLists, but the value can be None if sampler_output.logprobs_tensors is None. The type hint should be Optional[LogprobsLists] to accurately reflect this.

        Optional[LogprobsLists],

@facebook-github-bot
Copy link

This pull request was exported from Phabricator. Differential Revision: D81009244

@facebook-github-bot
Copy link

This pull request was exported from Phabricator. Differential Revision: D81009244

@facebook-github-bot
Copy link

This pull request was exported from Phabricator. Differential Revision: D81009244

@facebook-github-bot
Copy link

This pull request was exported from Phabricator. Differential Revision: D81009244

@facebook-github-bot
Copy link

This pull request was exported from Phabricator. Differential Revision: D81009244

@facebook-github-bot
Copy link

This pull request was exported from Phabricator. Differential Revision: D81009244

Copy link
Collaborator

@houseroad houseroad left a comment

Choose a reason for hiding this comment

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

I like this move. It will make the profiling result easier to parse. As by product, it also break long function into smaller pieces.

Copy link
Collaborator

Choose a reason for hiding this comment

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

later we can move this into something like _post_processing.

vllm/v1/utils.py Outdated
Comment on lines +364 to +368
Copy link
Collaborator

Choose a reason for hiding this comment

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

is there a reason not to turn it on by default? how much is the overhead? (given it's just nvtx context?)

Copy link
Collaborator

Choose a reason for hiding this comment

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

For use case for extreme perf, we would like to avoid additional overhead. Although, this should be light.

@WoosukKwon WoosukKwon added the ready ONLY add when PR is ready to merge/full CI is needed label Sep 6, 2025
@mergify
Copy link

mergify bot commented Sep 6, 2025

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @bangshengtang.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

… scopes (vllm-project#24265)

Summary:

break down the main execute_model() function into multiple parts so that we can have better latency breakdown in profiles:
- preprocess
- forward
- postprocess
- bookkeep (includes sync)
- draft (if spec decoding is enabled)

this is meant to be a refactor + some new function scopes, there's no functionality difference

Test Plan:
CI

run the vLLM predictor runbook and take a trace
{F1981500506}

Reviewed By: houseroad, frank-wei

Differential Revision: D81009244
@facebook-github-bot
Copy link

This pull request was exported from Phabricator. Differential Revision: D81009244

@houseroad houseroad enabled auto-merge (squash) September 6, 2025 20:59
@WoosukKwon WoosukKwon disabled auto-merge September 6, 2025 21:02
@WoosukKwon WoosukKwon merged commit 848562b into vllm-project:main Sep 6, 2025
37 of 38 checks passed
eicherseiji pushed a commit to eicherseiji/vllm that referenced this pull request Sep 9, 2025
… scopes (vllm-project#24265)

Co-authored-by: Bangsheng Tang <bangsheng@meta.com>
skyloevil pushed a commit to skyloevil/vllm that referenced this pull request Sep 13, 2025
… scopes (vllm-project#24265)

Co-authored-by: Bangsheng Tang <bangsheng@meta.com>
FeiDaLI pushed a commit to FeiDaLI/vllm that referenced this pull request Sep 25, 2025
… scopes (vllm-project#24265)

Co-authored-by: Bangsheng Tang <bangsheng@meta.com>
xuebwang-amd pushed a commit to xuebwang-amd/vllm that referenced this pull request Oct 10, 2025
… scopes (vllm-project#24265)

Co-authored-by: Bangsheng Tang <bangsheng@meta.com>
Signed-off-by: xuebwang-amd <xuebwang@amd.com>
xuebwang-amd pushed a commit to xuebwang-amd/vllm that referenced this pull request Oct 24, 2025
… scopes (vllm-project#24265)

Co-authored-by: Bangsheng Tang <bangsheng@meta.com>
Signed-off-by: xuebwang-amd <xuebwang@amd.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready ONLY add when PR is ready to merge/full CI is needed v1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants