eardoi/OpenAlphaDiffract-npu
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

OpenAlphaDiffract 昇腾 NPU 适配

OpenAlphaDiffract 是基于 1D ConvNeXt 的多任务粉末 X 射线衍射(PXRD)晶体学分析模型。给定一条 8192 点的 PXRD 强度谱,同时预测晶系(7 类)、空间群(230 类)与晶格参数(6 个:a, b, c, α, β, γ)。

模型规格

项目值
模型linked-liszt/OpenAlphaDiffract
架构1D ConvNeXt × 3 层 + 多任务 MLP 头
参数量8,734,989
输入8192 点 PXRD 强度谱,归一化到 [0, 100]
输出晶系(7 类)+ 空间群(230 类)+ 晶格参数(6 个)
许可证BSD 3-Clause
精度float32

环境要求

  • 硬件:Ascend 910B 系列(≥1 卡)
  • CANN ≥ 8.0(source /usr/local/Ascend/ascend-toolkit/set_env.sh)
  • Python 3.10 – 3.11
  • torch 2.9.0 / torch_npu 2.9.0.post1

环境准备

export PIP_INDEX_URL=https://repo.huaweicloud.com/repository/pypi/simple/
pip install torch torch_npu safetensors numpy

模型权重

权重文件(model.safetensors / config.json / maxsub.json / model.py)从 Hugging Face 获取:

export HF_ENDPOINT=https://hf-mirror.com
huggingface-cli download linked-liszt/OpenAlphaDiffract --local-dir model_src

推理

python3 inference.py --model_path . --device npu:0

可选参数:

  • --input <pattern.npy>:指定 8192 点 PXRD 强度谱(npy 文件);缺省使用合成的模拟衍射谱
  • --output <out.npz>:保存各头 logits 与晶格参数

输出示例(合成模拟谱):

[info] device = npu:0
[info] model loaded (1.20s), device=npu:0
[result] Crystal system : Triclinic (88.7%)
[result] Space group    : #1 (38.5%)
[result]       a =    5.760 A
[result]       b =    7.660 A
[result]       c =   11.212 A
[result]   alpha =   91.745 deg
[result]    beta =   90.308 deg
[result]   gamma =   91.784 deg

验证结果

  • 设备:Ascend 910B(npu:0)
  • 推理:✅ 通过(模型权重真实加载,输入/输出张量均位于 npu:0)
  • 验证日期:2026-08-22

适配说明

模型代码为纯 PyTorch 实现,无 CUDA 专属 API,直接迁移 npu:0 即可运行。from_pretrained 通过 safetensors 加载权重,无需改动架构。

目录结构

├── inference.py       # NPU 推理脚本
├── model.py           # 模型定义(原仓库自带)
├── config.json        # 架构配置
├── model.safetensors  # 权重(不推送)
├── maxsub.json        # 空间群子群图
├── README.md          # 本模型卡片
└── assets/            # 截图素材

引用

@article{andrejevic2026alphadiffract,
  title   = {AlphaDiffract: Automated Crystallographic Analysis of Powder X-ray Diffraction Data},
  author  = {Andrejevic, Nina and Du, Ming and Sharma, Hemant and Horwath, James P. and Luo, Aileen and Yin, Xiangyu and Prince, Michael and Toby, Brian H. and Cherukara, Mathew J.},
  year    = {2026},
  eprint  = {2603.23367},
  archivePrefix = {arXiv},
  primaryClass  = {cond-mat.mtrl-sci}
}