Skip to content

Commit 1914c41

Browse files
tf-marissawtensorflower-gardener
authored andcommitted
Update context and tfe_wrapper to support mlir_bridge_rollout
Update eager/context.py and tfe_wrapper to support returning the real value of mlir_bridge_rollout (enabled/disabled/unspecified) instead of a bool. This gives users a clearer signal of whether or not the mlir bridge is being used. At the moment, the mlir bridge is only enabled when mlir_bridge_rollout is set to enabled but this will change in the future. PiperOrigin-RevId: 338124102 Change-Id: I5c93cbdd2815a698e6b41244db8eed716f4988e6
1 parent 169cbde commit 1914c41

4 files changed

Lines changed: 26 additions & 4 deletions

File tree

‎tensorflow/compiler/tf2xla/mlir_bridge_pass.h‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class MlirBridgePass : public MlirOptimizationPass {
3131

3232
bool IsEnabled(const ConfigProto& config_proto) const override {
3333
return config_proto.experimental().enable_mlir_bridge() ||
34+
config_proto.experimental().mlir_bridge_rollout() ==
35+
tensorflow::ConfigProto::Experimental::
36+
MLIR_BRIDGE_ROLLOUT_ENABLED ||
3437
tensorflow::GetMlirCommonFlags()->tf_mlir_enable_mlir_bridge ==
3538
tensorflow::ConfigProto::Experimental::
3639
MLIR_BRIDGE_ROLLOUT_ENABLED;
@@ -50,7 +53,10 @@ class MlirBridgeV1CompatPass : public MlirV1CompatOptimizationPass {
5053

5154
bool IsEnabled(const ConfigProto& config_proto) const override {
5255
return config_proto.experimental().enable_mlir_bridge() ||
53-
GetMlirCommonFlags()->tf_mlir_enable_mlir_bridge ==
56+
config_proto.experimental().mlir_bridge_rollout() ==
57+
tensorflow::ConfigProto::Experimental::
58+
MLIR_BRIDGE_ROLLOUT_ENABLED ||
59+
tensorflow::GetMlirCommonFlags()->tf_mlir_enable_mlir_bridge ==
5460
tensorflow::ConfigProto::Experimental::
5561
MLIR_BRIDGE_ROLLOUT_ENABLED;
5662
}

‎tensorflow/python/eager/context.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,12 @@ def config(self):
948948
if self._log_device_placement is not None:
949949
config.log_device_placement = self._log_device_placement
950950

951-
config.experimental.enable_mlir_bridge = pywrap_tfe.TF_IsMlirBridgeEnabled()
951+
is_mlir_bridge_enabled = pywrap_tfe.TF_IsMlirBridgeEnabled()
952+
config.experimental.mlir_bridge_rollout = is_mlir_bridge_enabled
953+
if (is_mlir_bridge_enabled ==
954+
config_pb2.ConfigProto.Experimental.MLIR_BRIDGE_ROLLOUT_ENABLED):
955+
config.experimental.enable_mlir_bridge = True
956+
952957
if self._enable_mlir_graph_optimization is not None:
953958
config.experimental.enable_mlir_graph_optimization = (
954959
self._enable_mlir_graph_optimization)

‎tensorflow/python/framework/config_test.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,23 @@ def testLogDevicePlacement(self):
214214
def testEnableMlirBridge(self):
215215
# Default value of enable_mlir_bridge is false.
216216
self.assertFalse(context.context().config.experimental.enable_mlir_bridge)
217+
self.assertEqual(
218+
context.context().config.experimental.mlir_bridge_rollout,
219+
config_pb2.ConfigProto.Experimental.MLIR_BRIDGE_ROLLOUT_UNSPECIFIED)
217220

218221
# Tests enabling mlir bridge.
219222
config.enable_mlir_bridge()
220223
self.assertTrue(context.context().config.experimental.enable_mlir_bridge)
224+
self.assertEqual(
225+
context.context().config.experimental.mlir_bridge_rollout,
226+
config_pb2.ConfigProto.Experimental.MLIR_BRIDGE_ROLLOUT_ENABLED)
221227

222228
# Tests disabling mlir bridge.
223229
config.disable_mlir_bridge()
224230
self.assertFalse(context.context().config.experimental.enable_mlir_bridge)
231+
self.assertEqual(
232+
context.context().config.experimental.mlir_bridge_rollout,
233+
config_pb2.ConfigProto.Experimental.MLIR_BRIDGE_ROLLOUT_DISABLED)
225234

226235
@reset_eager
227236
def testEnableMlirGraphOptimization(self):

‎tensorflow/python/tfe_wrapper.cc‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,10 @@ PYBIND11_MODULE(_pywrap_tfe, m) {
580580

581581
// MLIR Logic
582582
m.def("TF_IsMlirBridgeEnabled", [] {
583-
return tensorflow::GetMlirCommonFlags()->tf_mlir_enable_mlir_bridge ==
584-
tensorflow::ConfigProto::Experimental::MLIR_BRIDGE_ROLLOUT_ENABLED;
583+
// Since python protobuf enums are integers, cast to an integer before
584+
// returning the enum to python.
585+
return static_cast<int32_t>(
586+
tensorflow::GetMlirCommonFlags()->tf_mlir_enable_mlir_bridge);
585587
});
586588
m.def("TF_EnableMlirBridge", [](bool enabled) {
587589
tensorflow::GetMlirCommonFlags()->tf_mlir_enable_mlir_bridge =

0 commit comments

Comments
 (0)