| 40 | } |
| 41 | |
| 42 | HloSharding HloSharding::Tuple(const ShapeTree<HloSharding>& sub_shardings) { |
| 43 | std::vector<HloSharding> flattened_list; |
| 44 | flattened_list.reserve(sub_shardings.leaf_count()); |
| 45 | for (const auto& index_to_sharding : sub_shardings.leaves()) { |
| 46 | flattened_list.push_back(index_to_sharding.second); |
| 47 | } |
| 48 | if (flattened_list.empty()) { |
| 49 | // Empty tuple sharding ends up having no leaves, but we want to allow |
| 50 | // empty tuple HLO instruction results to have sharding, so we fetch the |
| 51 | // root ({}) sharding value from the ShapeTree. |
| 52 | // A ShapeTree created with ShapeTree<HloSharding>(shape, init) will have |
| 53 | // init as value at its root. |
| 54 | flattened_list.push_back(sub_shardings.element(ShapeIndex({}))); |
| 55 | } |
| 56 | return HloSharding(flattened_list); |
| 57 | } |
| 58 | |
| 59 | HloSharding HloSharding::Tuple(const Shape& tuple_shape, |
| 60 | absl::Span<const HloSharding> shardings) { |
nothing calls this directly
no test coverage detected