Skip to main content

faster-diffBloch

Drop-in Apple Silicon Metal GPU and optimized CPU acceleration for diffBloch electron crystallography structure refinement.

Documentation and comparison benchmarks: https://godofecht.github.io/diffFlow/

Original diffBloch project: https://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?

  1. Native Metal GPU Execution on macOS: PyTorch MPS lacks a native GPU kernel for aten::linalg_matrix_exp, which causes PyTorch to fall back to CPU execution with host-device memory transfers. faster-diffBloch executes matrix exponentials directly on Apple Silicon Metal with zero-copy unified memory.

  2. Blocked-Pair Adjoint Formulation: Standard matrix exponential autograd embeds the operator into a $2N \times 2N$ block matrix, costing $8 \times N^3$ FLOPs. faster-diffBloch evaluates the pullback in the block-triangular pair algebra $(Y_a Y_b, Y_a L_b + L_a Y_b)$, reducing the work to $3 \times N^3$ FLOPs (2.67x fewer products).

  3. Bit-for-Bit Validation: Passes all 738 unit tests in diffBloch and reproduces the experimental 99-rotation quartz dataset ($R_{\text{obs}} = 0.0486$).


Performance

Forward and backward timing comparison on Apple Silicon (M4 Max) at $N=579$ beams (CsPbBr3 scale):

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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

faster_diffbloch-0.1.1.tar.gz (23.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

faster_diffbloch-0.1.1-py3-none-any.whl (27.6 kB view details)

Uploaded Python 3

File details

Details for the file faster_diffbloch-0.1.1.tar.gz.

File metadata

  • Download URL: faster_diffbloch-0.1.1.tar.gz
  • Upload date:
  • Size: 23.4 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for faster_diffbloch-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9cabb578d9d2b16a1c746cff928c9ffdd3509c3890045c0ab56f969d2e972a74
MD5 f266f9a216dcff95c80bbc1724e81c74
BLAKE2b-256 d0e44b8a47ca2422e61720a82e80887871e993443c7b05ce540cb3b89b1893d1

See more details on using hashes here.

File details

Details for the file faster_diffbloch-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: faster_diffbloch-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 27.6 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for faster_diffbloch-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 08dc7c39815b5359c05380731bdfc5edbabda2bd0f2c684e9ff3e47aeb37ff08
MD5 0b41a9daa594379bc0f93b0b8f40c018
BLAKE2b-256 c6e0642c9769d42547610cb26331f663ddbc9f3923afec6652b3e330ff4001b5

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page