-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[mlir][mesh] adding option for traversal order in sharding propagation #144079
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2fa8004
adding option for traversal order in sharding propagation
fschlimb 6d7d2d3
fixing invalid modification fo use-range while iterating
fschlimb 3f60b3a
code deduplication
fschlimb 6f86add
adding tests for forward and forward-backward sharding propagation
fschlimb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // RUN: mlir-opt --pass-pipeline="builtin.module(func.func(sharding-propagation{traversal=backward}))" %s | FileCheck %s | ||
|
|
||
| #map = affine_map<(d0, d1) -> (d0, d1)> | ||
| module { | ||
| mesh.mesh @mesh(shape = 1) {sym_visibility = "private"} | ||
| func.func @test_forward() -> tensor<6x6xi32> { | ||
| %c1_i32 = arith.constant 1 : i32 | ||
| // CHECK: tensor.empty() | ||
| %0 = tensor.empty() : tensor<6x6xi32> | ||
| %sharding = mesh.sharding @mesh split_axes = [[0]] : !mesh.sharding | ||
| // CHECK-COUNT-2: mesh.shard | ||
| %sharding_annotated = mesh.shard %0 to %sharding : tensor<6x6xi32> | ||
| %1 = linalg.fill ins(%c1_i32 : i32) outs(%sharding_annotated : tensor<6x6xi32>) -> tensor<6x6xi32> | ||
| // CHECK: tensor.empty() | ||
| // CHECK-NOT: mesh.shard @ | ||
| %2 = tensor.empty() : tensor<6x6xi32> | ||
| %3 = linalg.generic {indexing_maps = [#map, #map, #map], iterator_types = ["parallel", "parallel"]} ins(%1, %1 | ||
| : tensor<6x6xi32>, tensor<6x6xi32>) outs(%2 : tensor<6x6xi32>) { | ||
| ^bb0(%in: i32, %in_2: i32, %out: i32): | ||
| %9 = arith.addi %in, %in_2 : i32 | ||
| linalg.yield %9 : i32 | ||
| } -> tensor<6x6xi32> | ||
| // CHECK: return | ||
| return %3 : tensor<6x6xi32> | ||
| } | ||
| } |
27 changes: 27 additions & 0 deletions
27
mlir/test/Dialect/Mesh/forward-backward-sharding-propagation.mlir
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // RUN: mlir-opt --pass-pipeline="builtin.module(func.func(sharding-propagation{traversal=forward-backward}))" %s | FileCheck %s | ||
|
|
||
| #map = affine_map<(d0, d1) -> (d0, d1)> | ||
| module { | ||
| mesh.mesh @mesh(shape = 1) {sym_visibility = "private"} | ||
| func.func @test_forward() -> tensor<6x6xi32> { | ||
| %c1_i32 = arith.constant 1 : i32 | ||
| // CHECK: tensor.empty() | ||
| %0 = tensor.empty() : tensor<6x6xi32> | ||
| // CHECK-COUNT-3: mesh.sharding @mesh split_axes = {{\[\[0}}]] | ||
| %sharding_row = mesh.sharding @mesh split_axes = [[0]] : !mesh.sharding | ||
| %annotated_row = mesh.shard %0 to %sharding_row : tensor<6x6xi32> | ||
| %1 = linalg.fill ins(%c1_i32 : i32) outs(%annotated_row : tensor<6x6xi32>) -> tensor<6x6xi32> | ||
| %2 = tensor.empty() : tensor<6x6xi32> | ||
| // CHECK-COUNT-4: mesh.sharding @mesh split_axes = {{\[\[1}}]] | ||
| %3 = linalg.generic {indexing_maps = [#map, #map, #map], iterator_types = ["parallel", "parallel"]} ins(%2, %1 | ||
| : tensor<6x6xi32>, tensor<6x6xi32>) outs(%2 : tensor<6x6xi32>) { | ||
| ^bb0(%in: i32, %in_2: i32, %out: i32): | ||
| %9 = arith.addi %in, %in_2 : i32 | ||
| linalg.yield %9 : i32 | ||
| } -> tensor<6x6xi32> | ||
| %sharding_col = mesh.sharding @mesh split_axes = [[1]] : !mesh.sharding | ||
| %annotated_col = mesh.shard %3 to %sharding_col : tensor<6x6xi32> | ||
| // CHECK: return | ||
| return %annotated_col : tensor<6x6xi32> | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // RUN: mlir-opt --pass-pipeline="builtin.module(func.func(sharding-propagation{traversal=forward}))" %s | FileCheck %s | ||
|
|
||
| #map = affine_map<(d0, d1) -> (d0, d1)> | ||
| module attributes {dlti.map = #dlti.map<"MPI:Implementation" = "mpich", "MPI:comm_world_rank" = 0 : i32>} { | ||
| mesh.mesh @mesh(shape = 1) {sym_visibility = "private"} | ||
| func.func @test_forward() -> (tensor<6x6xi32>, tensor<6x6xi32>, tensor<i32>) attributes {llvm.emit_c_interface} { | ||
| %c1_i32 = arith.constant 1 : i32 | ||
| // CHECK: [[v3:%.*]] = tensor.empty() : tensor<6x6xi32> | ||
| %0 = tensor.empty() : tensor<6x6xi32> | ||
| // CHECK: [[v1:%.*]] = linalg.fill ins | ||
| // CHECK: [[vsharding_0:%.*]] = mesh.sharding @mesh split_axes = {{\[\[}}0]] : !mesh.sharding | ||
| // CHECK: [[vsharding_annotated_1:%.*]] = mesh.shard [[v1]] to [[vsharding_0]] : tensor<6x6xi32> | ||
| %1 = linalg.fill ins(%c1_i32 : i32) outs(%0 : tensor<6x6xi32>) -> tensor<6x6xi32> | ||
| %sharding = mesh.sharding @mesh split_axes = [[0]] : !mesh.sharding | ||
| %sharding_annotated = mesh.shard %1 to %sharding : tensor<6x6xi32> | ||
| // CHECK: [[v2:%.*]] = tensor.empty() : tensor<6x6xi32> | ||
| // CHECK: [[vsharding_2:%.*]] = mesh.sharding @mesh split_axes = {{\[\[}}0]] : !mesh.sharding | ||
| // CHECK: [[vsharding_annotated_3:%.*]] = mesh.shard [[vsharding_annotated_1]] to [[vsharding_2]] annotate_for_users : tensor<6x6xi32> | ||
| %3 = tensor.empty() : tensor<6x6xi32> | ||
| // CHECK: [[vsharding_4:%.*]] = mesh.sharding @mesh split_axes = {{\[\[}}0]] : !mesh.sharding | ||
| // CHECK: [[vsharding_annotated_5:%.*]] = mesh.shard [[v2]] to [[vsharding_4]] annotate_for_users : tensor<6x6xi32> | ||
| // CHECK: [[v3:%.*]] = linalg.generic {indexing_maps = [#map, #map, #map], iterator_types = ["parallel", "parallel"]} | ||
| // CHECK-SAME: ins([[vsharding_annotated_3]], [[vsharding_annotated_3]] : tensor<6x6xi32>, tensor<6x6xi32>) outs([[vsharding_annotated_5]] : tensor<6x6xi32>) { | ||
| // CHECK: [[vsharding_6:%.*]] = mesh.sharding @mesh split_axes = {{\[\[}}0]] : !mesh.sharding | ||
| // CHECK: [[vsharding_annotated_7:%.*]] = mesh.shard [[v3]] to [[vsharding_6]] : tensor<6x6xi32> | ||
| %4 = linalg.generic {indexing_maps = [#map, #map, #map], iterator_types = ["parallel", "parallel"]} ins(%sharding_annotated, %sharding_annotated | ||
| : tensor<6x6xi32>, tensor<6x6xi32>) outs(%3 : tensor<6x6xi32>) { | ||
| ^bb0(%in: i32, %in_2: i32, %out: i32): | ||
| %9 = arith.addi %in, %in_2 : i32 | ||
| linalg.yield %9 : i32 | ||
| } -> tensor<6x6xi32> | ||
| %c0_i32 = arith.constant 0 : i32 | ||
| %6 = tensor.empty() : tensor<i32> | ||
| %7 = linalg.fill ins(%c0_i32 : i32) outs(%6 : tensor<i32>) -> tensor<i32> | ||
| // CHECK: [[vreduced:%.*]] = linalg.reduce ins | ||
| // CHECK: [[vsharding_12:%.*]] = mesh.sharding @mesh split_axes = [] partial = sum [0] : !mesh.sharding | ||
| // CHECK: [[vsharding_annotated_13:%.*]] = mesh.shard [[vreduced]] to [[vsharding_12]] : tensor<i32> | ||
| %reduced = linalg.reduce ins(%4 : tensor<6x6xi32>) outs(%7 : tensor<i32>) dimensions = [0, 1] | ||
| (%in: i32, %init: i32) { | ||
| %9 = arith.addi %in, %init : i32 | ||
| linalg.yield %9 : i32 | ||
| } | ||
| // CHECK: [[vsharding_14:%.*]] = mesh.sharding @mesh split_axes = {{\[\[}}]] : !mesh.sharding | ||
| %sharding_0 = mesh.sharding @mesh split_axes = [[]] : !mesh.sharding | ||
| // CHECK: [[vsharding_annotated_15:%.*]] = mesh.shard [[vsharding_annotated_13]] to [[vsharding_14]] annotate_for_users : tensor<i32> | ||
| %sharding_annotated_1 = mesh.shard %reduced to %sharding_0 annotate_for_users : tensor<i32> | ||
| return %sharding_annotated, %4, %sharding_annotated_1 : tensor<6x6xi32>, tensor<6x6xi32>, tensor<i32> | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.