Commit 2881e55
committed
Fix ModelParallel layout map axis order for Phi3 QKV kernels
Phi3's query/key/value kernels are shaped (hidden, heads, head_dim),
with hidden as the contracting dim and heads as the output dim --
the opposite axis order from Gemma's (heads, hidden, head_dim)
kernels. The layout map had the data/model axes swapped for these
kernels (and for token_embedding/reverse_embeddings), which put the
small, GQA-sized key/value heads axis on the model-parallel dim
instead of hidden, and the large hidden axis on the batch axis
instead of the smaller heads axis for query -- both backwards from
the intended Megatron-style column-parallel sharding, and prone to
IndivisibleError whenever the model-mesh dimension didn't evenly
divide the (typically much smaller) key/value head count.
Corrected the axis order so heads land on the model-parallel dim
(matching attention_output.kernel's existing convention) and hidden
lands on the data-parallel dim, with key/value heads left fully
replicated on the model dim regardless of divisibility (mirrors
Gemma's kv convention).
Also expands phi3_backbone_test.py with a mesh-shape sweep across
this repo's capped device-mesh shapes, covering both the real
"mini" (1:1 query:kv head ratio) and a synthetic GQA-ratio width
class, plus a live-preset sweep that fetches real config.json files
from every registered Phi3 preset and validates the layout map
against their actual dims (skipping any build whose estimated
memory footprint would be unsafe to run locally).1 parent 8375767 commit 2881e55
2 files changed
Lines changed: 442 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
0 commit comments