OpenAlphaDiffract is a multi-task deep learning model designed for automated crystallographic analysis of powder X-ray diffraction (PXRD) data. Built on a 1D ConvNeXt backbone, it simultaneously tackles three prediction tasks: crystal system classification, space group identification, and lattice parameter regression.
This repository contains the adapted deployment package for Huawei Ascend NPU platforms, enabling hardware-accelerated inference on the torch_npu framework. The original model was developed by the Advanced Photon Source team at Argonne National Laboratory.
The model processes 8192-point PXRD intensity patterns through three ConvNeXt stages with progressively smaller kernel sizes (100, 50, 25) and stride-5 downsampling. After a final average pooling operation, the 560-dimensional feature vector feeds into three independent MLP heads:
| Component | Description |
|---|---|
| NPU | Ascend 910B (Atlas 800) |
| Available Chips | 2 (physical IDs 0 and 1) |
| HBM per Chip | 64 GB |
| Architecture | aarch64 (ARM64) |
| Component | Version |
|---|---|
| Python | 3.11.14 |
| PyTorch | 2.9.0 |
| torch_npu | 2.9.0.post1 |
| CANN | 8.5.1 |
| vLLM-Ascend | 0.18.0 |
| safetensors | latest |
pip install torch torch-npu numpy safetensors fastapi uvicornThe model weights are stored in Git LFS. The repository can be cloned directly from GitCode, and the actual weight file (~35 MB) can be retrieved via the LFS batch API:
import urllib.request, json
oid = '4d81f2716ef8c78683d52ac51afff3eaf160c0b2b410685d0c90299bc2fd58ed'
lfs_url = 'https://gitcode.com/hf_mirrors/linked-liszt/OpenAlphaDiffract.git/info/lfs/objects/batch'
payload = json.dumps({'operation':'download','objects':[{'oid':oid,'size':35155332}],'transfers':['basic']}).encode()
req = urllib.request.Request(lfs_url, data=payload, headers={'Content-Type':'application/vnd.git-lfs+json','Accept':'application/vnd.git-lfs+json','User-Agent':'git-lfs/3.0'})
with urllib.request.urlopen(req, timeout=30) as resp:
dl_url = json.loads(resp.read())['objects'][0]['actions']['download']['href']
data = urllib.request.urlopen(urllib.request.Request(dl_url)).read()
with open('model.safetensors','wb') as f:
f.write(data)# Single inference with random test pattern
python inference.py
# Inference with custom PXRD pattern
python inference.py --pattern /path/to/pattern.npy --device npu:0python inference.py --server --port 8000 --device npu:0The server exposes two endpoints:
GET /health - health checkPOST /predict - inference endpointimport requests
import numpy as np
pattern = np.random.rand(8192).tolist()
response = requests.post(
"http://localhost:8000/predict",
json={"pattern": pattern}
)
print(response.json())After deployment, confirm the model is working correctly:
npu-smi info # Check NPU status
curl http://localhost:8000/health # Check service healthA successful inference should produce results like:
{
"crystal_system": {
"label": "Cubic",
"confidence": 0.4148
},
"space_group": {
"number": 225,
"confidence": 0.2086
},
"lattice_parameters": {
"a (A)": 3.1642,
"b (A)": 3.298,
"c (A)": 4.14,
"alpha (deg)": 93.4535,
"beta (deg)": 90.5563,
"gamma (deg)": 94.7425
}
}Testing on Ascend 910B with random PXRD inputs:
| Metric | Value |
|---|---|
| Model Load Time | ~2.5 seconds |
| Single Inference | ~20 ms |
| NPU Memory Usage | ~190 MB |
| Weight File Size | ~35 MB |
| Total Parameters | 8,734,989 |
The model has a relatively small memory footprint, making it suitable for concurrent deployment scenarios on shared NPU infrastructure.
The deployed model was validated to ensure functional correctness on NPU hardware. Key verification points:
The original model's reported accuracy metrics (single model, Materials Project training):
These metrics are from the original paper and apply to the model weights regardless of the inference backend.
Device Selection: Run npu-smi info to verify available NPU chips. Use npu:0 or npu:1 for device specification. The NPU group number shown in npu-smi output is not the device ID.
Input Preprocessing: The model expects 8192 equally-spaced intensity values. Preprocessing steps: floor negative values to zero, then rescale to [0, 100] range. The original paper recommends 5-20 degrees 2theta range with monochromatic 20 keV radiation.
Weight File: The model.safetensors file in the git repository is an LFS pointer (133 bytes). The actual weight file (35 MB) must be downloaded separately through the LFS batch API.
Port Conflicts: If port 8000 is occupied, specify an alternative port with --port when starting the server.
Single Model Release: This repository contains a single model trained on Materials Project data only. The 10-model ensemble described in the research paper achieves higher accuracy but is not included in this release.