Repository navigation
Commit 2d8cd35
authored
XNNPACK: delegate bf16 softmax, computing in fp32 (#24805)
### Summary
Related to #24667. That issue reports that evo1's 24 bf16 softmaxes take
20.0 s of its 35.4 s chunk because their XNNPACK config turns bf16 off,
leaving them on the single-threaded portable kernels. This PR addresses
only that bf16 softmax item, not the other items tracked in that issue.
XNNPACK defines softmax only on fp32 and fp16 tensors, so flipping the
config alone would fail at load. SoftmaxConfig no longer sets
`supports_bf16 = False`, and the runtime now defines fp32 values for
bf16 softmax inputs and outputs and converts between them around the
fp32 softmax, sharing the fp32-value and convert helpers with the bf16
matmul path, so the delegate boundary stays bf16. Each side is converted
only when it is bf16. Without `enable_bf16` the behavior is unchanged,
and fp16 and fp32 softmaxes take the same path as before. The bf16
softmax test and the attention-block partitioner expectation are updated
accordingly.
**Compatibility:** a `.pte` exported with `enable_bf16=True` after this
change delegates bf16 softmax, and fails to load on a runtime built
before it. The serialization format doesn't change, so nothing in the
file flags this. The bf16 matmul change had the same constraint.
This PR was authored with Muse Code.
### Test plan
`lintrunner` on the four changed files is clean. Partitioner probes
confirmed a bf16 softmax delegates with `enable_bf16=True` and stays on
the portable kernels without it, and that the attention block still
splits into 3 delegates with the softmax inside one.
The runtime change was verified with a fresh Release `executor_runner`
build of this branch running exported `.pte` programs: a small bf16
softmax matched eager exactly, a 524288-element bf16 softmax matched to
1.2e-07, a bf16 attention block matched exactly, and fp32 and fp16
softmaxes passed. These cases were rerun after the helper refactor with
the same results. On the large bf16 shape, 500 executions took about
0.13 s delegated versus about 1.54 s on the portable kernels on the same
binary and inputs.
The new `Tester`-based bf16 softmax test and the partitioner
load-and-compare test were not run locally: this machine's installed
Python runtime is an older build that cannot load programs exported from
this branch, and an isolated rebuild was blocked by the repository's
requirement that the checkout directory be named exactly `executorch`.
Those tests need CI.1 parent 9fffe15 commit 2d8cd35
4 files changed
Lines changed: 129 additions & 57 deletions
File tree
- backends/xnnpack
- partition/config
- runtime
- test
- ops
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
408 | 408 | | |
409 | 409 | | |
410 | 410 | | |
411 | | - | |
412 | 411 | | |
413 | 412 | | |
414 | 413 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
819 | 819 | | |
820 | 820 | | |
821 | 821 | | |
822 | | - | |
823 | | - | |
824 | | - | |
825 | | - | |
826 | | - | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
827 | 825 | | |
828 | | - | |
| 826 | + | |
829 | 827 | | |
830 | | - | |
831 | | - | |
832 | | - | |
833 | | - | |
834 | | - | |
| 828 | + | |
835 | 829 | | |
836 | | - | |
837 | | - | |
838 | | - | |
839 | | - | |
840 | | - | |
841 | | - | |
842 | | - | |
843 | | - | |
844 | | - | |
845 | | - | |
846 | | - | |
| 830 | + | |
847 | 831 | | |
848 | 832 | | |
849 | | - | |
850 | | - | |
| 833 | + | |
| 834 | + | |
851 | 835 | | |
852 | 836 | | |
853 | 837 | | |
| |||
857 | 841 | | |
858 | 842 | | |
859 | 843 | | |
860 | | - | |
| 844 | + | |
861 | 845 | | |
862 | 846 | | |
863 | 847 | | |
864 | | - | |
| 848 | + | |
865 | 849 | | |
866 | 850 | | |
867 | 851 | | |
868 | 852 | | |
869 | 853 | | |
870 | | - | |
871 | | - | |
872 | | - | |
873 | | - | |
874 | | - | |
| 854 | + | |
875 | 855 | | |
876 | | - | |
877 | | - | |
| 856 | + | |
| 857 | + | |
878 | 858 | | |
879 | | - | |
| 859 | + | |
880 | 860 | | |
881 | 861 | | |
882 | | - | |
883 | | - | |
| 862 | + | |
| 863 | + | |
884 | 864 | | |
885 | 865 | | |
886 | 866 | | |
887 | | - | |
| 867 | + | |
888 | 868 | | |
889 | 869 | | |
890 | 870 | | |
891 | 871 | | |
892 | 872 | | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
893 | 901 | | |
894 | 902 | | |
895 | 903 | | |
| |||
934 | 942 | | |
935 | 943 | | |
936 | 944 | | |
937 | | - | |
| 945 | + | |
938 | 946 | | |
939 | 947 | | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
940 | 968 | | |
941 | 969 | | |
942 | 970 | | |
| |||
947 | 975 | | |
948 | 976 | | |
949 | 977 | | |
950 | | - | |
951 | | - | |
952 | 978 | | |
953 | 979 | | |
954 | 980 | | |
955 | 981 | | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
956 | 1002 | | |
957 | | - | |
| 1003 | + | |
958 | 1004 | | |
959 | 1005 | | |
960 | 1006 | | |
961 | 1007 | | |
962 | 1008 | | |
963 | 1009 | | |
964 | 1010 | | |
965 | | - | |
| 1011 | + | |
966 | 1012 | | |
967 | 1013 | | |
968 | 1014 | | |
| |||
1793 | 1839 | | |
1794 | 1840 | | |
1795 | 1841 | | |
1796 | | - | |
| 1842 | + | |
1797 | 1843 | | |
1798 | 1844 | | |
1799 | 1845 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| |||
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
25 | | - | |
| 27 | + | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
| |||
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
35 | 41 | | |
36 | | - | |
| 42 | + | |
37 | 43 | | |
38 | 44 | | |
39 | 45 | | |
40 | | - | |
41 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
42 | 59 | | |
43 | 60 | | |
44 | 61 | | |
45 | | - | |
| 62 | + | |
46 | 63 | | |
47 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
48 | 79 | | |
49 | 80 | | |
50 | 81 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | 185 | | |
190 | 186 | | |
191 | 187 | | |
| |||
200 | 196 | | |
201 | 197 | | |
202 | 198 | | |
203 | | - | |
204 | 199 | | |
205 | 200 | | |
206 | 201 | | |
| |||
270 | 265 | | |
271 | 266 | | |
272 | 267 | | |
273 | | - | |
274 | | - | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
275 | 271 | | |
276 | 272 | | |
277 | 273 | | |
| |||
294 | 290 | | |
295 | 291 | | |
296 | 292 | | |
297 | | - | |
| 293 | + | |
298 | 294 | | |
299 | 295 | | |
300 | 296 | | |
| |||
0 commit comments