Skip to content

Apply-MegatronAdaptor-NPU-migration-to-clean-branch - #385

Open
momo609 wants to merge 4 commits into
vllm-project:ascendfrom
momo609:ascendupdate2
Open

Apply-MegatronAdaptor-NPU-migration-to-clean-branch#385
momo609 wants to merge 4 commits into
vllm-project:ascendfrom
momo609:ascendupdate2

Conversation

@momo609

@momo609 momo609 commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Remove MindSpeed-specific dependencies and imports.
  • Switch NPU backend integration to MegatronAdaptor and TransformerEngineNPU.
  • Align Megatron-related patches with the mainline implementation.
  • Remove obsolete MindSpeed and Megatron communication patches.
  • Update Megatron, vLLM, and bridge patch application order.
  • Fix MegatronAdaptor initialization and feature re-patching in the actor.
  • Update NPU attention patch and weight-transfer compatibility logic.
  • Fix nested NPU memory-pool allocation during training offload.
  • Update the related unit test and deployment scripts.

Files Changed

  • vime/backends/megatron_utils/
  • vime/utils/
  • docker/
  • scripts/
  • examples/
  • tests/
  • train.py
  • train_async.py

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request transitions the NPU training stack from MindSpeed to MegatronAdaptor and TransformerEngineNPU, updates the Megatron-LM commit, and applies several patches for optimizer steps, memory pool regions, and vLLM speculative draft updates. The reviewer's feedback is highly actionable and should be addressed: the new megatron_bridge.patch is orphaned in the Dockerfile and lacks path resolution in the environment update script; cloning dependencies from main without pinning commits makes the Docker build fragile; and the run-qwen3-4B-npu.sh script contains several hardcoded absolute paths and NPU device IDs that break portability.

Comment thread docker/Dockerfile.npu Outdated
Comment thread .buildkite/scripts/update-npu-environment.sh Outdated
Comment thread docker/Dockerfile.npu Outdated
Comment on lines +78 to +79
RUN git clone https://gitcode.com/Ascend/MegatronAdaptor.git /root/MegatronAdaptor && \
git clone https://gitcode.com/Ascend/TransformerEngineNPU.git /root/TransformerEngineNPU

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Cloning MegatronAdaptor and TransformerEngineNPU from the main branch without pinning a specific commit or tag makes the Docker build non-reproducible and fragile. Any breaking change in their upstream repositories will break the build. Please define build arguments for their commits (e.g., MEGATRON_ADAPTOR_COMMIT and TRANSFORMER_ENGINE_NPU_COMMIT) and check them out, similar to Megatron-LM.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Agree

Comment thread scripts/run-qwen3-4B-npu.sh Outdated
Comment thread scripts/run-qwen3-4B-npu.sh Outdated
Comment thread scripts/run-qwen3-4B-npu.sh Outdated
Comment thread scripts/run-qwen3-4B-npu.sh Outdated
Comment thread docker/Dockerfile.npu Outdated
done && \
git -C /root/Megatron-LM apply --whitespace=nowarn \
/tmp/npu_patch/megatron_comm.patch && \
/tmp/npu_patch/megatron_mainline.patch && \

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could we simplify the Megatron patch layering here? The two patches modify several of the same core files, making future mainline updates prone to apply conflicts or duplicated behavior; please consider a single composite patch or a minimal non-overlapping NPU overlay.

Comment thread docker/patch/latest/vllm.patch Outdated

+ self._select_weight_update_target(is_draft)
self.weight_transfer_engine.start_weight_update()
self._weight_update_active = True

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could you clarify why thist file are being synchronized here?It seems not used by Dockerfile.npu,so it may be better to remove these unrelated changes or update these in a separate PR.

+ return True
+
+
+_register_auto_classes()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ditto


git -C "${WORKSPACE}/MindSpeed" apply --whitespace=nowarn "${PATCH_DIR}/mindspeed.patch"
pip install --no-deps --no-build-isolation -e ${WORKSPACE}/MegatronAdaptor
pip install --no-deps --no-build-isolation -e ${WORKSPACE}/TransformerEngineNPU

@floatlibai floatlibai Aug 20, 2026

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.

Do we need to clone these two repos or not? I think this step could use more detail.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

need install

# MegatronAdaptor must run before Megatron imports so its dummy NPU modules
# are bound in Megatron tensor-parallel modules.
import megatron_adaptor # noqa: F401
from . import npu_attention_patch # noqa: F401

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.

Why is this line needed here? Isn't the import in actor.py already sufficient?

Comment thread docker/Dockerfile.npu
ARG MEGATRON_COMMIT=1dcf0dafa884ad52ffb243625717a3471643e087
ARG MEGATRON_BRIDGE_COMMIT=3fd3768045422d0aa5c97e90a4e6c659aea9acb9
ARG MINDSPEED_COMMIT=fc63de5c48426dd019c3b3f39e65f5bdf56e4086
ARG MBRIDGE_COMMIT=89eb10887887bc74853f89a4de258c0702932a1c

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could you please remove the megatron_comm.patch and mindspeed.patch entries from docker/npu_patch/series.conf? This keeps the declared patch stack consistent with the Dockerfile and available patch files.

@momo609
momo609 force-pushed the ascendupdate2 branch 2 times, most recently from a283316 to e91f80c Compare August 26, 2026 08:48
Signed-off-by: wangxiaoxin-sherie <wangxiaoxin7@huawei.com>
wangxiaoxin-sherie added 2 commits August 27, 2026 17:30
Signed-off-by: wangxiaoxin-sherie <wangxiaoxin7@huawei.com>
Signed-off-by: wangxiaoxin-sherie <wangxiaoxin7@huawei.com>
@momo609
momo609 force-pushed the ascendupdate2 branch 3 times, most recently from 6c86097 to 0b8002e Compare August 27, 2026 12:27
Comment thread docker/Dockerfile.npu
pip install --no-deps --no-build-isolation -e /root/Megatron-LM && \
pip install --no-deps --no-build-isolation -e /root/TransformerEngineNPU && \
pip install --no-deps --no-build-isolation -e /root/MegatronAdaptor && \
pip install --no-deps --no-build-isolation -e /root/MindSpeed

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

NPU CI (#193) likely fails during image build: Dockerfile.npu removes the MindSpeed clone but still runs pip install -e /root/MindSpeed.
Drop that line? This migration also requires image-build (not smk-only on the legacy MindSpeed image), and the common docker/patch/latest/megatron.patch is Dockerfile-only and not in series.conf.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Offline weight updates depend on MindSpeed, so the MindSpeed code has been re-added.

@momo609
momo609 force-pushed the ascendupdate2 branch 4 times, most recently from 7db37fb to 971e1af Compare August 28, 2026 02:16
Signed-off-by: wangxiaoxin-sherie <wangxiaoxin7@huawei.com>
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.

4 participants