Commit Graph

18 Commits

Author SHA1 Message Date
Marissa Ikonomidis
3708f73481 Support Session's ConfigProto in TF2 MLIR bridge
Some models are using "TF2" but also using Session and passing
a ConfigProto. This is TF1 code running on the TF2 MLIR bridge.
The TF2 MLIR bridge assumed that this was not possible. This cl
updates the TF2 version of the MLIR bridge to support a ConfigProto
passed in via Session.

Disable MLIR bridge presubmit testing of saved_model_test.py because this fix reveals that the test is actually broken. It is using TF2 control flow but loading a model with Session.

PiperOrigin-RevId: 335915669
Change-Id: Ib50bef389449ce0011878dd50b73856e9c520289
2020-10-07 11:44:49 -07:00
Marissa Ikonomidis
c1921df0e2 Allow the TF_XLA_FLAGS tf_mlir_enable_mlir_bridge to still enable the experimental mlir bridge
for TensorFlow V1 even when the user overrides Session's default ConfigProto.

In TensorFlow V1, when the user doesn't override Session's default ConfigProto, the ConfigProto
uses the value from TF_XLA_FLAGS (via context.config). However, when the user passes in their
own ConfigProto, enable_mlir_bridge is defaulted to false.

PiperOrigin-RevId: 320661288
Change-Id: I5deacb4e12b6551a57c2496c35830ac3af25fe28
2020-07-10 13:18:18 -07:00
Lucy Fox
90077f8c7c Instrument the number of times the MLIR-based TF Bridge is enabled.
PiperOrigin-RevId: 311633792
Change-Id: Iba286e1c82900833b5cf9f69a697a312e51f3156
2020-05-14 17:04:52 -07:00
Mehdi Amini
da4a324454 Enable logging by default about running or not the MLIR bridge
PiperOrigin-RevId: 309344310
Change-Id: I610ab30c0483156e7bcc16185998005dd7da264f
2020-04-30 19:21:25 -07:00
Eugene Zhulenev
891375f55f [TF:MLIR] Add generic MLIR pass registration mechanism.
PiperOrigin-RevId: 300198093
Change-Id: I462e5c4096519f382271e4cc6734b28fa7fd2034
2020-03-10 16:04:53 -07:00
Brian Atkinson
ba2cbe1e55 Avoid direct access to the env var TEST_UNDECLARED_OUTPUTS_DIR.
On Windows, Bazel populates this path with `/`s only making proper path
management impossible without sanitizing the path up front. This changes to
accessing the env var through an indirection layer which will fix path problems
on Windows when the codebase is ready to switch over.

PiperOrigin-RevId: 296083765
Change-Id: I26bbaf83ba5e3fafd3ab0a0de08f6cb597b94477
2020-02-19 16:28:06 -08:00
HyoukJoong Lee
dbfb89dd91 internal change for IR dump
PiperOrigin-RevId: 295054393
Change-Id: I0a5e0d47cd6eed764c4b5163aba185dac089da06
2020-02-13 19:31:52 -08:00
Andy Ly
11d3a2d7f2 Add and register MLIR bridge v1 compat pass.
This pass is similar to the MLIR bridge pass but is specific to TensorFlow V1 Graphs. In addition, this pass will only trigger on non function graphs as they are already handled by the MLIR bridge pass.

PiperOrigin-RevId: 294521035
Change-Id: If80bb613b51ff9fd8b2dad61b4357a55452a4093
2020-02-11 14:33:38 -08:00
Andy Ly
d1577971d7 Register MLIR bridge pass as a FunctionOptimizationPass with FunctionOptimizationPassRegistry.
This reworks the MLIR bridge pass from an GraphOptimizationPass to a FunctionOptimizationPass for the function library runtime. Control ret node names are also passed into and updated from the registry pass run (MLIR to Graph).

PiperOrigin-RevId: 293703916
Change-Id: I644765f4c5294962450cacb9c748582a579989c5
2020-02-06 16:30:20 -08:00
Stella Laurenzo
ae07e29a16 Load SavedModelV2 variables directly from the checkpoint.
* This fixes a correctness problem where we were relying on the variable's "name" attribute, which is merely advisory.
* Should match the load heuristics in Python by reading the TrackableObjectGraph from the checkpoint, re-associating it with the SavedObjectGraph and using that to restore the variable.
* Has a side-effect of eliminating the dependency of the importer on the CPU runtime and kernels, which should reduce necessary dependencies to compile by tens of megabytes.

Open questions:
* I created a new bundle_v2.h because V2 is so substantially different from V1. Also, it has a different dependency surface area and I therefore wanted to use it as a different (lighter) library. Advise if you would like this organized differently. I tried to factor it so that a future C++ SavedModel loader/runner could be built on this as well (with some incremental work).
* There didn't seem to be a facility for generating the testdata SavedModels. I ended up just writing a small standalone python script that I can invoke from the command line to generate the new ones. It isn't wired up in any way but it should be possible to do so at some point (I'm not familiar enough with the test infra on this side of the tree, so please advise).
* I could see factoring the SavedModelV2Bundle::RestoreObjects method into a dedicated facility for loading arbitrary checkpoints. Not sure what the roadmap here is so just kept is simple for now.

PiperOrigin-RevId: 282439157
Change-Id: I685df47ab621917eed270319cde220498f191b74
2019-11-25 15:01:01 -08:00
Andy Ly
5c67a965db Replace logging in MLIR bridge passes with PassInstrumentation that handles logging via PassManager.
PiperOrigin-RevId: 280675323
Change-Id: I5d3406bd7b55b126b2e939b9589a041998ba5dcb
2019-11-15 09:40:03 -08:00
Andy Ly
87c5874443 Enable graph-as-function for exporting in bridge pass.
PiperOrigin-RevId: 278626392
Change-Id: Iedacd0abcb91b052df076a416448d06fb9d27227
2019-11-05 08:07:29 -08:00
Yanan Cao
00c915e579 Use graph as function in MLIR bridge, which eliminates _arg and _retval nodes.
PiperOrigin-RevId: 275363556
Change-Id: Ia9626bcd64fdc9bf935469fcd67a09b2cb3d0ee6
2019-10-17 16:35:51 -07:00
Andy Ly
0aaf71779a Create separate general device util for adding and getting device names (from DeviceSet) to and from an op (NFC).
This moves a function from tpu_rewrite_device_util for getting devices, and a function for adding devices from mlir_bridge_pass, into its own util.

PiperOrigin-RevId: 273610226
2019-10-08 19:29:27 -07:00
Andy Ly
4a93f199ea Propagate devices as strings in MlirBridgePass.
This takes every device in the device set of the GraphOptimizationPassOptions and converts their parsed name into a string. The device strings are then added to the module op as an ArrayAttr<StringAttr> attribute. Devices are necessary for certain passes (e.g. TPURewritePass).

PiperOrigin-RevId: 272029573
2019-09-30 13:30:03 -07:00
Jacques Pienaar
4a78601139 Rename import/export configs for Graph to MLIR consistently
NodeSpecs -> GraphImportConfig
ExporterConfigs -> GraphExportConfig

PiperOrigin-RevId: 271257644
2019-09-25 22:39:40 -07:00
Mehdi Amini
fe072f48e5 Plumb the MLIR TPU bridge passes
This is putting together MLIR passes that transforms the TensorFlow IR so
that it can be executed when targetted TPU.

PiperOrigin-RevId: 266978849
2019-09-03 13:24:21 -07:00
Mehdi Amini
c4ed3fe077 Add a MLIRBridgePass GraphOptimizationPass
This pass is implemented as early as possible in the pipeline and allows to
implement MLIR-based graph transformation. At the moment it is enabled by
an experimental session config flag only, and won't do anything useful
but round-tripping the Graph to MLIR.

PiperOrigin-RevId: 266036600
2019-08-28 18:19:42 -07:00