Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions third_party/xla/xla/service/spmd/spmd_partitioner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2758,6 +2758,14 @@ absl::Status SpmdPartitioningVisitor::HandleElementwise(HloInstruction* hlo) {
return absl::OkStatus();
}

absl::Status SpmdPartitioningVisitor::HandleCollectivePermute(
HloInstruction* hlo) {
if (hlo->channel_id()) {
return HandleElementwise(hlo);
}
return DefaultAction(hlo);
}

absl::Status SpmdPartitioningVisitor::HandleElementwiseWithDimsToReplicate(
HloInstruction* hlo, absl::Span<const int64_t> dims_to_replicate) {
const HloSharding& sharding = hlo->sharding();
Expand Down
1 change: 1 addition & 0 deletions third_party/xla/xla/service/spmd/spmd_partitioner.h
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ class SpmdPartitioningVisitor : public DfsHloVisitorWithDefault {
absl::Status HandleBroadcast(HloInstruction* hlo) override;
absl::Status HandleCall(HloInstruction* hlo) override;
absl::Status HandleCholesky(HloInstruction* hlo) override;
absl::Status HandleCollectivePermute(HloInstruction* hlo) override;
absl::Status HandleConcatenate(HloInstruction* hlo) override;
absl::Status HandleConditional(HloInstruction* hlo) override;
absl::Status HandleConstant(HloInstruction* hlo) override;
Expand Down
24 changes: 24 additions & 0 deletions third_party/xla/xla/service/spmd/spmd_partitioner_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15541,6 +15541,30 @@ ENTRY main {
AllOf(op::DynamicSlice(ts, _, _, _), op::Shape("f32[5,16,24]")));
}

TEST_P(SpmdPartitioningTest, PartitionCollectivePermute) {
absl::string_view hlo_string = R"(
HloModule jit_f, entry_computation_layout={(s32[8]{0})->s32[8]{0}}, allow_spmd_sharding_propagation_to_output={true}, num_partitions=8

ENTRY main.12 {
Arg_0.1 = s32[8]{0} parameter(0), sharding={devices=[8]<=[8]}, metadata={op_name="x"}
copy.2 = s32[8]{0} copy(Arg_0.1), sharding={devices=[4,2]<=[8] last_tile_dim_replicate}
custom-call.3 = s32[2]{0} custom-call(copy.2), custom_call_target="SPMDFullToShardShape", sharding={devices=[1,4,2]<=[8] last_tile_dims={manual, replicated}}, backend_config="unspecified_dims=[0]"
copy.1 = s32[2]{0} copy(custom-call.3), sharding={devices=[2,4]<=[4,2]T(1,0) last_tile_dims={manual}}
multiply.0 = s32[2]{0} multiply(copy.1, copy.1), sharding={devices=[2,4]<=[4,2]T(1,0) last_tile_dims={manual}}
collective-permute.0 = s32[2]{0} collective-permute(multiply.0), channel_id=1, source_target_pairs={{0,6},{2,0},{4,2},{6,4},{1,7},{3,1},{5,3},{7,5}}, sharding={devices=[2,4]<=[4,2]T(1,0) last_tile_dims={manual}}
ROOT custom-call.11 = s32[8]{0} custom-call(collective-permute.0), custom_call_target="SPMDShardToFullShape", sharding={devices=[8]<=[8]}, backend_config="unspecified_dims=[0]"
})";

TF_ASSERT_OK_AND_ASSIGN(auto module,
PartitionComputation(hlo_string, /*num_devices=*/8));
VLOG(1) << module->ToString();

// Check the collective permute instruction is partitioned.
auto cp = FindInstruction(module.get(), HloOpcode::kCollectivePermute);
EXPECT_NE(cp, nullptr);
EXPECT_THAT(cp, op::Shape("s32[1]{0}"));
}

} // namespace
} // namespace spmd
} // namespace xla
Loading