Skip to content

Commit

Permalink
Updating instructions for XLA export
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem Maevskiy authored and Artem Maevskiy committed Sep 1, 2022
1 parent 0a93bdd commit 514e900
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,22 @@ To export a trained model in ONNX format, run:
python3 export_model.py --checkpoint_name test_run --export_format onnx
```
Here `test_run` is the `CHECKPOINT_NAME` used in examples above. This creates a file `model_export/onnx/CHECKPOINT_NAME.onnx` containing the model graph and weights.

## Model export (XLA format)

To export a trained model in XLA format (compiled `.so`), run:
```bash
python3 export_model.py --checkpoint_name test_run --export_format pbtxt
```
Here `test_run` is the `CHECKPOINT_NAME` used in examples above. This creates protobuf files describing the model:
```
graph.pbtxt
graph-1.config.pbtxt
graph-10.config.pbtxt
graph-100.config.pbtxt
graph-1000.config.pbtxt
graph-10000.config.pbtxt
```
and puts them into `model_export/model_v4/` directory (previously created such files would get overwritten). The `graph.pbtxt` contains the frozen computation graph of the model with all the weight values. Files `graph-X.pbtxt` specify additional configuration for model build target - input and output tensor names and shapes (the number `X` standing for the batch size).

After exporting the model graph in protobuf format, please follow [these instructions](model_export/README.md) to build the model `.so` files.
4 changes: 2 additions & 2 deletions model_export/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The `setup_centos.sh` script (`model_export/setup_centos.sh`) contains all the e

*Note: this was only tested in a clean CentOS environment (in the docker container above), there might be conflicts with the main environment used for model training and evaluation.*

The `setup_centos.sh` script also creates a symlink to the `model_export/model_v4` folder and puts it into `tensorflow`. This folder contains bazel build instructions and needs to be inside the `tensorflow` directory to be built.
The `setup_centos.sh` script also creates a symlink to the `model_export/model_v4` folder (which should contain the `*.pbtxt` files describing the exported model) and puts it into `tensorflow`. This folder contains bazel build instructions and needs to be inside the `tensorflow` directory to be built.
```bash
./setup_centos.sh
```
Expand All @@ -23,7 +23,7 @@ cd tensorflow/
# rest options to default
BAZEL_LINKLIBS=-l%:libstdc++.a bazel build --local_resources 30000,15,1.0 -c opt model_v4:all_models
```
The `--local_resources` parameter from the last line allows to limit the resources to be used by bazel. 30000 is memory in megabytes, 15 is the number of CPU cores and 1.0 is the I/O capability. Not limiting the resources may result in a compiler crash.
The `--local_resources` parameter from the last line allows to limit the resources to be used by bazel. 30000 is memory in megabytes, 15 is the number of CPU cores and 1.0 is the I/O capability. Not limiting the resources may result in a compiler crash. To further rebuild the model (e.g., after updating the `*.pbtxt` files) only the last command is needed.

# Test:
```bash
Expand Down

0 comments on commit 514e900

Please sign in to comment.