Commit 63f0e71
committed
perf/accuracy: Flash Attention, torch-native SO3, cosine schedule, DDIM, analytical g(t)
Attention (Attention_module.py):
- Replace hand-rolled einsum attention with F.scaled_dot_product_attention in
Attention, AttentionWithBias, and MSAColAttention. Uses Flash Attention
automatically when available on CUDA (20-40% speedup, O(1) memory).
- AttentionWithBias passes the pairwise bias as attn_mask so it is folded into
the fused kernel rather than materializing a separate attention matrix.
SO3 diffusion (igso3.py, diffusion.py, inference/utils.py):
- Add hat_batch(), Log_torch(), Exp_torch() -- on-device rotation ops using
the Rodrigues formula. Eliminates all scipy CPU round-trips during inference.
- Replace scipy_R calls in reverse_sample_vectorized() and diffuse_frames() with
the new torch-native equivalents (stay on GPU, no .cpu()/.numpy() transfers).
- Remove redundant scipy rotation normalization in get_next_frames(); rotation
matrices from rigid_from_3_points are already orthogonal.
Noise schedule (diffusion.py):
- Add cosine schedule (Nichol & Dhariwal, 2021). Enabled via
schedule_type="cosine"; b0/bT are ignored for this mode.
- Analytical g(t) for linear schedule: eliminates a per-step autograd call.
Formula: g(t) = sqrt(2 * sigma(t) * (min_b + t*(max_b - min_b))).
IGSO3 cache (diffusion.py):
- Add module-level _igso3_cache dict. Avoids repeated disk deserialization when
multiple Diffuser objects are created in the same process (batch inference).
DDIM sampling (inference/utils.py):
- Add get_mu_xt_x0_ddim() implementing the deterministic DDIM update rule.
- Wire ddim=True flag through Denoise.__init__() -> get_next_pose() -> get_next_ca().
Setting ddim=True produces deterministic, lower-variance trajectories and
enables fewer-step inference at equivalent quality.
Numerical stability (kinematics.py):
- Clamp input to acos in get_ang() to [-1, 1] to prevent NaN from float
rounding at exactly +/-1.1 parent 2d0c003 commit 63f0e71
5 files changed
Lines changed: 180 additions & 103 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
77 | 71 | | |
78 | 72 | | |
79 | 73 | | |
| |||
117 | 111 | | |
118 | 112 | | |
119 | 113 | | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
132 | 123 | | |
133 | | - | |
134 | | - | |
135 | | - | |
| 124 | + | |
136 | 125 | | |
137 | 126 | | |
138 | 127 | | |
| |||
265 | 254 | | |
266 | 255 | | |
267 | 256 | | |
268 | | - | |
| 257 | + | |
269 | 258 | | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
277 | 269 | | |
278 | | - | |
279 | | - | |
280 | | - | |
| 270 | + | |
281 | 271 | | |
282 | 272 | | |
283 | 273 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | | - | |
9 | | - | |
10 | 9 | | |
11 | | - | |
12 | 10 | | |
13 | | - | |
14 | 11 | | |
15 | 12 | | |
16 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
22 | | - | |
23 | | - | |
24 | | - | |
| 23 | + | |
25 | 24 | | |
26 | | - | |
27 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
28 | 32 | | |
29 | | - | |
30 | | - | |
31 | 33 | | |
32 | | - | |
33 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
34 | 38 | | |
35 | 39 | | |
36 | | - | |
37 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
38 | 47 | | |
39 | | - | |
40 | | - | |
| 48 | + | |
41 | 49 | | |
42 | 50 | | |
43 | 51 | | |
44 | 52 | | |
45 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
46 | 56 | | |
47 | 57 | | |
48 | 58 | | |
| |||
228 | 238 | | |
229 | 239 | | |
230 | 240 | | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
231 | 245 | | |
232 | 246 | | |
233 | 247 | | |
| |||
241 | 255 | | |
242 | 256 | | |
243 | 257 | | |
| 258 | + | |
244 | 259 | | |
245 | 260 | | |
246 | 261 | | |
| |||
288 | 303 | | |
289 | 304 | | |
290 | 305 | | |
291 | | - | |
| 306 | + | |
292 | 307 | | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
| 308 | + | |
297 | 309 | | |
298 | | - | |
299 | | - | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
300 | 314 | | |
301 | | - | |
302 | | - | |
| 315 | + | |
303 | 316 | | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
308 | 329 | | |
309 | 330 | | |
310 | 331 | | |
| |||
427 | 448 | | |
428 | 449 | | |
429 | 450 | | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
436 | 454 | | |
437 | 455 | | |
438 | 456 | | |
| |||
494 | 512 | | |
495 | 513 | | |
496 | 514 | | |
497 | | - | |
| 515 | + | |
498 | 516 | | |
499 | | - | |
500 | | - | |
501 | | - | |
| 517 | + | |
| 518 | + | |
502 | 519 | | |
503 | 520 | | |
504 | 521 | | |
| |||
527 | 544 | | |
528 | 545 | | |
529 | 546 | | |
530 | | - | |
| 547 | + | |
| 548 | + | |
531 | 549 | | |
532 | 550 | | |
533 | 551 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
19 | 59 | | |
20 | | - | |
| 60 | + | |
21 | 61 | | |
22 | 62 | | |
23 | 63 | | |
24 | | - | |
25 | | - | |
| 64 | + | |
26 | 65 | | |
27 | 66 | | |
28 | 67 | | |
| |||
0 commit comments