huawei-cloud-ascend-small-model-migrate について
huawei-cloud-ascend-small-model-migrateは、対応するビジョンモデルをAscend NPUへ移行する手順を案内するスキルです。モデル分析、推論検証、プロファイリング、最適化提案に加え、リソース見積もりと性能ベースライン比較を行います。
主な機能
- 01モデル構造と移行経路の分析
- 02Ascend NPUでの推論検証
- 03オペレータープロファイルの収集と分析
- 04性能最適化の提案
- 05リソース見積もりとベースライン比較
活用シーン
- 01YOLOやResNetをGPUからAscendへ移行
- 02移行後のモデル精度を確認
- 03ビジョン処理のオペレーターのボトルネックを特定
- 04NPUメモリと推論性能を見積もり
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ huaweicloud/ huaweicloud-skills --skill huawei-cloud-ascend-small-model-migrateインストール後、Claude Code で/huawei-cloud-ascend-small-model-migrateを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
references/acceptance-criteria.mdmigration-scripts.mdprofiler-sql.mdreport-template.mdtroubleshooting.mdverification-method.mdscripts/analyze_model.py詳細
Huawei Cloud Ascend 小規模モデルの移行
概要
このスキルでは、小規模なビジョンモデルを Ascend NPU に移行するためのワークフローを案内します。構成分析 → 移行検証 → パフォーマンス最適化を扱います。
アーキテクチャ:モデル分析 → 環境構築 → NPU 推論 → パフォーマンスプロファイリング → ボトルネック分析 → 最適化の提案
関連スキル:
huawei-cloud-msmodelslim-model-analysis- 移行パスを決定するためのモデル構成分析huawei-cloud-msot-msopprof-operator-profiler- オペレーターのパフォーマンスデータ収集huawei-cloud-ascend-profiler-db-explorer- ボトルネック特定のためのプロファイリングデータベース分析huawei-cloud-ascendc-operator-performance-optim- 任意:ボトルネックとなるオペレーターの AscendC 最適化
アーキテクチャの構成要素
このスキルでは、以下のクラウドサービスとコンポーネントを使用します。
- Ascend NPU:モデルのデプロイ先となるハードウェア(Ascend 910B シリーズ)
- torch_npu:Ascend NPU 用 PyTorch アダプター
- MSProf:パフォーマンス分析用の Ascend プロファイリングツール
- Ultralytics:YOLO モデルフレームワークのサポート
- Docker:一貫性のあるデプロイを実現するコンテナ環境
ユースケース
よくある問題のシナリオ:
- ビジョンモデルを GPU から Ascend NPU に移行する
- YOLO/ResNet/UNet モデルを Ascend ハードウェアにデプロイする
- NPU 上の小規模モデルのパフォーマンスを最適化する
- 移行後のモデル精度を検証する
- コンピュータービジョンモデルのパフォーマンスボトルネックを特定する
よくあるユーザーの質問:
- 「YOLOv8 を Ascend NPU に移行する
- 「Ascend で ResNet を実行する方法は?
- 「NPU 上の UNet 推論を最適化する
- 「移行後のモデル精度を検証する
- 「ビジョンモデルのパフォーマンスボトルネックを分析する
- 「YOLOModelMigrationAscendNPU
- 「AscendModel?
- 「ModelMigrationNPU?
対象範囲
サポート対象:
- エンコーダーのみのアーキテクチャ(ResNet、VGG、EfficientNet)
- 検出モデル(YOLO、Faster-RCNN、SSD)
- セグメンテーションモデル(UNet、DeepLab)
- その他のデコーダーのみではない LLM モデル
サポート対象外:
- デコーダーのみの LLM(Qwen、LLaMA、DeepSeek) - アダプターベースの量子化アプローチが必要です
- VLM のテキストバックボーンの理解 - アダプターベースの量子化アプローチが必要です
ワークフロー
┌─────────────────────────────────────────────────────────────┐
│ Step 1: Model Structure Analysis │
│ → Determine msmodelslim compatibility │
│ → Output structure analysis + migration path suggestion │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ Step 2: Environment Preparation + Migration Verification │
│ → Configure torch_npu environment │
│ → Run inference test │
│ → Verify accuracy │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ Step 3: Performance Data Collection │
│ → Collect operator performance data │
│ → Output performance data location │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ Step 4: Performance Analysis │
│ → Analyze profiling data for bottlenecks │
│ → Output complete operator time distribution │
│ → Identify bottleneck and well-performing operators │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ Step 5: Optimization Suggestions │
│ → Provide optimization solutions for bottleneck operators │
│ → Optional operator optimization │
└─────────────────────────────────────────────────────────────┘
ステップ 1:モデル構成分析
1.1 分析プロセス
モデル構成を読み取り、以下を分析します。
- モデル実装のソース(transformers またはローカルディレクトリ)
- アーキテクチャの種類(デコーダーのみ/エンコーダーのみ/エンコーダー・デコーダー)
- レイヤーごとの読み込み要件
- MoE の重み融合に関するリスク
1.2 移行パスの決定
| アーキテクチャの種類 | 推奨パス |
|---|---|
| デコーダーのみの LLM | アダプターベースの量子化 |
| VLM のテキストバックボーンの理解 | アダプターベースの量子化 |
| エンコーダーのみ/検出/セグメンテーション | このスキルを続けて使用 |
| その他 | 手動での判断が必要 |
1.3 分析レポートの出力
## Model Structure Analysis Result
### Basic Information
- Model Name: xxx
- Architecture Type: Encoder-only / Decoder-only / Encoder-Decoder
- Parameter Count: xxx
- Source: transformers / local directory
### Support Status
- msmodelslim Support: Yes/No
- Recommended Migration Path: torch_npu direct migration / msmodelslim adaptation
### Migration Suggestions
[Specific recommendations]
ステップ 2:環境の準備と移行検証
2.1 デフォルトの検証環境
- サーバー:ascend-server-01
- コンテナ:skill-the
- イメージ:quay.io/ascend/vllm-ascend:v0.18.0
- NPU:8× Ascend 910B3
2.2 環境設定
# Enter container
docker exec -it skill-the bash
# Install dependencies
pip install torch_npu
pip install ultralytics # For YOLO series
# Or other model-specific libraries
# OpenCV dependencies (if needed)
apt install libgl1 libglib2.0-0
2.3 移行検証スクリプト
import torch
import torch_npu
# Check NPU availability
print(f"NPU available: {torch.npu.is_available()}")
print(f"NPU count: {torch.npu.device_count()}")
# Load model
model = ... # Model loading code
model = model.to('npu:0')
# Inference test
with torch.no_grad():
output = model(input_tensor)
print(f"Inference success: {output is not None}")
2.4 移行検証レポートの出力
## Migration Verification Result
### Environment Information
- Server: ascend-server-01
- Container: skill-the
- torch_npu Version: xxx
- NPU Status: Normal
### Inference Test
- Model Loading: Success/Failure
- NPU Inference: Success/Failure
- Accuracy Verification: Pass/Fail
### Performance Metrics
- Average Inference Time: xxx ms
- FPS: xxx
ステップ 3:パフォーマンスデータの収集
3.1 パフォーマンス収集プロセス
プロファイリングスキルを使用して、オペレーターのパフォーマンスデータを収集します。
- オンボード収集(デバイスモード)
- またはシミュレーション収集(シミュレーターモード)
3.2 パフォーマンスデータの出力先
## Performance Collection Result
### Data Location
- Server: ascend-server-01
- Path: /home/xxx/PROF_xxx/
- Database: msprof_xxx.db
- Collection Time: xxx
### Collection Configuration
- Mode: device / simulator
- NPU: npu:0
- Collection Duration: xxx s
ステップ 4:パフォーマンス分析
4.1 分析プロセス
以下をクエリして分析します。
- 処理時間が長い上位 N 個のオペレーター
- オペレーターの種類ごとのグループ統計
- AI_CPU/AI_CORE/AI_VECTOR_CORE の分布
4.2 SQL クエリの例
-- Top 20 operators by time
SELECT op_name, op_type, total_time, call_times
FROM op_summary
ORDER BY total_time DESC
LIMIT 20;
-- Group by type
SELECT op_type, SUM(total_time) as type_time, COUNT(*) as count
FROM op_summary
GROUP BY op_type
ORDER BY type_time DESC;
4.3 パフォーマンス分析レポートの出力
## Performance Analysis Result
### Operator Time Distribution (TOP 20)
| Rank | Operator Name | Type | Time(ms) | Percentage | Call Count |
|------|--------------|------|----------|------------|------------|
| 1 | xxx | AI_CPU | xxx | xx% | xxx |
| ... | ... | ... | ... | ... | ... |
### Statistics by Type
| Type | Total Time | Percentage | Operator Count |
|------|------------|------------|----------------|
| AI_CPU | xxx | xx% | xxx |
| AI_CORE | xxx | xx% | xxx |
| AI_VECTOR_CORE | xxx | xx% | xxx |
### Bottleneck Operators (>5% usage)
| Operator | Type | Percentage | Issue |
|----------|------|------------|-------|
| xxx | AI_CPU | xx% | [Specific issue] |
### Well-performing Operators
| Operator | Type | Description |
|----------|------|-------------|
| Conv2D | AI_CORE | High Cube utilization, normal |
ステップ 5:最適化の提案
5.1 よくあるボトルネックと解決策
| ボトルネックの種類 | 原因 | 最適化ソリューション |
|---|---|---|
| Index operator の処理時間が長い | AI_CPU 実装 | AscendC で最適化バージョンを開発する |
| TransData の処理時間が長い | フォーマット変換のオーバーヘッド | CPU-NPU 間のデータ転送を減らす |
| NMS が CPU にフォールバックする | オペレーターが NPU に対応していない | AscendC で NPU 版の NMS を開発する |
| Upsample が遅い | Vector core の効率 | Upsample オペレーターを最適化する |
5.2 出力最適化提案レポート
## Optimization Suggestions
### Priority Ranking
| Priority | Operator | Issue | Solution | Expected Gain |
|----------|----------|-------|----------|---------------|
| P0 | xxx | xxx | xxx | xx% |
| P1 | xxx | xxx | xxx | xx% |
### Next Steps
1. [Specific optimization steps]
2. Operator optimization may be performed for bottleneck operators
完全版レポートテンプレート
各移行タスクの完了後、完全版レポートを出力します。
# [Model Name] Ascend Migration Report
## 1. Model Structure Analysis
[Step 1 output]
## 2. Migration Verification
[Step 2 output]
## 3. Performance Collection
[Step 3 output]
## 4. Performance Analysis
[Step 4 output]
## 5. Optimization Suggestions
[Step 5 output]
## Summary
- Migration Status: Success/Failure
- Inference Performance: xxx ms / xxx FPS
- Main Bottlenecks: xxx
- Optimization Direction: xxx
デフォルト環境
- サーバー:ascend-server-01:22 (root/Hhuawei@smb)
- コンテナー:skill-the
- NPU:8× Ascend 910B3(各 64G HBM)
- CANN:cann-version-placeholder.220
前提条件
システム要件
- Python 3.8+
- torch_npu >= 2.0.0
- msprof >= 7.0.0
- ultralytics >= 8.0.0(YOLO モデル用)
環境チェック
前提条件の確認:Python3、torch_npu、msprof が必要です
python3 --version # Python3 >= 3.8 python3 -c "import torch_npu; print('OK')" # NPU PyTorch サポート python3 -c "import msprof; print('OK')" # プロファイリングライブラリインストールされていない場合:
pip3 install --user torch_npu msprof ultralytics
その他のシステム依存関係
コンピュータービジョンモデルの場合:
apt install libgl1 libglib2.0-0 # OpenCV dependencies
強化機能
パフォーマンスベースライン比較モジュール
このスキルには、現在のモデルのパフォーマンスを業界標準のベースラインと比較する、パフォーマンスベースライン比較メカニズムが含まれています。
機能:
- 事前定義済みベースライン:Ascend NPU 上の一般的なモデル(YOLOv8、ResNet50、UNet、EfficientNet)のベースラインデータ
- 差分分析:パフォーマンスギャップ分析と最適化の可能性評価を生成します
- パフォーマンスランキング:ベンチマークデータベース内の類似モデルと比較します
- 傾向分析:移行の反復ごとのパフォーマンス改善を追跡します
ベースラインデータベース:
| モデル | バッチサイズ | レイテンシ(ms) | スループット(FPS) | 精度 |
|---|---|---|---|---|
| YOLOv8n | 32 | 2.3 | 434 | 53.1% mAP |
| YOLOv8s | 16 | 4.8 | 208 | 60.6% mAP |
| ResNet50 | 64 | 1.2 | 533 | 76.1% top-1 |
| UNet | 8 | 8.5 | 94 | - |
差分分析の出力:
## Performance Baseline Comparison
- Target Model: YOLOv8s
- Baseline Reference: YOLOv8s @ Ascend 910B
### Performance Gap
| Metric | Current | Baseline | Gap |
|--------|---------|----------|-----|
| Latency | 5.2 ms | 4.8 ms | +8.3% |
| Throughput | 192 FPS | 208 FPS | -7.7% |
| Accuracy | 60.2% | 60.6% | -0.4% |
### Optimization Potential
- Priority P0: Reduce latency by optimizing Conv operators
- Priority P1: Improve memory access pattern
- Expected Gain: ~10-15% performance improvement
リソース推定・計画ツール
このスキルでは、移行前のリソース推定機能を利用できます。
機能:
- メモリ要件の予測:モデルサイズとバッチ設定に基づいて、NPU メモリ使用量を推定します
- 推論時間の推定:デプロイ前にレイテンシとスループットを予測します
- バッチサイズの推奨:目標レイテンシの制約に基づいて、最適なバッチサイズを提案します
- マルチカードスケーリングのガイダンス:マルチデバイスデプロイ向けのスケーリング推奨事項を提供します
- 費用対効果分析:最適化への投資と予想されるパフォーマンス向上を評価します
リソース推定の出力:
## Resource Estimation Report
- Model: YOLOv8s
- Input Resolution: 640x640
### Memory Requirements
| Component | Size |
|-----------|------|
| Model Weights | 21 MB |
| Activation (BS=16) | 480 MB |
| Total Estimated | 501 MB |
### Performance Prediction
| Batch Size | Estimated Latency | Estimated Throughput |
|------------|-------------------|---------------------|
| 8 | 3.2 ms | 250 FPS |
| 16 | 4.8 ms | 208 FPS |
| 32 | 8.5 ms | 188 FPS |
### Recommended Configuration
- Optimal Batch Size: 16
- Target Latency: 4.8 ms
- Expected Throughput: 208 FPS
- Memory Utilization: ~78% of 64GB HBM
参考ドキュメント
| ドキュメント | 説明 |
|---|---|
| 受け入れ基準 | 機能面および非機能面の受け入れ基準 |
| 検証方法 | 段階的な検証ガイド |
| トラブルシューティング | よくある問題と解決策 |
| レポートテンプレート | レポート生成テンプレート |
| Profiler SQL | SQL クエリのリファレンス |
| 移行スクリプト | 移行支援スクリプト |
前提条件(重複 - 上記を参照)
- torch_npu >= 2.0.0 がインストールされていること
- msprof >= 7.0.0 がインストールされていること
- Ascend NPU 環境が構成されていること
- 移行対象のモデルコードがあること
コアコマンド
# Analyze model migration feasibility
python3 scripts/analyze_model.py --model /path/to/model
# Verify NPU inference
python3 scripts/verify_npu.py --model /path/to/model --input test.jpg
パラメーターの確認
| パラメーター | 説明 | 必須 |
|---|---|---|
| model | モデルコードのパス | はい |
| input | テスト入力データ | はい |
| output | 出力ディレクトリー | いいえ |