From external-gitcode-ascend-skills
Migrates GENERator DNA sequence generation models from CUDA to Huawei Ascend NPU, covering environment setup, dependency installation, code adaptation, multi-process handling, and sequence recovery validation.
How this skill is triggered — by the user, by Claude, or both
Slash command
/external-gitcode-ascend-skills:generatorThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
| 项目 | 要求 |
| 项目 | 要求 |
|---|---|
| 硬件 | Ascend910 系列(至少 1 卡) |
| CANN | ≥ 8.2(验证版本 8.3.RC1) |
| Python | 3.11 |
| PyTorch | 2.5.1 |
| torch_npu | 2.5.1 |
source /usr/local/Ascend/ascend-toolkit/set_env.sh
export PIP_INDEX_URL=https://repo.huaweicloud.com/repository/pypi/simple/
conda create -n GENERator python=3.11 -y
pip install torch==2.5.1 -i https://repo.huaweicloud.com/repository/pypi/simple/
pip install torch_npu==2.5.1 # 从本地 whl 或华为源安装
pip install numpy==1.26.4 pyyaml decorator attrs psutil absl-py cloudpickle ml-dtypes scipy tornado
pip install transformers==4.49.0 huggingface_hub 'datasets<3.0.0' scikit-learn pandas tqdm pyarrow
import torch_npu
from torch_npu.contrib import transfer_to_npu
| 原始代码 | 替换为 |
|---|---|
torch.cuda.set_device(id) | torch.npu.set_device(id) |
device = f"cuda:{id}" | device = f"npu:{id}" |
torch.cuda.empty_cache() | torch.npu.empty_cache() |
torch.cuda.device_count() | torch.npu.device_count() |
原始代码使用 dtype=dtype,需改为 torch_dtype=dtype:
model = AutoModelForCausalLM.from_pretrained(
args.model_path,
trust_remote_code=True,
torch_dtype=dtype # 原为 dtype=dtype
).to(device)
GENERator 使用 ProcessPoolExecutor 进行多卡推理。 每个子进程函数内需重新导入 torch_npu:
def process_data_shard(shard_id, ...):
import torch_npu
from torch_npu.contrib import transfer_to_npu
torch.npu.set_device(shard_id)
device = f"npu:{shard_id}"
...
os.environ["HF_ENDPOINT"] = "https://hf-mirror.com"
source /usr/local/Ascend/ascend-toolkit/set_env.sh
export ASCEND_RT_VISIBLE_DEVICES=0
conda activate GENERator
cd /root/GENERator
python src/tasks/downstream/sequence_recovery.py --bf16
验证通过标准:
✅ Completed 和 📊 Results saved./sequence_recovery_results/GENERator-v2-eukaryote-1.2b-base_bfloat16.parquetASCEND_RT_VISIBLE_DEVICES 控制可见设备数量python scripts/validate_generator_env.py --model-path /path/to/modelreferences/runtime-adaptation.mdnpx claudepluginhub ascend-ai-coding/awesome-ascend-skills --plugin npu-torchair-inferMigrates OligoFormer (siRNA efficacy prediction) from CUDA to Huawei Ascend NPU, covering environment setup, RNA-FM installation, code adaptation, inference verification, and optional training.
Generates and analyzes DNA sequences via NVIDIA's Evo 2 BioNeMo NIM, supporting hosted API calls and local Docker deployment on FP8-capable GPUs for layer outputs, logits, and generation.
Creates, edits, and optimizes skills for Claude Code, including drafting, evaluating with test prompts, iterating on performance, and improving skill descriptions for better triggering accuracy.