code-migration

Migrate CUDA-based PyTorch code to Ascend NPU with API mappings.

7|Updated Jan 29, 2026
One-click install
npx skills add https://github.com/FeRhodium/ascend-migration --skill code-migration-ferhodium
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: code-migration
Source: https://github.com/FeRhodium/ascend-migration/tree/main/skills/code-migration
Command: npx skills add https://github.com/FeRhodium/ascend-migration --skill code-migration-ferhodium

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides a structured guide to migrate CUDA-based PyTorch code to Ascend NPU, detailing API replacements, migration patterns, and best practices to minimize manual effort and errors.

Core Features & Use Cases

  • API Replacements: Map CUDA APIs to torch_npu equivalents to ensure correct device placement and execution.
  • Migration Patterns: Common code patterns for initializing models, moving tensors, and training loops.
  • Best Practices & Validation: Guidance on testing correctness and performance after migration across typical PyTorch workloads.

Quick Start

Start by identifying CUDA code sections, apply the CUDA-to-NPU mapping guide, and validate results on Ascend NPU using torch_npu, iterating until parity is achieved.

Frequently Asked Questions about code-migration

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I migrate PyTorch code from CUDA to Ascend NPU?

To migrate PyTorch code from CUDA to Ascend NPU, you map CUDA APIs to torch_npu equivalents for model initialization, data movement, and training loops. This process requires replacing specific device calls and applying structured migration patterns.

What are the API mappings for replacing CUDA functions with torch_npu?

API mappings for replacing CUDA functions with torch_npu provide direct equivalents for device placement and execution. These mappings cover essential PyTorch operations, ensuring correct tensor movement and model initialization on Ascend NPU hardware.

Does PyTorch Automatic Mixed Precision (AMP) work with Ascend NPU?

PyTorch AMP usage is supported during Ascend NPU migration. The process provides specific migration patterns for training loops and AMP usage, allowing you to maintain mixed precision training workflows when transitioning from CUDA.

What is the best way to validate PyTorch model correctness after migrating to Ascend NPU?

The best way to validate PyTorch model correctness after migrating to Ascend NPU is by testing typical workloads and iterating until parity is achieved. This involves applying best practices to verify performance and correctness on the new device.

Can I use standard PyTorch training loops when migrating code to Ascend NPU?

You can use standard PyTorch training loops when migrating to Ascend NPU by applying specific migration patterns. These patterns guide necessary adjustments for data movement and AMP usage to ensure correct execution on the target hardware.