ColossalAI
ColossalAI copied to clipboard
[DTensor] implement layout converter
📌 Checklist before creating the PR
- [x] I have created an issue for this PR for traceability
- [x] The title follows the standard format:
[doc/gemini/tensor/...]: A concise description
- [x] I have added relevant tags if possible for us to better distinguish different PRs
🚨 Issue number
#3067
📝 What does this PR do?
LayoutConverter mainly has three main functions:
- Search an efficient transform path for the given pair of source_layout and target_layout.
- Estimate the converting cost for the given pair of source_layout and target_layout.
- Apply the layout converting path to redistribute a tensor from source_layout to target_layout.
To search the transform path, we use a heuristic algorithm which could be simplily describe as:
- Step1: Generate all one-step transform sequences from source_layout.
- Step2: Pick the 'best' layout following the heuristic function.
- Step3: Repeat above steps until the source layout transform to target layout.
To estimate the total converting cost, we implement a method to estimate the communication cost of each communication operation under the instruction of CommSpec. Then, we just need sum the costs of CommSpec in the transform_sequence up to get the total converting cost.
💥 Checklist before requesting a review
- [x] I have linked my PR to an issue (instruction)
- [x] My issue clearly describes the problem/feature/proposal, with diagrams/charts/table/code if possible
- [x] I have performed a self-review of my code
- [x] I have added thorough tests.
- [x] I have added docstrings for all the functions/methods I implemented
⭐️ Do you enjoy contributing to Colossal-AI?
- [x] 🌝 Yes, I do.
- [ ] 🌚 No, I don't.
Tell us more if you don't enjoy contributing to Colossal-AI.
The code coverage for the changed files is %.
Click me to view the complete report
Name Stmts Miss Cover
-----------------------------------------------------------------------------
colossalai/tensor/d_tensor/layout_converter.py 200 24 88%
colossalai/tensor/d_tensor/utils.py 38 7 82%
tests/test_tensor/test_dtensor/test_layout_converter.py 97 1 99%
-----------------------------------------------------------------------------
TOTAL 335 32 90%
Looks good to me.