Torch npu pyyaml preinstall

From Fudan-SMI-lab/SEAM · View interactive version

Torch npu pyyaml preinstall is an AI agent skill from the GitHub repository Fudan-SMI-lab/SEAM. Pre-install PyYAML to prevent torch-npu transitive dependency failure

How to use this skill

Skill file

Pre-install PyYAML to prevent torch-npu transitive dependency failure

When to Use

Root Cause

torch-npu 2.5.1's memory visualization submodule (torch_npu/npu/_memory_viz.py) imports yaml unconditionally at module load time. However, PyYAML is not declared in torch-npu's pip metadata (requires field), so a fresh virtual environment with only torch-npu installed will lack it. The error is misleading because the traceback originates from import torch (not import torch_npu), making the actual missing dependency hard to diagnose.

How to Use

  1. 1. Before or alongside installing torch-npu, explicitly install PyYAML: pip install PyYAML (use domestic mirror if needed: pip install PyYAML -i https://mirrors.aliyun.com/pypi/simple/).
  2. 2. Alternatively, add PyYAML to the project's requirements.txt alongside torch, torch-npu, and torchvision.
  3. 3. After installing torch-npu, run a pre-flight validation: python -c 'import torch_npu; import torch_npu.npu' — if this exits cleanly without ModuleNotFoundError, the dependency is resolved.
  4. 4. If the error still occurs, verify the yaml module is accessible: python -c 'import yaml; print(yaml.__version__)'.

Code Examples

File: requirements.txt

Before

torch

torch-npu

torchvision

After

torch

torch-npu

torchvision

PyYAML

Do Not

References

Evidence

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.