faster-diffbloch 0.1.5__tar.gz → 0.1.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: faster-diffbloch
3
- Version: 0.1.5
3
+ Version: 0.1.6
4
4
  Summary: Drop-in Metal GPU (macOS) and optimized CPU (macOS/Linux) acceleration for diffBloch
5
5
  Project-URL: Homepage, https://godofecht.github.io/diffFlow/
6
6
  Project-URL: Documentation, https://godofecht.github.io/diffFlow/
@@ -35,7 +35,7 @@ Description-Content-Type: text/markdown
35
35
 
36
36
  Drop-in Apple Silicon Metal GPU and optimized CPU acceleration for [diffBloch](https://diffbloch.com) electron crystallography structure refinement.
37
37
 
38
- A Metal GPU path for Apple Silicon and an optimized CPU path for macOS and Linux, measured against diffBloch running on PyTorch.
38
+ **2.59x faster than PyTorch** on the forward-plus-backward pass at 579 beams, through the Metal path on Apple Silicon. An optimized CPU path covers macOS and Linux.
39
39
 
40
40
  | Package | Documentation | Source repository | Original project |
41
41
  | :--- | :--- | :--- | :--- |
@@ -78,28 +78,40 @@ example documents.
78
78
 
79
79
  ## Performance
80
80
 
81
- Forward-plus-backward timing on an Apple M4 Max, single-threaded PyTorch,
82
- running the same diffBloch workload through `bench/compare_faster.py`. This is
83
- what `pip install faster-diffbloch` gives you: the accelerated matrix
84
- exponential bridged into diffBloch, with PyTorch handling everything else.
85
-
86
- | Beams | faster-diffbloch | PyTorch | Speedup |
87
- | :---: | :---: | :---: | :---: |
88
- | 31 | 1.48 ms | 1.54 ms | 1.05x |
89
- | 61 | 1.93 ms | 2.07 ms | 1.07x |
90
- | 91 | 3.48 ms | 3.69 ms | 1.06x |
91
- | 163 | 8.76 ms | 10.14 ms | 1.16x |
92
-
93
- Best of three alternating runs per mode. The gain grows with beam count,
94
- because the matrix exponential takes a larger share of the work as the system
95
- grows and the fixed ctypes and PyTorch overhead matters less.
81
+ Forward-plus-backward timing on an Apple M4 Max, single-threaded PyTorch, over
82
+ the same diffBloch quartz workload at five beam counts. Both device paths, best
83
+ of three runs each.
84
+
85
+ | Beams | PyTorch | CPU path | Metal path | CPU | Metal |
86
+ | :---: | :---: | :---: | :---: | :---: | :---: |
87
+ | 31 | 1.52 ms | 1.42 ms | 1.95 ms | 1.07x | 0.78x |
88
+ | 61 | 2.11 ms | 2.07 ms | 2.20 ms | 1.02x | 0.96x |
89
+ | 91 | 3.87 ms | 3.61 ms | 3.70 ms | 1.07x | 1.05x |
90
+ | 163 | 10.46 ms | 8.60 ms | 6.27 ms | 1.22x | 1.67x |
91
+ | 579 | 123.30 ms | 89.17 ms | 47.63 ms | 1.38x | **2.59x** |
92
+
93
+ The speedup grows with beam count, and this is the shape of the result rather
94
+ than noise. The package replaces the matrix exponential, which costs O(N^3),
95
+ while structure factors and the loss stay in PyTorch. As the system grows the
96
+ exponential takes a larger share of the runtime, so there is more for the
97
+ accelerated path to reach.
98
+
99
+ That has two practical consequences. At 579 beams, CsPbBr3 scale, Metal runs the
100
+ forward-plus-backward pass in 47.63 ms against PyTorch's 123.30 ms. Below about
101
+ 91 beams Metal is slower than PyTorch, because the dispatch cost outweighs a
102
+ small exponential, so `enable(device="cpu")` is the better choice for small
103
+ systems.
104
+
105
+ Forward pass alone at 579 beams: PyTorch 25.90 ms, Metal 15.58 ms, a factor of
106
+ 1.66. PyTorch MPS has no native kernel for `aten::linalg_matrix_exp` and falls
107
+ back to the CPU with host transfers, which is the gap this closes.
96
108
 
97
109
  ### The standalone Flow port
98
110
 
99
111
  The diffFlow repository also holds a standalone port of the whole calculation,
100
112
  compiled from Flow rather than bridged into PyTorch. It avoids the framework
101
- overhead entirely and is considerably faster. At 579 beams, forward plus
102
- backward, minimum of five runs:
113
+ overhead and goes further. At 579 beams, forward plus backward, minimum of five
114
+ runs:
103
115
 
104
116
  | Implementation | Forward + Backward |
105
117
  | :--- | :---: |
@@ -108,29 +120,12 @@ backward, minimum of five runs:
108
120
  | Flow port, C backend | 82.84 ms |
109
121
  | Flow port, MLIR backend | 79.74 ms |
110
122
 
111
- Those numbers are not what this package delivers. They are reachable by
112
- running the port directly, and they are why the package exists. See the
123
+ Running the port directly is how those are reached. See the
113
124
  [diffFlow documentation](https://godofecht.github.io/diffFlow/).
114
125
 
115
126
  These figures come from one workload on one machine. Other crystals, hardware
116
127
  configurations and beam counts will differ.
117
128
 
118
- ### Metal GPU
119
-
120
- The Metal path is available on Apple Silicon through `enable(device="gpu")`.
121
- Correctness on this path is checked: the quartz reproduction above runs through
122
- it. The timings below come from an earlier run and have not been reproduced
123
- against the current package, so treat those as indicative.
124
-
125
- ### Package benchmark snapshot
126
-
127
- | Implementation | Forward | Forward + Backward | Speedup vs PyTorch CPU | Speedup vs PyTorch MPS |
128
- | :--- | :---: | :---: | :---: | :---: |
129
- | PyTorch CPU | 25.7 ms | 130.3 ms | 1.00x | 1.17x |
130
- | PyTorch MPS (fallback) | 26.2 ms | 153.0 ms | 0.85x | 1.00x |
131
- | **faster-diffBloch CPU** | **24.4 ms** | **83.5 ms** | **1.56x** | **1.83x** |
132
- | **faster-diffBloch Metal GPU** | **13.1 ms** | **58.1 ms** | **2.24x** | **2.63x** |
133
-
134
129
  ---
135
130
 
136
131
  ## Installation
@@ -2,7 +2,7 @@
2
2
 
3
3
  Drop-in Apple Silicon Metal GPU and optimized CPU acceleration for [diffBloch](https://diffbloch.com) electron crystallography structure refinement.
4
4
 
5
- A Metal GPU path for Apple Silicon and an optimized CPU path for macOS and Linux, measured against diffBloch running on PyTorch.
5
+ **2.59x faster than PyTorch** on the forward-plus-backward pass at 579 beams, through the Metal path on Apple Silicon. An optimized CPU path covers macOS and Linux.
6
6
 
7
7
  | Package | Documentation | Source repository | Original project |
8
8
  | :--- | :--- | :--- | :--- |
@@ -45,28 +45,40 @@ example documents.
45
45
 
46
46
  ## Performance
47
47
 
48
- Forward-plus-backward timing on an Apple M4 Max, single-threaded PyTorch,
49
- running the same diffBloch workload through `bench/compare_faster.py`. This is
50
- what `pip install faster-diffbloch` gives you: the accelerated matrix
51
- exponential bridged into diffBloch, with PyTorch handling everything else.
52
-
53
- | Beams | faster-diffbloch | PyTorch | Speedup |
54
- | :---: | :---: | :---: | :---: |
55
- | 31 | 1.48 ms | 1.54 ms | 1.05x |
56
- | 61 | 1.93 ms | 2.07 ms | 1.07x |
57
- | 91 | 3.48 ms | 3.69 ms | 1.06x |
58
- | 163 | 8.76 ms | 10.14 ms | 1.16x |
59
-
60
- Best of three alternating runs per mode. The gain grows with beam count,
61
- because the matrix exponential takes a larger share of the work as the system
62
- grows and the fixed ctypes and PyTorch overhead matters less.
48
+ Forward-plus-backward timing on an Apple M4 Max, single-threaded PyTorch, over
49
+ the same diffBloch quartz workload at five beam counts. Both device paths, best
50
+ of three runs each.
51
+
52
+ | Beams | PyTorch | CPU path | Metal path | CPU | Metal |
53
+ | :---: | :---: | :---: | :---: | :---: | :---: |
54
+ | 31 | 1.52 ms | 1.42 ms | 1.95 ms | 1.07x | 0.78x |
55
+ | 61 | 2.11 ms | 2.07 ms | 2.20 ms | 1.02x | 0.96x |
56
+ | 91 | 3.87 ms | 3.61 ms | 3.70 ms | 1.07x | 1.05x |
57
+ | 163 | 10.46 ms | 8.60 ms | 6.27 ms | 1.22x | 1.67x |
58
+ | 579 | 123.30 ms | 89.17 ms | 47.63 ms | 1.38x | **2.59x** |
59
+
60
+ The speedup grows with beam count, and this is the shape of the result rather
61
+ than noise. The package replaces the matrix exponential, which costs O(N^3),
62
+ while structure factors and the loss stay in PyTorch. As the system grows the
63
+ exponential takes a larger share of the runtime, so there is more for the
64
+ accelerated path to reach.
65
+
66
+ That has two practical consequences. At 579 beams, CsPbBr3 scale, Metal runs the
67
+ forward-plus-backward pass in 47.63 ms against PyTorch's 123.30 ms. Below about
68
+ 91 beams Metal is slower than PyTorch, because the dispatch cost outweighs a
69
+ small exponential, so `enable(device="cpu")` is the better choice for small
70
+ systems.
71
+
72
+ Forward pass alone at 579 beams: PyTorch 25.90 ms, Metal 15.58 ms, a factor of
73
+ 1.66. PyTorch MPS has no native kernel for `aten::linalg_matrix_exp` and falls
74
+ back to the CPU with host transfers, which is the gap this closes.
63
75
 
64
76
  ### The standalone Flow port
65
77
 
66
78
  The diffFlow repository also holds a standalone port of the whole calculation,
67
79
  compiled from Flow rather than bridged into PyTorch. It avoids the framework
68
- overhead entirely and is considerably faster. At 579 beams, forward plus
69
- backward, minimum of five runs:
80
+ overhead and goes further. At 579 beams, forward plus backward, minimum of five
81
+ runs:
70
82
 
71
83
  | Implementation | Forward + Backward |
72
84
  | :--- | :---: |
@@ -75,29 +87,12 @@ backward, minimum of five runs:
75
87
  | Flow port, C backend | 82.84 ms |
76
88
  | Flow port, MLIR backend | 79.74 ms |
77
89
 
78
- Those numbers are not what this package delivers. They are reachable by
79
- running the port directly, and they are why the package exists. See the
90
+ Running the port directly is how those are reached. See the
80
91
  [diffFlow documentation](https://godofecht.github.io/diffFlow/).
81
92
 
82
93
  These figures come from one workload on one machine. Other crystals, hardware
83
94
  configurations and beam counts will differ.
84
95
 
85
- ### Metal GPU
86
-
87
- The Metal path is available on Apple Silicon through `enable(device="gpu")`.
88
- Correctness on this path is checked: the quartz reproduction above runs through
89
- it. The timings below come from an earlier run and have not been reproduced
90
- against the current package, so treat those as indicative.
91
-
92
- ### Package benchmark snapshot
93
-
94
- | Implementation | Forward | Forward + Backward | Speedup vs PyTorch CPU | Speedup vs PyTorch MPS |
95
- | :--- | :---: | :---: | :---: | :---: |
96
- | PyTorch CPU | 25.7 ms | 130.3 ms | 1.00x | 1.17x |
97
- | PyTorch MPS (fallback) | 26.2 ms | 153.0 ms | 0.85x | 1.00x |
98
- | **faster-diffBloch CPU** | **24.4 ms** | **83.5 ms** | **1.56x** | **1.83x** |
99
- | **faster-diffBloch Metal GPU** | **13.1 ms** | **58.1 ms** | **2.24x** | **2.63x** |
100
-
101
96
  ---
102
97
 
103
98
  ## Installation
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "faster-diffbloch"
7
- version = "0.1.5"
7
+ version = "0.1.6"
8
8
  description = "Drop-in Metal GPU (macOS) and optimized CPU (macOS/Linux) acceleration for diffBloch"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -4,7 +4,7 @@ from __future__ import annotations
4
4
 
5
5
  from .backend import enable, disable, matrix_exp, matrix_exp_backward, faster_propagate
6
6
 
7
- __version__ = "0.1.5"
7
+ __version__ = "0.1.6"
8
8
  __all__ = [
9
9
  "enable",
10
10
  "disable",