redannancy/OpenAlphaDiffract
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

OpenAlphaDiffract for Ascend NPU

Overview

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.

Model Architecture

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:

  • Crystal System Head: 560 -> 2300 -> 1150 -> 7
  • Space Group Head: 560 -> 2300 -> 1150 -> 230
  • Lattice Parameter Head: 560 -> 512 -> 256 -> 6

Deployment Environment

Hardware Configuration

ComponentDescription
NPUAscend 910B (Atlas 800)
Available Chips2 (physical IDs 0 and 1)
HBM per Chip64 GB
Architectureaarch64 (ARM64)

Software Stack

ComponentVersion
Python3.11.14
PyTorch2.9.0
torch_npu2.9.0.post1
CANN8.5.1
vLLM-Ascend0.18.0
safetensorslatest

Installing Dependencies

pip install torch torch-npu numpy safetensors fastapi uvicorn

Quick Start

Downloading Weights

The 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)

Running Inference

# Single inference with random test pattern
python inference.py

# Inference with custom PXRD pattern
python inference.py --pattern /path/to/pattern.npy --device npu:0

Starting the API Server

python inference.py --server --port 8000 --device npu:0

The server exposes two endpoints:

  • GET /health - health check
  • POST /predict - inference endpoint

Example API Call

import requests
import numpy as np

pattern = np.random.rand(8192).tolist()
response = requests.post(
    "http://localhost:8000/predict",
    json={"pattern": pattern}
)
print(response.json())

Verification

After deployment, confirm the model is working correctly:

npu-smi info                        # Check NPU status
curl http://localhost:8000/health    # Check service health

A 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
  }
}

Performance Characteristics

Testing on Ascend 910B with random PXRD inputs:

MetricValue
Model Load Time~2.5 seconds
Single Inference~20 ms
NPU Memory Usage~190 MB
Weight File Size~35 MB
Total Parameters8,734,989

The model has a relatively small memory footprint, making it suitable for concurrent deployment scenarios on shared NPU infrastructure.

Accuracy Assessment

The deployed model was validated to ensure functional correctness on NPU hardware. Key verification points:

  1. Model weights loaded successfully from safetensors format
  2. Forward pass completed without dtype or shape errors
  3. Output tensors had correct dimensions and valid probability distributions
  4. Lattice parameter predictions fell within the expected bounds

The original model's reported accuracy metrics (single model, Materials Project training):

  • Crystal system: 74.88% (simulated validation)
  • Space group: 57.31% (simulated validation)
  • Lattice parameter MAE: 2.71

These metrics are from the original paper and apply to the model weights regardless of the inference backend.

Important Notes

  1. 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.

  2. 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.

  3. 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.

  4. Port Conflicts: If port 8000 is occupied, specify an alternative port with --port when starting the server.

  5. 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.