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.
| Item | Value |
|---|---|
| Task | PXRD → crystal system (7) / space group (230) / lattice params (6) |
| Backbone | 1D ConvNeXt (channels 80, kernel 100/50/25, stride 5) |
| Params | 8,734,989 |
| Input | 8192-point intensity pattern, normalized to [0, 100] |
| Device | npu:0 (Ascend), CPU fallback |
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/OpenAlphaDiffractinference.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.
python3 inference.py --img sample_pattern.npyThe --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}
}Serve the model over HTTP:
python3 inference.py --serve --port 8000Health 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.
npu:0; NPU init is wrapped in try-except with a CPU fallback.cuda (case-insensitive) in the project code..
├── 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, ...}