Skip to content

Commit 2800111

Browse files
Michael Levesque-Diontensorflower-gardener
authored andcommitted
Revert TrivialDce pass
The need for this was due to a bug in MLIR's GreedyPatternRewriteDriver (llvm/llvm-project#86765) which has been fixed (llvm/llvm-project#86990), so the TrivialDce pass is no longer needed. Reverts 04b31c7 PiperOrigin-RevId: 621959286
1 parent dcc58f9 commit 2800111

24 files changed

+157
-329
lines changed

tensorflow/lite/kernels/lstm_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,7 @@ TEST_P(LstmOpTest, Cifg_Peephole_Projection_LayerNorm) {
13041304

13051305
static const auto* tolerance_per_type =
13061306
new std::map<TensorType, float>{{TensorType_FLOAT32, 0.00001f},
1307-
{TensorType_UINT8, 0.000971057f},
1307+
{TensorType_UINT8, 0.001f},
13081308
{TensorType_INT8, 0.001f}};
13091309
VerifyGoldens(&lstm, tolerance_per_type->at(weight_type));
13101310
}

third_party/stablehlo/temporary.patch

Lines changed: 3 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ diff --ruN a/stablehlo/stablehlo/CMakeLists.txt b/stablehlo/stablehlo/CMakeLists
177177
diff --ruN a/stablehlo/stablehlo/experimental/BUILD.bazel b/stablehlo/stablehlo/experimental/BUILD.bazel
178178
--- stablehlo/stablehlo/experimental/BUILD.bazel
179179
+++ stablehlo/stablehlo/experimental/BUILD.bazel
180-
@@ -0,0 +1,116 @@
180+
@@ -0,0 +1,115 @@
181181
+# Copyright 2023 The StableHLO Authors. All Rights Reserved.
182182
+#
183183
+# Licensed under the Apache License, Version 2.0 (the "License");
@@ -251,7 +251,6 @@ diff --ruN a/stablehlo/stablehlo/experimental/BUILD.bazel b/stablehlo/stablehlo/
251251
+ "transforms/ChloRecomposeOps.cpp",
252252
+ "transforms/StablehloCanonicalizeDynamism.cpp",
253253
+ "transforms/StablehloRefineShapes.cpp",
254-
+ "transforms/StablehloTrivialDce.cpp",
255254
+ ],
256255
+ hdrs = [
257256
+ "transforms/Passes.h",
@@ -1904,7 +1903,7 @@ diff --ruN a/stablehlo/stablehlo/experimental/tools/StablehloOptMain.cpp b/stabl
19041903
diff --ruN a/stablehlo/stablehlo/experimental/transforms/CMakeLists.txt b/stablehlo/stablehlo/experimental/transforms/CMakeLists.txt
19051904
--- stablehlo/stablehlo/experimental/transforms/CMakeLists.txt
19061905
+++ stablehlo/stablehlo/experimental/transforms/CMakeLists.txt
1907-
@@ -0,0 +1,41 @@
1906+
@@ -0,0 +1,40 @@
19081907
+# Copyright 2023 The StableHLO Authors.
19091908
+#
19101909
+# Licensed under the Apache License, Version 2.0 (the "License");
@@ -1928,7 +1927,6 @@ diff --ruN a/stablehlo/stablehlo/experimental/transforms/CMakeLists.txt b/stable
19281927
+ ChloRecomposeOps.cpp
19291928
+ StablehloCanonicalizeDynamism.cpp
19301929
+ StablehloRefineShapes.cpp
1931-
+ StablehloTrivialDce.cpp
19321930
+
19331931
+ DEPENDS
19341932
+ ExperimentalPassesIncGen
@@ -2173,7 +2171,7 @@ diff --ruN a/stablehlo/stablehlo/experimental/transforms/Passes.h b/stablehlo/st
21732171
diff --ruN a/stablehlo/stablehlo/experimental/transforms/Passes.td b/stablehlo/stablehlo/experimental/transforms/Passes.td
21742172
--- stablehlo/stablehlo/experimental/transforms/Passes.td
21752173
+++ stablehlo/stablehlo/experimental/transforms/Passes.td
2176-
@@ -0,0 +1,55 @@
2174+
@@ -0,0 +1,39 @@
21772175
+/* Copyright 2023 The StableHLO Authors.
21782176
+
21792177
+Licensed under the Apache License, Version 2.0 (the "License");
@@ -2213,22 +2211,6 @@ diff --ruN a/stablehlo/stablehlo/experimental/transforms/Passes.td b/stablehlo/s
22132211
+ }];
22142212
+ let dependentDialects = ["chlo::ChloDialect"];
22152213
+}
2216-
+
2217-
+def StablehloTrivialDcePass : Pass<"experimental-stablehlo-trivial-dce", "ModuleOp"> {
2218-
+ let summary = "(Experimental) Performs a single bottom up pass to remove values that are trivially dead.";
2219-
+ let description = [{
2220-
+ An experimental pass to remove dead values prior to running other passes
2221-
+ that may fail to converge otherwise. For example, running shape refinement
2222-
+ on a program that has a lot of dead values can fail because shape refinement
2223-
+ is top down and removing values causes a new iteration to be triggered, and
2224-
+ removing all the dead values with a top down traversal can take a lot of
2225-
+ iterations (10+), which is slow.
2226-
+
2227-
+ Performing a single pass should be fast, and doing it bottom up means that
2228-
+ values that are transitively dead can be removed since leaf values will be
2229-
+ processed first.
2230-
+ }];
2231-
+}
22322214
diff --ruN a/stablehlo/stablehlo/experimental/transforms/StablehloCanonicalizeDynamism.cpp b/stablehlo/stablehlo/experimental/transforms/StablehloCanonicalizeDynamism.cpp
22332215
--- stablehlo/stablehlo/experimental/transforms/StablehloCanonicalizeDynamism.cpp
22342216
+++ stablehlo/stablehlo/experimental/transforms/StablehloCanonicalizeDynamism.cpp
@@ -2578,73 +2560,6 @@ diff --ruN a/stablehlo/stablehlo/experimental/transforms/StablehloRefineShapes.c
25782560
+} // namespace experimental
25792561
+} // namespace stablehlo
25802562
+} // namespace mlir
2581-
diff --ruN a/stablehlo/stablehlo/experimental/transforms/StablehloTrivialDce.cpp b/stablehlo/stablehlo/experimental/transforms/StablehloTrivialDce.cpp
2582-
--- stablehlo/stablehlo/experimental/transforms/StablehloTrivialDce.cpp
2583-
+++ stablehlo/stablehlo/experimental/transforms/StablehloTrivialDce.cpp
2584-
@@ -0,0 +1,63 @@
2585-
+/* Copyright 2022 The StableHLO Authors.
2586-
+Licensed under the Apache License, Version 2.0 (the "License");
2587-
+you may not use this file except in compliance with the License.
2588-
+You may obtain a copy of the License at
2589-
+
2590-
+ http://www.apache.org/licenses/LICENSE-2.0
2591-
+
2592-
+Unless required by applicable law or agreed to in writing, software
2593-
+distributed under the License is distributed on an "AS IS" BASIS,
2594-
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2595-
+See the License for the specific language governing permissions and
2596-
+limitations under the License.
2597-
+==============================================================================*/
2598-
+
2599-
+#include <cstdint>
2600-
+
2601-
+#include "llvm/ADT/SmallVector.h"
2602-
+#include "mlir/Dialect/Func/IR/FuncOps.h"
2603-
+#include "mlir/IR/PatternMatch.h"
2604-
+#include "mlir/Support/LogicalResult.h"
2605-
+#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
2606-
+#include "stablehlo/experimental/transforms/Passes.h"
2607-
+
2608-
+namespace mlir {
2609-
+namespace stablehlo {
2610-
+namespace experimental {
2611-
+
2612-
+#define GEN_PASS_DEF_STABLEHLOTRIVIALDCEPASS
2613-
+#include "stablehlo/experimental/transforms/Passes.h.inc"
2614-
+
2615-
+namespace {
2616-
+
2617-
+struct StablehloTrivialDcePass
2618-
+ : public impl::StablehloTrivialDcePassBase<StablehloTrivialDcePass> {
2619-
+ using StablehloTrivialDcePassBase::StablehloTrivialDcePassBase;
2620-
+
2621-
+ void runOnOperation() override {
2622-
+ GreedyRewriteConfig config;
2623-
+
2624-
+ // Hardcode defaults for stability.
2625-
+ config.enableRegionSimplification = true;
2626-
+ config.maxNumRewrites = GreedyRewriteConfig::kNoLimit;
2627-
+ config.strictMode = GreedyRewriteStrictness::AnyOp;
2628-
+
2629-
+ // Run a single bottom up pass.
2630-
+ config.useTopDownTraversal = false;
2631-
+ config.maxIterations = 1;
2632-
+
2633-
+ // Running a greedy rewrite will cause trivially dead values to be removed.
2634-
+ // Doing it without patterns ensures that no other changes are made to the
2635-
+ // IR. Doing it bottom-up ensures that values that are transitively dead are
2636-
+ // also removed. Although 1 pass should be enough,
2637-
+ // applyPatternsAndFoldGreedily will want to run at least 1 more iteration
2638-
+ // to confirm convergence, but we don't need to check for convergence, so we
2639-
+ // ignore the return value.
2640-
+ (void)applyPatternsAndFoldGreedily(getOperation(), RewritePatternSet(&getContext()), config);
2641-
+ }
2642-
+};
2643-
+
2644-
+} // namespace
2645-
+} // namespace experimental
2646-
+} // namespace stablehlo
2647-
+} // namespace mlir
26482563
diff --ruN a/stablehlo/stablehlo/tests/chlo/chlo_legalize_to_stablehlo.mlir b/stablehlo/stablehlo/tests/chlo/chlo_legalize_to_stablehlo.mlir
26492564
--- stablehlo/stablehlo/tests/chlo/chlo_legalize_to_stablehlo.mlir
26502565
+++ stablehlo/stablehlo/tests/chlo/chlo_legalize_to_stablehlo.mlir

third_party/xla/third_party/stablehlo/temporary.patch

Lines changed: 3 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ diff --ruN a/stablehlo/stablehlo/CMakeLists.txt b/stablehlo/stablehlo/CMakeLists
177177
diff --ruN a/stablehlo/stablehlo/experimental/BUILD.bazel b/stablehlo/stablehlo/experimental/BUILD.bazel
178178
--- stablehlo/stablehlo/experimental/BUILD.bazel
179179
+++ stablehlo/stablehlo/experimental/BUILD.bazel
180-
@@ -0,0 +1,116 @@
180+
@@ -0,0 +1,115 @@
181181
+# Copyright 2023 The StableHLO Authors. All Rights Reserved.
182182
+#
183183
+# Licensed under the Apache License, Version 2.0 (the "License");
@@ -251,7 +251,6 @@ diff --ruN a/stablehlo/stablehlo/experimental/BUILD.bazel b/stablehlo/stablehlo/
251251
+ "transforms/ChloRecomposeOps.cpp",
252252
+ "transforms/StablehloCanonicalizeDynamism.cpp",
253253
+ "transforms/StablehloRefineShapes.cpp",
254-
+ "transforms/StablehloTrivialDce.cpp",
255254
+ ],
256255
+ hdrs = [
257256
+ "transforms/Passes.h",
@@ -1904,7 +1903,7 @@ diff --ruN a/stablehlo/stablehlo/experimental/tools/StablehloOptMain.cpp b/stabl
19041903
diff --ruN a/stablehlo/stablehlo/experimental/transforms/CMakeLists.txt b/stablehlo/stablehlo/experimental/transforms/CMakeLists.txt
19051904
--- stablehlo/stablehlo/experimental/transforms/CMakeLists.txt
19061905
+++ stablehlo/stablehlo/experimental/transforms/CMakeLists.txt
1907-
@@ -0,0 +1,41 @@
1906+
@@ -0,0 +1,40 @@
19081907
+# Copyright 2023 The StableHLO Authors.
19091908
+#
19101909
+# Licensed under the Apache License, Version 2.0 (the "License");
@@ -1928,7 +1927,6 @@ diff --ruN a/stablehlo/stablehlo/experimental/transforms/CMakeLists.txt b/stable
19281927
+ ChloRecomposeOps.cpp
19291928
+ StablehloCanonicalizeDynamism.cpp
19301929
+ StablehloRefineShapes.cpp
1931-
+ StablehloTrivialDce.cpp
19321930
+
19331931
+ DEPENDS
19341932
+ ExperimentalPassesIncGen
@@ -2173,7 +2171,7 @@ diff --ruN a/stablehlo/stablehlo/experimental/transforms/Passes.h b/stablehlo/st
21732171
diff --ruN a/stablehlo/stablehlo/experimental/transforms/Passes.td b/stablehlo/stablehlo/experimental/transforms/Passes.td
21742172
--- stablehlo/stablehlo/experimental/transforms/Passes.td
21752173
+++ stablehlo/stablehlo/experimental/transforms/Passes.td
2176-
@@ -0,0 +1,55 @@
2174+
@@ -0,0 +1,39 @@
21772175
+/* Copyright 2023 The StableHLO Authors.
21782176
+
21792177
+Licensed under the Apache License, Version 2.0 (the "License");
@@ -2213,22 +2211,6 @@ diff --ruN a/stablehlo/stablehlo/experimental/transforms/Passes.td b/stablehlo/s
22132211
+ }];
22142212
+ let dependentDialects = ["chlo::ChloDialect"];
22152213
+}
2216-
+
2217-
+def StablehloTrivialDcePass : Pass<"experimental-stablehlo-trivial-dce", "ModuleOp"> {
2218-
+ let summary = "(Experimental) Performs a single bottom up pass to remove values that are trivially dead.";
2219-
+ let description = [{
2220-
+ An experimental pass to remove dead values prior to running other passes
2221-
+ that may fail to converge otherwise. For example, running shape refinement
2222-
+ on a program that has a lot of dead values can fail because shape refinement
2223-
+ is top down and removing values causes a new iteration to be triggered, and
2224-
+ removing all the dead values with a top down traversal can take a lot of
2225-
+ iterations (10+), which is slow.
2226-
+
2227-
+ Performing a single pass should be fast, and doing it bottom up means that
2228-
+ values that are transitively dead can be removed since leaf values will be
2229-
+ processed first.
2230-
+ }];
2231-
+}
22322214
diff --ruN a/stablehlo/stablehlo/experimental/transforms/StablehloCanonicalizeDynamism.cpp b/stablehlo/stablehlo/experimental/transforms/StablehloCanonicalizeDynamism.cpp
22332215
--- stablehlo/stablehlo/experimental/transforms/StablehloCanonicalizeDynamism.cpp
22342216
+++ stablehlo/stablehlo/experimental/transforms/StablehloCanonicalizeDynamism.cpp
@@ -2578,73 +2560,6 @@ diff --ruN a/stablehlo/stablehlo/experimental/transforms/StablehloRefineShapes.c
25782560
+} // namespace experimental
25792561
+} // namespace stablehlo
25802562
+} // namespace mlir
2581-
diff --ruN a/stablehlo/stablehlo/experimental/transforms/StablehloTrivialDce.cpp b/stablehlo/stablehlo/experimental/transforms/StablehloTrivialDce.cpp
2582-
--- stablehlo/stablehlo/experimental/transforms/StablehloTrivialDce.cpp
2583-
+++ stablehlo/stablehlo/experimental/transforms/StablehloTrivialDce.cpp
2584-
@@ -0,0 +1,63 @@
2585-
+/* Copyright 2022 The StableHLO Authors.
2586-
+Licensed under the Apache License, Version 2.0 (the "License");
2587-
+you may not use this file except in compliance with the License.
2588-
+You may obtain a copy of the License at
2589-
+
2590-
+ http://www.apache.org/licenses/LICENSE-2.0
2591-
+
2592-
+Unless required by applicable law or agreed to in writing, software
2593-
+distributed under the License is distributed on an "AS IS" BASIS,
2594-
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2595-
+See the License for the specific language governing permissions and
2596-
+limitations under the License.
2597-
+==============================================================================*/
2598-
+
2599-
+#include <cstdint>
2600-
+
2601-
+#include "llvm/ADT/SmallVector.h"
2602-
+#include "mlir/Dialect/Func/IR/FuncOps.h"
2603-
+#include "mlir/IR/PatternMatch.h"
2604-
+#include "mlir/Support/LogicalResult.h"
2605-
+#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
2606-
+#include "stablehlo/experimental/transforms/Passes.h"
2607-
+
2608-
+namespace mlir {
2609-
+namespace stablehlo {
2610-
+namespace experimental {
2611-
+
2612-
+#define GEN_PASS_DEF_STABLEHLOTRIVIALDCEPASS
2613-
+#include "stablehlo/experimental/transforms/Passes.h.inc"
2614-
+
2615-
+namespace {
2616-
+
2617-
+struct StablehloTrivialDcePass
2618-
+ : public impl::StablehloTrivialDcePassBase<StablehloTrivialDcePass> {
2619-
+ using StablehloTrivialDcePassBase::StablehloTrivialDcePassBase;
2620-
+
2621-
+ void runOnOperation() override {
2622-
+ GreedyRewriteConfig config;
2623-
+
2624-
+ // Hardcode defaults for stability.
2625-
+ config.enableRegionSimplification = true;
2626-
+ config.maxNumRewrites = GreedyRewriteConfig::kNoLimit;
2627-
+ config.strictMode = GreedyRewriteStrictness::AnyOp;
2628-
+
2629-
+ // Run a single bottom up pass.
2630-
+ config.useTopDownTraversal = false;
2631-
+ config.maxIterations = 1;
2632-
+
2633-
+ // Running a greedy rewrite will cause trivially dead values to be removed.
2634-
+ // Doing it without patterns ensures that no other changes are made to the
2635-
+ // IR. Doing it bottom-up ensures that values that are transitively dead are
2636-
+ // also removed. Although 1 pass should be enough,
2637-
+ // applyPatternsAndFoldGreedily will want to run at least 1 more iteration
2638-
+ // to confirm convergence, but we don't need to check for convergence, so we
2639-
+ // ignore the return value.
2640-
+ (void)applyPatternsAndFoldGreedily(getOperation(), RewritePatternSet(&getContext()), config);
2641-
+ }
2642-
+};
2643-
+
2644-
+} // namespace
2645-
+} // namespace experimental
2646-
+} // namespace stablehlo
2647-
+} // namespace mlir
26482563
diff --ruN a/stablehlo/stablehlo/tests/chlo/chlo_legalize_to_stablehlo.mlir b/stablehlo/stablehlo/tests/chlo/chlo_legalize_to_stablehlo.mlir
26492564
--- stablehlo/stablehlo/tests/chlo/chlo_legalize_to_stablehlo.mlir
26502565
+++ stablehlo/stablehlo/tests/chlo/chlo_legalize_to_stablehlo.mlir

third_party/xla/xla/pjrt/distributed/client.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ class DistributedRuntimeCoordinationServiceClient
4848
: DistributedRuntimeCoordinationServiceClient(channel, Options()) {}
4949
~DistributedRuntimeCoordinationServiceClient() override;
5050

51-
xla::Status Connect() override;
52-
xla::Status Shutdown() override;
51+
absl::Status Connect() override;
52+
absl::Status Shutdown() override;
5353
absl::StatusOr<std::string> BlockingKeyValueGet(
5454
std::string_view key, absl::Duration timeout) override;
5555
absl::StatusOr<std::vector<std::pair<std::string, std::string>>>
5656
KeyValueDirGet(std::string_view key) override;
57-
xla::Status KeyValueSet(std::string_view key,
58-
std::string_view value) override;
59-
xla::Status KeyValueDelete(std::string_view key) override;
60-
xla::Status WaitAtBarrier(std::string barrier_id,
61-
absl::Duration timeout) override;
57+
absl::Status KeyValueSet(std::string_view key,
58+
std::string_view value) override;
59+
absl::Status KeyValueDelete(std::string_view key) override;
60+
absl::Status WaitAtBarrier(std::string barrier_id,
61+
absl::Duration timeout) override;
6262
absl::StatusOr<tsl::CoordinationServiceAgent*> GetCoordinationServiceAgent()
6363
override;
6464

@@ -107,7 +107,7 @@ DistributedRuntimeCoordinationServiceClient::
107107
DistributedRuntimeCoordinationServiceClient::
108108
~DistributedRuntimeCoordinationServiceClient() = default;
109109

110-
xla::Status DistributedRuntimeCoordinationServiceClient::Connect() {
110+
absl::Status DistributedRuntimeCoordinationServiceClient::Connect() {
111111
const absl::Time deadline =
112112
absl::Now() +
113113
absl::Milliseconds(config_.cluster_register_timeout_in_ms());
@@ -130,7 +130,7 @@ xla::Status DistributedRuntimeCoordinationServiceClient::Connect() {
130130
return s;
131131
}
132132

133-
xla::Status DistributedRuntimeCoordinationServiceClient::Shutdown() {
133+
absl::Status DistributedRuntimeCoordinationServiceClient::Shutdown() {
134134
LOG(INFO) << "Distributed task shutdown initiated.";
135135
Status s = coord_agent_->Shutdown();
136136
LOG(INFO) << "Distributed task shutdown result: " << s;
@@ -162,17 +162,17 @@ DistributedRuntimeCoordinationServiceClient::KeyValueDirGet(
162162
return kvs;
163163
}
164164

165-
xla::Status DistributedRuntimeCoordinationServiceClient::KeyValueDelete(
165+
absl::Status DistributedRuntimeCoordinationServiceClient::KeyValueDelete(
166166
std::string_view key) {
167167
return coord_agent_->DeleteKeyValue(key);
168168
}
169169

170-
xla::Status DistributedRuntimeCoordinationServiceClient::KeyValueSet(
170+
absl::Status DistributedRuntimeCoordinationServiceClient::KeyValueSet(
171171
std::string_view key, std::string_view value) {
172172
return coord_agent_->InsertKeyValue(key, value);
173173
}
174174

175-
xla::Status DistributedRuntimeCoordinationServiceClient::WaitAtBarrier(
175+
absl::Status DistributedRuntimeCoordinationServiceClient::WaitAtBarrier(
176176
std::string barrier_id, absl::Duration timeout) {
177177
return coord_agent_->WaitAtBarrier(barrier_id, timeout, /*tasks=*/{});
178178
}

0 commit comments

Comments
 (0)