Repository navigation
Validate MXFP8 fused QKV head alignment - #4677
Conversation
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
Extend StackedLinear to fused QKV with weight layout [R, num_kv_heads * head_dim, model_dim], where R = num_query_heads / num_kv_heads + 2. The first R - 2 slices contain the query heads, followed by one slice for all key heads and one for all value heads. ghstack-source-id: 2381544 Pull-Request: #4677
| wqkv=StackedLinear.Config( | ||
| in_features=dim, | ||
| out_features=(n_heads + 2 * n_kv) * per_head_dim, | ||
| out_features=n_kv * per_head_dim, | ||
| num_linears=n_heads // n_kv + 2, |
There was a problem hiding this comment.
Reasoning about the motivation of this change:
TP usually shards on num_heads dimension, so it's different from MLP linears where we need an extra dimension to denote TP.
For quantization, I don't believe it's popular to do quantization on wqkv.
For lora, it's less clear to me. But our earlier argument of lora probably don't care much if they are fused or not anyway.
There was a problem hiding this comment.
One correction: we do quantize wqkv today, but you are right that quantization does not motivate this layout change.
Since q, k, v are stored in interleaved fashion, I thought that they suffer from the same quantization problem as we saw in w13.
But here the layout, even though interleaved, is still ok for quantization.
For heads_per_kv = 4, the old flattened order is:
Q0 Q1 Q2 Q3 K0 V0 | Q4 Q5 Q6 Q7 K1 V1 | ...
where each element (like Q0) is itself head_dim rows. Since head_dim is typically a multiple of 32, we are unlikely to have overlapping regions. This is quite different from w13 where 32 rows had 16 rows of w1 and 16 rows of w3.
That said, there are 2 options
- Still keep the PR because it makes it consistent with w13 linear.
- Remove this PR and just add a check for MxFP8linear that the head_dim is a multiple of 32.
I think both of us prefer the option 2, but looking for opinions.
There was a problem hiding this comment.
yes I prefer option 2 as well -- hoping to keep things as minimal as possible until changes are necessary
Extend StackedLinear to fused QKV with weight layout [R, num_kv_heads * head_dim, model_dim], where R = num_query_heads / num_kv_heads + 2. The first R - 2 slices contain the query heads, followed by one slice for all key heads and one for all value heads. ghstack-source-id: 2381544 Pull-Request: #4677
[ghstack-poisoned]
[ghstack-poisoned]
| "debugmodel": (_debugmodel, 131072), | ||
| # Preserve the debug model's dimensions and QKV GEMM shape, but use | ||
| # 32-wide heads so MXFP8 weight-scale tiles align with head boundaries. | ||
| "debugmodel_mxfp8": (partial(_debugmodel, n_heads=8), 131072), |
There was a problem hiding this comment.
@tianyu-l I had to change the debug model to have head_dim as 32. Otherwise, the assertion was firing. I checked the head_dims of a few OSS models - all of them exceed way beyond 32, so our debug model was not just enough.
I thought of changing the debugmodel but that seems like a big change as we have large number of tests on it.
[ghstack-poisoned]
|
Warning: Unknown label
Please add the new label to .github/pytorch-probot.yml |
|
Warning: Unknown label
Please add the new label to .github/pytorch-probot.yml |
|
Warning: Unknown label
Please add the new label to .github/pytorch-probot.yml |
[ghstack-poisoned]
Require fused QKV head_dim to align with the 32-row MXFP8 weight block so a scale tile cannot span Q, K, or V. Pull-Request: pytorch/torchtitan#4677 ghstack-source-id: c68dc93
Stack from ghstack (oldest at bottom):
Require fused QKV
head_dimto align with the 32-row MXFP8 weight block so a scale tile cannot span Q, K, or V.