Skip to content

Conversation

@tongtong0613
Copy link
Collaborator

@tongtong0613 tongtong0613 commented Jul 25, 2025

What does this PR do?

Currently, whether in end-to-end mode or discrete mode, all roles are fully collected. As the sequence length continues to increase, the volume of collected data becomes large, leading to slow parsing. Therefore, we introduce a new feature in the NPU Profiler that allows optional role selection in discrete mode, enabling quick collection of specific roles.

We have added a new roles parameter in npu_profile.yaml to specify the roles to be collected. The currently supported options are: all, rollout_generate, actor_compute_log_prob, actor_update and ref_compute_log_prob. Setting roles to ["all"] means all roles will be collected. Other options can be freely combined, for example: ["actor_update", "ref_compute_log_prob"]

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.

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 a feature for the NPU profiler, allowing selective profiling of roles in discrete mode. A critical issue exists in verl/utils/profiler/mstx_profile.py related to exception handling, where the profiler cleanup code is skipped if the decorated function throws an exception. A refactoring using a try...finally block is suggested to address this.

Comment on lines +205 to 235
profile_this_role = True
discrete_mode = self.profiler.discrete
profile_enable = self.profiler.this_step and self.profile_option is not None

if not profile_enable:
return func(self, *args, **kwargs)

if profile_enable and role is not None:
target_roles = self.profile_option.get("roles", [])
profile_this_role = "all" in target_roles or role in target_roles

if profile_enable:
if not discrete_mode:
mark_range = mark_start_range(message=profile_name)
else:
if profile_this_role:
profile_npu = get_npu_profiler(option=self.profile_option, role=role)
profile_npu.start()
mark_range = mark_start_range(message=profile_name)

result = func(self, *args, **kwargs)

if self.profiler.this_step and self.profile_option is not None:
mark_end_range(mark_range)
if self.profiler.discrete:
profile_npu.step()
profile_npu.stop()
if profile_enable:
if not discrete_mode:
mark_end_range(mark_range)
else:
if profile_this_role:
mark_end_range(mark_range)
profile_npu.step()
profile_npu.stop()

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 current implementation doesn't handle exceptions raised by the decorated function func. If func(*args, **kwargs) raises an exception, the cleanup code (mark_end_range, profile_npu.stop()) won't be executed, potentially leading to corrupted profiling data or resource leaks. Refactor the wrapper function to use a try...finally block to guarantee resource cleanup and simplify the control flow.

                profile_name = message or func.__name__
                profile_enable = self.profiler.this_step and self.profile_option is not None

                if not profile_enable:
                    return func(self, *args, **kwargs)

                discrete_mode = self.profiler.discrete
                profile_this_role = True
                # In discrete mode, check if the current role is selected for profiling.
                if discrete_mode and role is not None:
                    target_roles = self.profile_option.get("roles", [])
                    profile_this_role = "all" in target_roles or role in target_roles
                    

                # Setup profiler
                profile_npu = None
                mark_range = None
                if discrete_mode and profile_this_role:
                    profile_npu = get_npu_profiler(option=self.profile_option, role=role)
                    profile_npu.start()
                
                if profile_enable:
                    mark_range = mark_start_range(message=profile_name)

                try:
                    result = func(self, *args, **kwargs)
                finally:
                    # Teardown profiler
                    if profile_enable:
                        mark_end_range(mark_range)
                    if profile_npu:
                        profile_npu.step()
                        profile_npu.stop()
                
                return result

