Commit a588b26
authored
Fix PruneEmptyTensorsPass crash on data-dependent shapes (pytorch#20809)
### Summary
PruneEmptyTensorsPass crashes during export when cat inputs have
data-dependent shapes (e.g. from conservatively keep the tensor. This is
safe because the pass is purely an optimization; keeping an extra tensor
in cat is a no-op at runtime.
This removes the need for HuggingFace's
_patch_remove_empty_tensors_from_cat monkey-patch in their ExecuTorch
exporter:(https://github.com/huggingface/transformers/blob/main/src/transformers/exporters/exporter_executorch.py#L456-L485).
### Test plan
Existing tests pass: test_empty_tensor_removed_from_cat,
test_cat_removed_all_empty. New test
test_unbacked_symint_numel_does_not_crash exports a model using
torch.nonzero (produces unbacked SymInt shapes) and verifies the pass
completes without crashing
Verified guard_or_true returns True for undecidable expressions and
correct concrete values for decidable ones
python -m pytest exir/tests/test_prune_empty_tensors_pass.py -v1 parent 5f6d1aa commit a588b26
2 files changed
Lines changed: 35 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
38 | | - | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
28 | 39 | | |
29 | 40 | | |
30 | 41 | | |
| |||
77 | 88 | | |
78 | 89 | | |
79 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
0 commit comments