Skip to content

[NPU] Fix load torch_dist weight error - #396

Open
floatlibai wants to merge 2 commits into
vllm-project:ascendfrom
floatlibai:fix/ref-load
Open

[NPU] Fix load torch_dist weight error#396
floatlibai wants to merge 2 commits into
vllm-project:ascendfrom
floatlibai:fix/ref-load

Conversation

@floatlibai

Copy link
Copy Markdown
Contributor

This PR resolves #380 by implementing the following changes:

  • Fixes the tools/convert_hf_to_torch_dist.py script.
  • Reverts default_megatron_to_hf_mode back to raw.

@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 refactors NPU-specific logic. In tools/convert_hf_to_torch_dist.py, it conditionally imports mindspeed.megatron_adaptor and updates the distributed process group initialization depending on whether an NPU is detected. In vime/utils/arguments.py, the default value for --megatron-to-hf-mode is simplified to always default to "raw". Feedback on these changes highlights that calling is_npu() at the module level in tools/convert_hf_to_torch_dist.py can raise a RuntimeError if no NPU device is available, and suggests wrapping the call in a try-except block to prevent import-time crashes.

Comment thread tools/convert_hf_to_torch_dist.py Outdated
Comment on lines +7 to +9
from vime.utils.common import is_npu
if is_npu():
import mindspeed.megatron_adaptor

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

Calling is_npu() at the module level can raise a RuntimeError if torch_npu is installed but no NPU device is visible or available (for example, on a CPU-only login/compile node or during testing/building). This will cause the script to crash immediately upon import or when running basic commands like --help.

To prevent this, wrap the module-level is_npu() call in a try-except block to handle the RuntimeError gracefully.

Suggested change
from vime.utils.common import is_npu
if is_npu():
import mindspeed.megatron_adaptor
from vime.utils.common import is_npu
_is_npu = False
try:
_is_npu = is_npu()
except RuntimeError:
pass
if _is_npu:
import mindspeed.megatron_adaptor

Signed-off-by: flb_ <floatlibai@gmail.com>
Signed-off-by: flb_ <floatlibai@gmail.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.

1 participant