@vermouth1992 vermouth1992 merged commit 92e81cf into volcengine:main Jul 25, 2025
51 of 53 checks passed
oseyosey pushed a commit to oseyosey/verl that referenced this pull request Jul 28, 2025
…filer (volcengine#2750)

### What does this PR do?

Currently, whether in `end-to-end` mode or `discrete` mode, all roles
are fully collected. As the sequence length continues to increase, the
volume of collected data becomes large, leading to slow parsing.
Therefore, we introduce a new feature in the NPU Profiler that allows
optional role selection in `discrete` mode, enabling quick collection of
specific roles.

We have added a new roles parameter in `npu_profile.yaml` to specify the
roles to be collected. The currently supported options are: `all`,
`rollout_generate`, `actor_compute_log_prob`, `actor_update` and
`ref_compute_log_prob`. Setting roles to `["all"]` means all roles will
be collected. Other options can be freely combined, for example:
`["actor_update", "ref_compute_log_prob"]`

### 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`, `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.

```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/volcengine/verl/blob/main/CONTRIBUTING.md).
- [x] Apply [pre-commit
checks](https://github.com/volcengine/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/volcengine/verl/tree/main/docs).
- [x] Add unit or end-to-end test(s) to [the CI
workflow](https://github.com/volcengine/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).)
CurryRice233 added a commit to CurryRice233/verl that referenced this pull request Jul 28, 2025
* origin/mindspeed: (39 commits)
  [perf] feat: add optional role selection in discrete mode for NPU Profiler (volcengine#2750)
  [rollout] feat: remove chat scheduler (volcengine#2725)
  [trainer] refactor: Make sure to keep the type checking (volcengine#2634)
  [doc] style: change resize handle from gradient to plain color (volcengine#2746)
  [CI] feat: add `mypy` to pre-commit (volcengine#2614)
  [megatron] feat: a bunch of optimzation on vram, sequence packing (volcengine#2678)
  [docker] feat: upgrade to torch 2.7, sglang 0.4.8 (volcengine#2617)
  [doc] feat: add resizable sidebar and improve layout (volcengine#2577)
  [ci] fix: release ascend test time, fix one step off-policy CI (volcengine#2731)
  [recipe] chore: add retool training script (volcengine#2732)
  [ci] fix: checkpoint_convertor ci miss a hf model download (volcengine#2730)
  [doc] feat: Add agent-lightning in the list of "awesome works using verl (volcengine#2726)
  [tool] fix: geo3k create return str instead of tuple (volcengine#2714)
  [megatron] fix: resolve backward propagation error in megatron_actor due to shared logits tensor in-place modification (volcengine#2484)
  [misc] chore: bump main branch version to v0.5.0.dev (volcengine#2718)
  [sglang] fix: Adding strict naming sanity for sglang (volcengine#2719)
  [ray] feat: RayWorkerGroup support set worker env (volcengine#2685)
  [ci] test: add CriticWorker unit test, make some util CPU friendly (volcengine#2717)
  [cfg] refactor: add ActorConfig, EngineConfig, and ActorWorker unit test, refactor validation code (volcengine#2621)
  [misc] chore: bump version to v0.5.0 (volcengine#2716)
  ...
SumanthRH pushed a commit to SumanthRH/verl that referenced this pull request Jul 29, 2025
…filer (volcengine#2750)

### What does this PR do?

Currently, whether in `end-to-end` mode or `discrete` mode, all roles
are fully collected. As the sequence length continues to increase, the
volume of collected data becomes large, leading to slow parsing.
Therefore, we introduce a new feature in the NPU Profiler that allows
optional role selection in `discrete` mode, enabling quick collection of
specific roles.

We have added a new roles parameter in `npu_profile.yaml` to specify the
roles to be collected. The currently supported options are: `all`,
`rollout_generate`, `actor_compute_log_prob`, `actor_update` and
`ref_compute_log_prob`. Setting roles to `["all"]` means all roles will
be collected. Other options can be freely combined, for example:
`["actor_update", "ref_compute_log_prob"]`

### 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`, `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.

```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/volcengine/verl/blob/main/CONTRIBUTING.md).
- [x] Apply [pre-commit
checks](https://github.com/volcengine/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/volcengine/verl/tree/main/docs).
- [x] Add unit or end-to-end test(s) to [the CI
workflow](https://github.com/volcengine/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).)
yellowbee686 pushed a commit to yellowbee686/verl that referenced this pull request Jul 31, 2025
…filer (volcengine#2750)

### What does this PR do?

Currently, whether in `end-to-end` mode or `discrete` mode, all roles
are fully collected. As the sequence length continues to increase, the
volume of collected data becomes large, leading to slow parsing.
Therefore, we introduce a new feature in the NPU Profiler that allows
optional role selection in `discrete` mode, enabling quick collection of
specific roles.

We have added a new roles parameter in `npu_profile.yaml` to specify the
roles to be collected. The currently supported options are: `all`,
`rollout_generate`, `actor_compute_log_prob`, `actor_update` and
`ref_compute_log_prob`. Setting roles to `["all"]` means all roles will
be collected. Other options can be freely combined, for example:
`["actor_update", "ref_compute_log_prob"]`

### 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`, `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.

```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/volcengine/verl/blob/main/CONTRIBUTING.md).
- [x] Apply [pre-commit
checks](https://github.com/volcengine/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/volcengine/verl/tree/main/docs).
- [x] Add unit or end-to-end test(s) to [the CI
workflow](https://github.com/volcengine/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).)
Juniper1021 pushed a commit to Juniper1021/verl that referenced this pull request Aug 7, 2025
…filer (volcengine#2750)

### What does this PR do?

Currently, whether in `end-to-end` mode or `discrete` mode, all roles
are fully collected. As the sequence length continues to increase, the
volume of collected data becomes large, leading to slow parsing.
Therefore, we introduce a new feature in the NPU Profiler that allows
optional role selection in `discrete` mode, enabling quick collection of
specific roles.

We have added a new roles parameter in `npu_profile.yaml` to specify the
roles to be collected. The currently supported options are: `all`,
`rollout_generate`, `actor_compute_log_prob`, `actor_update` and
`ref_compute_log_prob`. Setting roles to `["all"]` means all roles will
be collected. Other options can be freely combined, for example:
`["actor_update", "ref_compute_log_prob"]`

### 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`, `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.

```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/volcengine/verl/blob/main/CONTRIBUTING.md).
- [x] Apply [pre-commit
checks](https://github.com/volcengine/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/volcengine/verl/tree/main/docs).
- [x] Add unit or end-to-end test(s) to [the CI
workflow](https://github.com/volcengine/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).)
whatadayG pushed a commit to whatadayG/verl that referenced this pull request Sep 5, 2025
…filer (volcengine#2750)

### What does this PR do?

Currently, whether in `end-to-end` mode or `discrete` mode, all roles
are fully collected. As the sequence length continues to increase, the
volume of collected data becomes large, leading to slow parsing.
Therefore, we introduce a new feature in the NPU Profiler that allows
optional role selection in `discrete` mode, enabling quick collection of
specific roles.

We have added a new roles parameter in `npu_profile.yaml` to specify the
roles to be collected. The currently supported options are: `all`,
`rollout_generate`, `actor_compute_log_prob`, `actor_update` and
`ref_compute_log_prob`. Setting roles to `["all"]` means all roles will
be collected. Other options can be freely combined, for example:
`["actor_update", "ref_compute_log_prob"]`

### 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`, `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.

```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/volcengine/verl/blob/main/CONTRIBUTING.md).
- [x] Apply [pre-commit
checks](https://github.com/volcengine/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/volcengine/verl/tree/main/docs).
- [x] Add unit or end-to-end test(s) to [the CI
workflow](https://github.com/volcengine/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).)
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.

2 participants