Skip to content

[megatron] fix: the NPU error that occurs after migrating from megatron worker to engine worker.#6135

Merged
wuxibin89 merged 5 commits into
verl-project:mainfrom
xiazhahe:verl_mindspeed
May 11, 2026
Merged

[megatron] fix: the NPU error that occurs after migrating from megatron worker to engine worker.#6135
wuxibin89 merged 5 commits into
verl-project:mainfrom
xiazhahe:verl_mindspeed

Conversation

@xiazhahe
Copy link
Copy Markdown
Contributor

@xiazhahe xiazhahe commented Apr 25, 2026

What does this PR do?

Add concise overview of what this PR aims to achieve or accomplish. Reference related GitHub issues and PRs that help with the review.

After migrating from megatron worker to engine worker, there is no longer Critic worker to use.
Fix the error occurs on NPU: AssertionError: Unknown device: npu for model_type: value_model and backend: megatron.

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, veomni, sglang, vllm, vllm_omni, rollout, trainer, ci, training_utils, recipe, hardware, deployment, ray, worker, single_controller, misc, perf, model, algo, env, tool, ckpt, doc, data, cfg, reward, fully_async, one_step_off
    • 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
Copy Markdown
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 MindspeedEngineWithValueHead and MegatronEngineWithValueHead across the engine worker modules to support value models. The review feedback identifies several improvement opportunities: an unused import of repatch in engine_workers.py should be removed, a redundant init method in MindspeedEngineWithValueHead can be deleted, and the duplicated patching logic in _init_device_mesh should be refactored into a shared helper function to improve maintainability.

Comment thread verl/workers/engine_workers.py Outdated
Comment on lines +23 to +27
try:
from verl.workers.engine.mindspeed.transformer_impl import repatch
except ImportError:
repatch = None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The import of repatch in verl/workers/engine_workers.py is unused and redundant. The repatch function is already imported and called within the specific engine implementations (e.g., in verl/workers/engine/mindspeed/transformer_impl.py) during their initialization. Adding it here at the top level of the worker file introduces unnecessary module loading and dead code.

Comment on lines +71 to +78
def __init__(
self,
model_config: HFModelConfig,
engine_config: McoreEngineConfig,
optimizer_config: McoreOptimizerConfig,
checkpoint_config: CheckpointConfig,
):
super().__init__(model_config, engine_config, optimizer_config, checkpoint_config)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The __init__ method in MindspeedEngineWithValueHead is redundant as it only calls super().__init__ with the exact same arguments as the base class MegatronEngineWithValueHead (and its ancestor MegatronEngine). In Python, this can be omitted to improve code clarity and maintainability.

Comment thread verl/workers/engine/mindspeed/transformer_impl.py
@xiazhahe xiazhahe changed the title [fix]: Fix the NPU error that occurs after migrating from megatron worker to engine worker. [megatron]: fix the NPU error that occurs after migrating from megatron worker to engine worker. Apr 25, 2026
Comment thread verl/workers/engine_workers.py Outdated
Comment thread verl/workers/engine_workers.py Outdated
Comment thread verl/workers/engine_workers.py Outdated
@wuxibin89 wuxibin89 changed the title [megatron]: fix the NPU error that occurs after migrating from megatron worker to engine worker. [megatron] fix: the NPU error that occurs after migrating from megatron worker to engine worker. Apr 28, 2026
@wuxibin89
Copy link
Copy Markdown
Collaborator

@xiazhahe xiazhahe requested a review from ArronHZG as a code owner May 11, 2026 03:15
@xiazhahe xiazhahe requested a review from wuxibin89 May 11, 2026 07:05
@wuxibin89 wuxibin89 merged commit b002a0c into verl-project:main May 11, 2026
92 of 99 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants