f
gcw_pCMO8DfP/OpenAlphaDiffract
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

OpenAlphaDiffract (Ascend NPU)

NPU-adapted inference for linked-liszt/OpenAlphaDiffract — a multi-task 1D ConvNeXt model for automated crystallographic analysis of powder X-ray diffraction (PXRD) data.

The model is executed on an Ascend NPU via torch-npu. No CUDA is used anywhere.

ItemValue
TaskPXRD → crystal system (7) / space group (230) / lattice params (6)
Backbone1D ConvNeXt (channels 80, kernel 100/50/25, stride 5)
Params8,734,989
Input8192-point intensity pattern, normalized to [0, 100]
Devicenpu:0 (Ascend), CPU fallback

1. Get the weights

Weights are cached in ./model_weights/OpenAlphaDiffract (auto-downloaded on first run from the hf-mirror.com mirror if the cache is missing):

mkdir -p model_weights/OpenAlphaDiffract
HF_ENDPOINT=https://hf-mirror.com python3 -m huggingface_hub.snapshot_download \
  linked-liszt/OpenAlphaDiffract --local-dir model_weights/OpenAlphaDiffract

inference.py loads the local cache first (config.json, maxsub.json, model.safetensors) and only downloads when the cache is absent.

Weights are git-ignored; only code and assets/ are published.

2. CLI inference

python3 inference.py --img sample_pattern.npy

The --img argument accepts a PXRD pattern file: .npy, .npz, .txt, .csv or a spectrum image (PNG/JPG, digitized to a 1D 8192-point profile). The pattern is floored at zero and rescaled to [0, 100] before inference.

Example output:

{
  "model": "OpenAlphaDiffract",
  "device": "npu:0",
  "crystal_system": {"class": "Cubic", "index": 6, "confidence": 0.91},
  "space_group": {"number": 225, "confidence": 0.42},
  "lattice_parameters": {"a": 4.08, "b": 4.08, "c": 4.08, "alpha": 90.0, "beta": 90.0, "gamma": 90.0}
}

3. FastAPI service

Serve the model over HTTP:

python3 inference.py --serve --port 8000

Health check:

curl http://127.0.0.1:8000/health
# {"status":"ok","model":"OpenAlphaDiffract","device":"npu:0"}

Prediction (upload a pattern file):

curl -X POST http://127.0.0.1:8000/predict -F "file=@sample_pattern.npy"

Returns the same JSON result as the CLI.

4. Notes

  • Model and tensors are moved to npu:0; NPU init is wrapped in try-except with a CPU fallback.
  • No CUDA calls; verified by grep for cuda (case-insensitive) in the project code.
  • Input format: 8192 equally-spaced intensity values over a 2θ range of 5–20°.

5. Directory layout

.
├── inference.py            # dual-mode NPU inference (CLI + FastAPI)
├── model.py                # self-contained AlphaDiffract model definition
├── sample_pattern.npy      # sample input (synthetic PXRD pattern)
├── sample_pattern.txt
├── README.md
├── assets/                 # 3 screenshots (NPU workflow / CLI / web)
└── model_weights/          # git-ignored weight cache
    └── OpenAlphaDiffract/{model.safetensors, config.json, maxsub.json, ...}