Commit 897ad9d
Inductor Lite Mode (pytorch#167115)
This PR introduces inductor lite mode for opt-in optimizations and numeric correctness guarantees.
Different from default mode that applies all possible fusions, lite mode gives the control back to user and provides guarantee on numeric correctness. Specifically, this mode:
- **Fallback by Default**: Fallback for ALL nodes by default, unless users explicitly mark node for inductor fusion.
- **Selective Decomposition**: Skip decomposition for all nodes except for user marked nodes.
- **Regional inductor compile**
- Skip dead code elimination
- Skip buffer reues
- Skip reorder passes, such as reorder for peak memory, reorder for compute comm overlap, and reorder_for_reducing_graph_partitions.
- Skip all pre-grad, joint-graph, and post-grad passes.
## Example: Flex Attention
```python
import torch
import torch.fx.traceback as fx_traceback
from torch.nn.attention.flex_attention import create_block_mask, flex_attention
def _squared(score, b, h, m, n):
return score * score
def mask_mod(b, h, q, k):
return q >= 0
a, b = 12, 64
block_mask = create_block_mask(mask_mod, None, None, a * b, a * b, device="cuda")
def fn(x):
x = torch.sin(x)
with fx_traceback.annotate({"compile_with_inductor": 0}):
x = flex_attention(x, x, x, block_mask=block_mask, score_mod=_squared)
return torch.cos(x)
x = torch.randn(1, 1, a * b, b, dtype=torch.bfloat16, device="cuda", requires_grad=True)
opt_fn = torch.compile(fn, mode="lite", fullgraph=True,)
opt_fn(x)
```
[code diff](https://www.internalfb.com/intern/diffing/?paste_number=2027441476)
[default mode tlp](https://manifold.edge.x2p.facebook.net/v0/read/tree/logs/.tmpYAzDxX/index.html?bucketName=tlparse_reports&apiKey=tlparse_reports-key&withPayload=1&timeoutMsec=10000) vs [lite mode tlp](https://manifold.edge.x2p.facebook.net/v0/read/tree/logs/.tmpnnuh1W/index.html?bucketName=tlparse_reports&apiKey=tlparse_reports-key&withPayload=1&timeoutMsec=10000)
## Numerics
Inductor lite mode provides bitwise equivalence with `aot_eager` backend on torchtitan llama3-8b and DeepSeek v3. pytorch/torchtitan#2005
close: pytorch#167012
Pull Request resolved: pytorch#167115
Approved by: https://github.com/ezyang1 parent 76100f9 commit 897ad9d
File tree
11 files changed
+486
-18
lines changed- test/inductor
- torch
- _functorch
- _aot_autograd
- _inductor
- fx
- experimental
- passes
11 files changed
+486
-18
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
13564 | 13565 | | |
13565 | 13566 | | |
13566 | 13567 | | |
| 13568 | + | |
| 13569 | + | |
| 13570 | + | |
| 13571 | + | |
| 13572 | + | |
| 13573 | + | |
| 13574 | + | |
| 13575 | + | |
| 13576 | + | |
| 13577 | + | |
| 13578 | + | |
| 13579 | + | |
| 13580 | + | |
| 13581 | + | |
| 13582 | + | |
| 13583 | + | |
| 13584 | + | |
| 13585 | + | |
| 13586 | + | |
| 13587 | + | |
| 13588 | + | |
| 13589 | + | |
| 13590 | + | |
| 13591 | + | |
| 13592 | + | |
| 13593 | + | |
| 13594 | + | |
| 13595 | + | |
| 13596 | + | |
| 13597 | + | |
| 13598 | + | |
| 13599 | + | |
| 13600 | + | |
| 13601 | + | |
| 13602 | + | |
| 13603 | + | |
| 13604 | + | |
| 13605 | + | |
| 13606 | + | |
| 13607 | + | |
| 13608 | + | |
| 13609 | + | |
| 13610 | + | |
| 13611 | + | |
| 13612 | + | |
| 13613 | + | |
| 13614 | + | |
| 13615 | + | |
| 13616 | + | |
| 13617 | + | |
| 13618 | + | |
| 13619 | + | |
| 13620 | + | |
| 13621 | + | |
| 13622 | + | |
| 13623 | + | |
| 13624 | + | |
| 13625 | + | |
| 13626 | + | |
| 13627 | + | |
| 13628 | + | |
| 13629 | + | |
| 13630 | + | |
| 13631 | + | |
| 13632 | + | |
| 13633 | + | |
| 13634 | + | |
| 13635 | + | |
| 13636 | + | |
| 13637 | + | |
| 13638 | + | |
| 13639 | + | |
| 13640 | + | |
| 13641 | + | |
| 13642 | + | |
| 13643 | + | |
| 13644 | + | |
| 13645 | + | |
| 13646 | + | |
| 13647 | + | |
| 13648 | + | |
| 13649 | + | |
| 13650 | + | |
| 13651 | + | |
| 13652 | + | |
| 13653 | + | |
| 13654 | + | |
| 13655 | + | |
| 13656 | + | |
| 13657 | + | |
| 13658 | + | |
| 13659 | + | |
| 13660 | + | |
| 13661 | + | |
| 13662 | + | |
| 13663 | + | |
| 13664 | + | |
| 13665 | + | |
| 13666 | + | |
| 13667 | + | |
| 13668 | + | |
| 13669 | + | |
| 13670 | + | |
| 13671 | + | |
| 13672 | + | |
| 13673 | + | |
| 13674 | + | |
| 13675 | + | |
| 13676 | + | |
| 13677 | + | |
| 13678 | + | |
| 13679 | + | |
| 13680 | + | |
| 13681 | + | |
| 13682 | + | |
| 13683 | + | |
| 13684 | + | |
| 13685 | + | |
| 13686 | + | |
| 13687 | + | |
| 13688 | + | |
| 13689 | + | |
| 13690 | + | |
| 13691 | + | |
| 13692 | + | |
| 13693 | + | |
| 13694 | + | |
| 13695 | + | |
| 13696 | + | |
| 13697 | + | |
| 13698 | + | |
| 13699 | + | |
| 13700 | + | |
| 13701 | + | |
| 13702 | + | |
| 13703 | + | |
| 13704 | + | |
| 13705 | + | |
| 13706 | + | |
| 13707 | + | |
| 13708 | + | |
| 13709 | + | |
| 13710 | + | |
| 13711 | + | |
| 13712 | + | |
| 13713 | + | |
| 13714 | + | |
| 13715 | + | |
| 13716 | + | |
| 13717 | + | |
| 13718 | + | |
| 13719 | + | |
| 13720 | + | |
| 13721 | + | |
| 13722 | + | |
| 13723 | + | |
| 13724 | + | |
| 13725 | + | |
| 13726 | + | |
| 13727 | + | |
| 13728 | + | |
| 13729 | + | |
| 13730 | + | |
| 13731 | + | |
| 13732 | + | |
| 13733 | + | |
| 13734 | + | |
| 13735 | + | |
| 13736 | + | |
| 13737 | + | |
| 13738 | + | |
| 13739 | + | |
| 13740 | + | |
| 13741 | + | |
| 13742 | + | |
| 13743 | + | |
| 13744 | + | |
| 13745 | + | |
| 13746 | + | |
| 13747 | + | |
| 13748 | + | |
| 13749 | + | |
| 13750 | + | |
| 13751 | + | |
| 13752 | + | |
| 13753 | + | |
| 13754 | + | |
| 13755 | + | |
| 13756 | + | |
| 13757 | + | |
| 13758 | + | |
| 13759 | + | |
| 13760 | + | |
| 13761 | + | |
| 13762 | + | |
| 13763 | + | |
| 13764 | + | |
| 13765 | + | |
| 13766 | + | |
| 13767 | + | |
| 13768 | + | |
| 13769 | + | |
| 13770 | + | |
| 13771 | + | |
| 13772 | + | |
| 13773 | + | |
| 13774 | + | |
| 13775 | + | |
| 13776 | + | |
| 13777 | + | |
| 13778 | + | |
| 13779 | + | |
| 13780 | + | |
| 13781 | + | |
| 13782 | + | |
| 13783 | + | |
| 13784 | + | |
| 13785 | + | |
13567 | 13786 | | |
13568 | 13787 | | |
13569 | 13788 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
106 | 117 | | |
107 | 118 | | |
108 | 119 | | |
| |||
196 | 207 | | |
197 | 208 | | |
198 | 209 | | |
199 | | - | |
200 | | - | |
201 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
202 | 230 | | |
203 | | - | |
| 231 | + | |
204 | 232 | | |
205 | 233 | | |
206 | 234 | | |
207 | 235 | | |
208 | 236 | | |
209 | 237 | | |
210 | 238 | | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
220 | 250 | | |
221 | 251 | | |
222 | 252 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
374 | 374 | | |
375 | 375 | | |
376 | 376 | | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
377 | 384 | | |
378 | 385 | | |
379 | 386 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
315 | 315 | | |
316 | 316 | | |
317 | 317 | | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
318 | 337 | | |
319 | 338 | | |
320 | 339 | | |
| |||
332 | 351 | | |
333 | 352 | | |
334 | 353 | | |
| 354 | + | |
| 355 | + | |
335 | 356 | | |
336 | 357 | | |
337 | 358 | | |
| |||
0 commit comments