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


Why faster-diffBloch?

  1. Native Metal GPU Execution: 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
faster_diffbloch.enable(device="gpu")

# Or CPU acceleration
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.0.tar.gz (22.3 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.0-py3-none-any.whl (26.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: faster_diffbloch-0.1.0.tar.gz
  • Upload date:
  • Size: 22.3 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.0.tar.gz
Algorithm Hash digest
SHA256 d311c3f191dafdda4042761bf6eb393dee6b3d1691d9483216e431b9a2bdc716
MD5 e311c6d36fed72ce88450125a69f471d
BLAKE2b-256 bc2f0f3b6d31f67a8e4d1453d25fd875bb2630b9995f087cfce2adbfa61486cf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: faster_diffbloch-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 26.4 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eca648e75e63f3e132c4e793f3ae6d018c6e2c1be251f43643cbb04bb08201c9
MD5 5c278377519ce9e42162cfe30c647df8
BLAKE2b-256 f1f7518086ae5df925a0122edc02570c09757a8e732fd9de6db64e3fdfe9b829

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.1

2 files

This release

0.1.0 This release

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