Commit 021970c
committed
Fix the seq-first Ulysses all2all output layout
_generate_layout_params builds the reshape target for every all2all in
DistributedAttention. For batch_dim_idx=1 (s, b, n, h) with scatter_idx < 2 it
returns [bs, seq_world_size * global_seq_len, num_local_head // seq_world_size,
head_dim], which is the batch_dim_idx=0 / scatter_idx >= 2 shape: it puts the
batch first, multiplies the sequence and divides the heads, when this direction
scatters the sequence and gathers the heads.
Before #6750 extracted this function, post_all2all computed
[seq_len // seq_world_size, bs, seq_world_size * num_head, head_dim] for that
case, so the refactor copied the wrong sibling branch. Restore that shape.
The element count still matches whenever num_local_head is divisible by
seq_world_size, so the reshape succeeds and silently returns a transposed,
mis-strided tensor; when it is not divisible, the floor division makes a
dimension 0 and the reshape raises. Both are reachable from
DistributedAttention, whose default gather_idx is 0: the output projection
all2all and the backward of the q/k/v all2alls both run scatter_idx < 2.
The existing coverage misses it. TestUlyssesAll2All only runs batch_dim_idx=0,
and TestUlyssesAll2All_odd sets num_kv_heads on its first call so every later
call takes uneven_heads_all2all instead of _generate_layout_params.
_generate_layout_params is pure, so add TestUlyssesAll2AllLayout, which drives
it with an emulated all_to_all_single and checks that both directions land the
right (sequence, head) shard of a known tensor. It needs no process group and
no accelerator, so it runs in the CPU CI. Against the current code the two
batch_dim_idx=1 head-to-sequence cases fail (2 failed, 6 passed: one shape
assertion, one reshape RuntimeError) and all 8 pass with the fix.1 parent 7154a00 commit 021970c
2 files changed
Lines changed: 61 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
54 | 56 | | |
55 | 57 | | |
56 | 58 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
151 | 208 | | |
152 | 209 | | |
153 | 210 | | |
| |||
0 commit comments