ColossalAI icon indicating copy to clipboard operation
ColossalAI copied to clipboard

[DTensor] implement layout converter

Open YuliangLiu0306 opened this issue 1 year ago • 1 comments

📌 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:

  1. Search an efficient transform path for the given pair of source_layout and target_layout.
  2. Estimate the converting cost for the given pair of source_layout and target_layout.
  3. 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.

YuliangLiu0306 avatar Mar 08 '23 07:03 YuliangLiu0306

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%

github-actions[bot] avatar Mar 09 '23 06:03 github-actions[bot]

Looks good to me.

FrankLeeeee avatar Mar 10 '23 01:03 FrankLeeeee