faster-diffbloch
Drop-in Apple Silicon Metal GPU and optimized CPU acceleration for diffBloch electron crystallography structure refinement.
A Metal GPU path for Apple Silicon and an optimized CPU path for macOS and Linux, measured against diffBloch running on PyTorch.
| Package | Documentation | Source repository | Original project |
|---|---|---|---|
| PyPI · piwheels | diffFlow documentation and benchmarks | github.com/godofecht/diffFlow | diffbloch.com |
Operating System and Platform Support
| Operating System / Hardware | CPU Acceleration (device="cpu") |
GPU Acceleration (device="gpu") |
Backend Runtime |
|---|---|---|---|
| macOS Apple Silicon (M1/M2/M3/M4/Max/Ultra) | Supported | Supported | Native Metal Compute Shaders + Apple Accelerate BLAS |
| macOS Intel (x86_64) | Supported | Fallback to CPU | Apple Accelerate BLAS |
| Linux (x86_64 / aarch64) | Supported | Fallback to CPU | OpenBLAS / C11 BLAS |
| Windows | PyTorch Reference | PyTorch Reference | Pure PyTorch Reference Fallback |
Runtime platform guards automatically detect your operating system and hardware configuration. When device="gpu" is requested on Linux, faster-diffbloch automatically selects the optimized CPU backend with an informative warning.
Why faster-diffBloch?
faster-diffbloch keeps the diffBloch workflow and public API intact while moving
the expensive propagation and gradient work onto an accelerated native backend.
You get the same scientific calculation, with a faster path on supported hardware
and a safe PyTorch fallback when the native backend is unavailable.
The package is validated against diffBloch's own test suite. With acceleration enabled it passes all 738 diffBloch tests and 55 conformance tests that compare the accelerated results against diffBloch's, field by field, including gradients. The diffBloch run makes 4855 calls into the native matrix exponential, so the accelerated path is exercised rather than skipped.
Performance
Forward-plus-backward timing on an Apple M4 Max, single-threaded PyTorch,
running the same diffBloch workload through bench/compare_faster.py. This is
what pip install faster-diffbloch gives you: the accelerated matrix
exponential bridged into diffBloch, with PyTorch handling everything else.
| Beams | faster-diffbloch | PyTorch | Speedup |
|---|---|---|---|
| 31 | 1.48 ms | 1.54 ms | 1.05x |
| 61 | 1.93 ms | 2.07 ms | 1.07x |
| 91 | 3.48 ms | 3.69 ms | 1.06x |
| 163 | 8.76 ms | 10.14 ms | 1.16x |
Best of three alternating runs per mode. The gain grows with beam count, because the matrix exponential takes a larger share of the work as the system grows and the fixed ctypes and PyTorch overhead matters less.
The standalone Flow port
The diffFlow repository also holds a standalone port of the whole calculation, compiled from Flow rather than bridged into PyTorch. It avoids the framework overhead entirely and is considerably faster. At 579 beams, forward plus backward, minimum of five runs:
| Implementation | Forward + Backward |
|---|---|
| PyTorch | 117.21 ms |
| Mojo port | 85.52 ms |
| Flow port, C backend | 82.84 ms |
| Flow port, MLIR backend | 79.74 ms |
Those numbers are not what this package delivers. They are reachable by running the port directly, and they are why the package exists. See the diffFlow documentation.
These figures come from one workload on one machine. Other crystals, hardware configurations and beam counts will differ.
Metal GPU
The Metal path is available on Apple Silicon through enable(device="gpu").
The table below is from an earlier run and has not been reproduced against the
current package, so treat it as indicative.
Package benchmark snapshot
| Implementation | Forward | Forward + Backward | Speedup vs PyTorch CPU | Speedup vs PyTorch MPS |
|---|---|---|---|---|
| PyTorch CPU | 25.7 ms | 130.3 ms | 1.00x | 1.17x |
| PyTorch MPS (fallback) | 26.2 ms | 153.0 ms | 0.85x | 1.00x |
| faster-diffBloch CPU | 24.4 ms | 83.5 ms | 1.56x | 1.83x |
| faster-diffBloch Metal GPU | 13.1 ms | 58.1 ms | 2.24x | 2.63x |
Installation
pip install faster-diffbloch
Usage
1. Drop-in CLI
Use diffbloch-fast or faster-diffbloch anywhere you would use diffbloch:
diffbloch-fast infer examples/Colmey_et_al_2026/data/quartz-no-abs
diffbloch-fast refine examples/Colmey_et_al_2026/data/quartz-no-abs
2. Python API Injection
Enable acceleration inside any existing diffBloch script:
import faster_diffbloch
# Enable Metal GPU acceleration (macOS Apple Silicon)
faster_diffbloch.enable(device="gpu")
# Or CPU acceleration (macOS and Linux)
faster_diffbloch.enable(device="cpu")
# Run standard diffBloch code
import diffBloch
# All propagate and matrix_exp calls now route through faster-diffBloch
Metadata
Release files for faster-diffbloch 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| faster_diffbloch-0.1.4.tar.gz | 24.8 kB | Without provenance | Details for faster_diffbloch-0.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| faster_diffbloch-0.1.4-py3-none-any.whl | Python 3 | none | any | Details for faster_diffbloch-0.1.4-py3-none-any.whl |
Total release size: 53.6 kB
Release files / faster_diffbloch-0.1.4.tar.gz
| Download URL | faster_diffbloch-0.1.4.tar.gz |
|---|---|
| Size | 24.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d2ce2272ab60aa1d39f854d192bec8b411ecb04f751a5179e00d19c68464951d
|
|
BLAKE2b-256 checksum How to use checksums |
92f58382fc6c00f7c85c1387de1bea73dcdbf3d32685f761e351626db9774541
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / faster_diffbloch-0.1.4-py3-none-any.whl
| Download URL | faster_diffbloch-0.1.4-py3-none-any.whl |
|---|---|
| Size | 28.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3df6004d8fe1a8c971eb8bdccd9d2648caeca3b4273b260eee54722b56aceca9
|
|
BLAKE2b-256 checksum How to use checksums |
af5bbc6036af7c2c301bc8f7cf69ecd299e4f89ee6020377753c9b152c1d7230
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for faster-diffbloch 0.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.