Loading: convert transposed and RoPE-permuted weights before taking the DTensor shard - #48519
Loading: convert transposed and RoPE-permuted weights before taking the DTensor shard#48519qgallouedec wants to merge 3 commits into
Conversation
…ing the DTensor shard
…hen one of them is sharded
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
CI recapDashboard: View test results in Grafana |
|
cc @3outeille could you take a first look here? |
vasqu
left a comment
There was a problem hiding this comment.
Just one initial design question but letting Ferdinand comment first on the logic
| return True | ||
| if isinstance(op, PermuteForRope) and 0 in shard_dims: | ||
| return True | ||
| return False |
There was a problem hiding this comment.
Wondering whether we might move this as general function within converter/renaming and override where we need it
Would make it easier to scale tbh
There was a problem hiding this comment.
Yes I wasn't sure. I went for simplicity instead of generality as a first step, but happy to generalize
There was a problem hiding this comment.
I just fear the function exploding at some point 😢 and it makes custom extensions simpler
When a parameter is loaded as a DTensor (
tp_plan, or FSDP2 at load time), the loader slices the checkpoint tensor to this rank's shard first and runs the conversion ops on the slice.TransposeandPermuteForRopemove elements across dims, so when the sharded dim is one they touch, the shard of the source is not the shard of the converted tensor:Transpose: a router stored as(hidden, experts), sharded on dim 0 over 2 ranks, comes out as(experts, hidden/2)against a(experts/2, hidden)shard. Loud: mismatched-keys error.PermuteForRope: takes the head size fromtensor.shape[0], i.e. from the shard. Silent: q/k permuted with the wrong head size, no error.Repro (Kimi K2.5 vision q/k go through
PermuteForRope; needs FSDP2 at load, #48205):First:
Before (no error raised):
After:
Fix:
shards_after_conversionsays whether a converter has one of these ops on a sharded dim;DtensorShardOperation.Everything else keeps shard-on-read (fused experts, and transposes on unsharded dims such as Qwen3-VL-MoE's)