tree: ba53c3aba0bee7490e05f463d8666f961d06d5f0 [path history] [tgz]
  1. keras/
  2. batch_norm_test.py
  3. broadcasting_test.py
  4. BUILD
  5. complex_test.py
  6. concat_test.py
  7. control_flow_test.py
  8. conv_test.py
  9. depth_conv_test.py
  10. dynamic_mlp_relu_test.py
  11. dynamic_mlp_test.py
  12. explicit_backend_test.py
  13. fill_test.py
  14. gather_test.py
  15. iree_e2e_test_suite.bzl
  16. linspace_test.py
  17. mandelbrot_test.py
  18. math_test.py
  19. matrix_ops_test.py
  20. README.md
  21. resource_ops_test.py
  22. ring_buffer_test.py
  23. scatter_update_test.py
  24. simple_arithmetic_test.py
  25. simple_stateful_test.py
  26. sliding_window_test.py
  27. strings_test.py
  28. tensorlist_test.py
integrations/tensorflow/e2e/README.md

TensorFlow e2e tests

This is a collection of e2e tests that save a TensorFlow model, compile it with IREE, run it on multiple backends and crosscheck the results.

Pre-Requisites

You will need a TensorFlow 2.0+ nightly installed in your python environment: the python binary in $PYTHON_BIN should be able to import tensorflow and that TensorFlow should be version 2.0+. This can be checked with tensorflow.version.

See Install TensorFlow with pip for instructions.

Vulkan setup

If you do not have your environment setup to use IREE with Vulkan (see the doc), then you can run the manual test targets with --target_backends=tf,iree_vmla,iree_llvmjit (that is, by omitting iree_vulkan from the list of backends to run the tests on).

The test suites can be run excluding Vulkan by specifying --test_tag_filters="-driver=vulkan" in the bazel test invocation.

Compiling tf.Modules

Compatible TensorFlow modules can be compiled to specific IREE backends using IreeCompiledModule. This also optionally saves compilation artifacts to a specified directory. These artifacts include: MLIR across various lowerings, a TensorFlow SavedModel, and the compiled VM FlatBuffer. A basic example of creating and calling an IreeCompiledModule can be found in tf_utils_test.py

When using Keras models or tf.Modules with functions that IREE can't compile, exported_names should be specified. For example:

from pyiree.tf.support import tf_utils
vmla_module = tf_utils.IreeCompiledModule(
    module_class=KerasTFModuleClass,
    backend_info=tf_utils.BackendInfo.ALL['iree_vmla'],
    exported_names=['predict'])
vmla_module.predict(...)

Running tests

For locally running tests and iterating on backend development, bazel run is preferred.

# Run math_test on all backends.
bazel run :math_test_manual

# Run math_test on the VMLA backend only.
bazel run :math_test_manual -- --target_backends=iree_vmla

# Same as above, but add `tf` backend to cross-check numerical correctness.
bazel run :math_test_manual -- --target_backends=tf,iree_vmla

# Run math_test and output on failure.
bazel test :math_test_manual --test_output=errors

# Run an individual test interactively.
bazel run :math_test_manual -- --test_output=streamed

If you specify the same backend multiple times, for example --target_backends=iree_vmla,iree_vmla. The same backends are grouped and in this example iree_vmla will run once. If you specify tf,iree_vmla as backends, then we will test both backends and compare them with each other. If you specify tf backend only, then we will also test tf vs tf to capture any model initialization/randomization issues (it is a special case for debug purpose). For reproducibility of the unit tests we set random seed of tf and numpy by calling tf_utils.set_random_seed() before model creation.

Test Suites

Test targets are automatically generated for each test file and for each backend to check numerical correctness against TensorFlow. Tests targets that pass are placed into the e2e_tests test suite. Tests that fail on particular backends are recorded in lists in the BUILD files. For example, if experimental_new_test.py fails on the iree_llvmjit and iree_vulkan backends then the following lines should be added to the BUILD file:

LLVM_FAILING = [
    ...
    "experimental_new_test.py",
    ...
]

VULKAN_FAILING = [
    ...
    "experimental_new_test.py",
    ...
]

Test targets for these backends are placed into the e2e_tests_failing test suite. Test targets in these test suites can be run as follows:

# Run all e2e tests that are expected to pass.
bazel test :e2e_tests

# Run all e2e tests that are expected to fail.
bazel test :e2e_tests_failing

# Run a specific failing e2e test target.
# Note that generated test targets are prefixed with their test suite name.
bazel test :e2e_tests_failing_broadcasting_test__tf__iree_vulkan

Debugging tests

If the compiler fails to compile the program, then it will create a crash reproducer (see MLIR documentation), which then allows reproducing the bug with an appropriate “opt” tool. Further debugging iteration can happen in opt.

TODO(silvasean): debugging miscompiles

Test harnesses

Simple function tests

See simple_arithmetic_test.py for some basic examples.