Commit 51d594c
committed
mx cleanup [2/x]: refactor mx gemm
Summary:
Refactors the MX gemm emulation code to properly emulate the memory layout
constraints we expect from the future mx-enabled hardware, where we
expect:
* the first argument to the mx gemm to be required row-major memory
format
* the second argument to the mx gemm to be required col-major memory
format
Note that two morally unrelated issues were uncovered with this
refactor:
1. when autocast is on, compile is no longer matching eager numerics.
Since the "before this PR" state isn't really representative of the
world, I'm treating this as a newly uncovered issue, and we can fix
it in a future PR.
2. our transpose logic for fp4 packed into two elements per byte doesn't
work for tensors of shape (M, 1), because we currently rely on the
`is_contiguous()` function to see if our tensor was transposed. We
could work around, but punting that until a time that becomes
important. I expect most tensors in real world usage with MX to not
hit this case.
Test Plan:
```
pytest test/prototype/mx_formats/ -s -x
```
Reviewers:
Subscribers:
Tasks:
Tags:
ghstack-source-id: a828471
ghstack-comment-id: 2605962974
Pull Request resolved: #15931 parent 15dac8d commit 51d594c
File tree
5 files changed
+113
-47
lines changed- test/prototype/mx_formats
- torchao/prototype/mx_formats
5 files changed
+113
-47
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
105 | 113 | | |
106 | 114 | | |
107 | 115 | | |
108 | 116 | | |
109 | 117 | | |
110 | 118 | | |
111 | | - | |
112 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
113 | 122 | | |
114 | | - | |
| 123 | + | |
115 | 124 | | |
116 | 125 | | |
117 | 126 | | |
118 | 127 | | |
119 | | - | |
| 128 | + | |
120 | 129 | | |
121 | 130 | | |
122 | 131 | | |
123 | 132 | | |
124 | 133 | | |
125 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
126 | 139 | | |
127 | 140 | | |
128 | 141 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
170 | | - | |
| 170 | + | |
171 | 171 | | |
| 172 | + | |
172 | 173 | | |
173 | 174 | | |
174 | 175 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
| 8 | + | |
14 | 9 | | |
15 | 10 | | |
| 11 | + | |
| 12 | + | |
16 | 13 | | |
17 | 14 | | |
18 | 15 | | |
19 | 16 | | |
20 | 17 | | |
21 | 18 | | |
22 | 19 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
28 | 26 | | |
29 | 27 | | |
30 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
31 | 36 | | |
32 | 37 | | |
33 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
34 | 49 | | |
35 | 50 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
42 | 69 | | |
43 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
44 | 88 | | |
45 | 89 | | |
46 | 90 | | |
| |||
59 | 103 | | |
60 | 104 | | |
61 | 105 | | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
66 | 117 | | |
67 | 118 | | |
68 | 119 | | |
69 | 120 | | |
70 | 121 | | |
71 | 122 | | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
72 | 126 | | |
73 | 127 | | |
74 | 128 | | |
| |||
84 | 138 | | |
85 | 139 | | |
86 | 140 | | |
87 | | - | |
88 | | - | |
| 141 | + | |
| 142 | + | |
89 | 143 | | |
90 | 144 | | |
91 | 145 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
68 | 71 | | |
69 | 72 | | |
70 | 73 | | |
71 | 74 | | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | 75 | | |
85 | 76 | | |
86 | 77 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
314 | 314 | | |
315 | 315 | | |
316 | 316 | | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
317 | 321 | | |
318 | 322 | | |
319 | 323 | | |
320 | 324 | | |
321 | 325 | | |
322 | 326 | | |
323 | 327 | | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
324 | 331 | | |
325 | 332 | | |
326 | 333 | | |
| |||
0 commit comments