Skip to content

Conversation

@mengchengTang
Copy link
Contributor

@mengchengTang mengchengTang commented Nov 27, 2025

What does this PR do?

Updated Description: This PR fixes the missing rollout profiling data issue caused by the Agent Loop architecture shift.

Root Cause: Inference requests now bypass the generate_sequences method of the worker, causing missing performance data during the rollout phase in Discrete Mode.

Solution: We add explicit profiling control to support the current rollout workers. This is a backward-compatible fix.
New methods start_capture_profile and stop_capture_profile in DistProfiler and Workers.
AgentLoopManager now manually starts and stops profiling via vLLMReplica around inference requests.

This ensures existing rollout workers can collect performance data correctly.

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

@CLAassistant
Copy link

CLAassistant commented Nov 27, 2025

CLA assistant check
All committers have signed the CLA.

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 introduces profiling capabilities for the agent loop by adding start_profile and stop_profile methods to AgentLoopManager, vLLMHttpServerBase, and vLLMReplica. The changes correctly propagate the profiling calls down to the workers. My review includes one high-severity suggestion to fix a blocking call (ray.get) within an asynchronous actor in vLLMHttpServerBase, which should be converted to a non-blocking asyncio.gather to prevent blocking the event loop and to maintain consistency with other asynchronous methods in the class.

@mengchengTang mengchengTang force-pushed the profiler_support_agent_loop branch from b620922 to d721a17 Compare November 27, 2025 09:28
@mengchengTang mengchengTang marked this pull request as draft November 28, 2025 02:14
@tardis-key
Copy link
Contributor

It can be seen that the overall process control and the actual profiling startup are far apart, and the original solution requires passing the calling function many times, which is not elegant enough.

if (not self.discrete or self.async_start) and NPUProfiler._define_count == 0:
if not self.discrete:
prof_role = "e2e"
prof_step = profile_step
Copy link
Contributor

Choose a reason for hiding this comment

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

prof_step and profile_step are confusing. And new variables are unnecessary, the original role&profile_step can still meet the requirements.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The corresponding variable(s) have been deprecated in the new solution.

@mengchengTang mengchengTang force-pushed the profiler_support_agent_loop branch 10 times, most recently from 8486b44 to b76689b Compare December 4, 2025 09:43
@mengchengTang mengchengTang marked this pull request as ready for review December 4, 2025 11:20
@mengchengTang mengchengTang force-pushed the profiler_support_agent_loop branch from b76689b to 17d67e9 Compare December 4, 2025 11:27
@mengchengTang mengchengTang changed the title profiler bug fix for agent loop [perf] fix: profiler bug fix for agent loop Dec 4, 2025
@tardis-key
Copy link
Contributor

@FightingZhen @wuxibin89 ready for review. This pr is bugfix for legacy_workers.

@mengchengTang mengchengTang force-pushed the profiler_support_agent_loop branch 2 times, most recently from bd1e8e3 to 882201c Compare December 4, 2025 12:16
@mengchengTang mengchengTang force-pushed the profiler_support_agent_loop branch from 882201c to c49435b Compare December 8, 2025 03:38

async def start_profile(self, **kwargs):
"""Start profiling on all workers."""
await asyncio.gather(*[worker.start_capture_profile.remote(**kwargs) for worker in self.workers])
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is only suitable for vllm with vLLMAsyncRollout(ModelRunner) colocated with trainer in same process, while sglang have separate processes. We're working on separating vllm process as well #4280.

For rollout performance profile, we should reuse vllm/sglang server metrics

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understood. I completely agree that using native server metrics is the right direction.
And this pr is necessary as a bugfix for the currently supported architecture (colocated vLLM) to ensure profiling data is captured correctly right now. We treat this as an interim solution and will align with the native metrics approach after the process separation (#4280) lands.

@mengchengTang mengchengTang force-pushed the profiler_support_agent_loop branch from c49435b to af06917 Compare December 8, 2025 09:01
@mengchengTang mengchengTang force-pushed the profiler_support_agent_loop branch from af06917 to 9204dd5 Compare December 16, 2025 07:29
@mengchengTang mengchengTang force-pushed the profiler_support_agent_loop branch 4 times, most recently from 0229ef0 to 4d19488 Compare December 16, 2025 09:22
@mengchengTang mengchengTang force-pushed the profiler_support_agent_loop branch from 4d19488 to e033c06 Compare December 16, 2025 14:10
@tardis-key
Copy link
Contributor

Is there any way to unify start_e2e_profiler and start_capture_profiler?

if self.device_mesh["infer_tp"].get_local_rank() == 0:
await self._engine.flush_cache()

async def start_async_rollout_profile(self, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

what about moving start_async_rollout_profile to DistProfilerExtension?

"""Start an async rollout profiling segment."""
await self.rollout.start_async_rollout_profile(**kwargs)

@register(dispatch_mode=Dispatch.DIRECT_ROLLOUT_METHOD)
Copy link
Contributor

Choose a reason for hiding this comment

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

Try to encapsulate the profiler method of rollout, and support custom use of either the engine's built-in profiler capability or the VeriL profiler capability.

Copy link
Contributor

@tardis-key tardis-key left a comment

Choose a reason for hiding this comment

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

  1. Do not rename start/stop. The implementation of the second pair of functions depends on the patch implementation.
  2. Patch the start_profiler capability of vLLM. Do not unravel vLLM's complex scheduling mechanism, so as to keep the external scheduling logic of VeRL cleaner.
  3. Retain distinct serer profiling capabilities for SGLang and vLLM, and consider implementing rolloutExtension or slangExtension/vllmExtension.

@mengchengTang mengchengTang force-pushed the profiler_support_agent_loop branch from e033c06 to 54f19ce Compare December 30, 2025 06:01
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.

5 participants