예제 #1
0
def run_ngtf_pytests(venv_dir, build_dir):
    root_pwd = os.getcwd()

    build_dir = os.path.abspath(build_dir)
    venv_dir = os.path.abspath(venv_dir)

    test_dir = os.path.join(build_dir, "test")
    test_dir = os.path.join(test_dir, "python")

    if not os.path.isdir(test_dir):
        raise Exception("test directory doesn't exist: " + test_dir)

    # Change the directory to the test_dir
    os.chdir(test_dir)

    # Load venv
    load_venv(venv_dir)

    # Next run the ngraph-tensorflow python tests
    command_executor([sys.executable, "-m", "pip", "install", "-U", "pytest"])
    command_executor([sys.executable, "-m", "pip", "install", "-U", "psutil"])
    command_executor([
        "python", "-m", "pytest",
        ('--junitxml=%s/xunit_pytest.xml' % build_dir)
    ],
                     verbose=True)

    os.chdir(root_pwd)
예제 #2
0
def run_tensorflow_pytests(venv_dir, build_dir, ngraph_tf_src_dir, tf_src_dir):
    root_pwd = os.getcwd()

    build_dir = os.path.abspath(build_dir)
    venv_dir = os.path.abspath(venv_dir)
    ngraph_tf_src_dir = os.path.abspath(ngraph_tf_src_dir)

    patch_file = os.path.abspath(
        os.path.join(ngraph_tf_src_dir,
                     "test/python/tensorflow/tf_unittest_ngraph.patch"))

    # Load the virtual env
    venv_dir_absolute = load_venv(venv_dir)

    # Next patch the TensorFlow so that the tests run using ngraph_bridge
    pwd = os.getcwd()

    # Go to the site-packages/tensorflow_core_python/framework
    os.chdir(
        glob.glob(venv_dir_absolute +
                  "/lib/py*/site-packages/tensorflow_core/python/framework")[0])
    print("CURRENT DIR: " + os.getcwd())

    print("Patching TensorFlow using: %s" % patch_file)
    apply_patch(patch_file)
    os.chdir(pwd)

    # Now run the TensorFlow python tests
    test_src_dir = os.path.join(ngraph_tf_src_dir, "test/python/tensorflow")
    test_script = os.path.join(test_src_dir, "tf_unittest_runner.py")
    if get_os_type() == 'Darwin':
        test_manifest_file = os.path.join(test_src_dir,
                                          "python_tests_list_mac.txt")
    else:
        test_manifest_file = os.path.join(test_src_dir, "python_tests_list.txt")
    test_xml_report = '%s/junit_tensorflow_tests.xml' % build_dir

    import psutil
    num_cores = int(psutil.cpu_count(logical=False))
    print("OMP_NUM_THREADS: %s " % str(num_cores))
    os.environ['OMP_NUM_THREADS'] = str(num_cores)
    os.environ['NGRAPH_TF_DISABLE_DEASSIGN_CLUSTERS'] = '1'

    # command_executor([
    #     "python", test_script, "--tensorflow_path", tf_src_dir,
    #     "--run_tests_from_file", test_manifest_file, "--xml_report",
    #     test_xml_report
    # ], verbose=True)

    command_executor([
        "python", test_script, "--tensorflow_path", tf_src_dir,
        "--run_tests_from_file", test_manifest_file
    ],
                     verbose=True)

    os.chdir(root_pwd)
예제 #3
0
def run_ngtf_pytests(venv_dir, build_dir):
    root_pwd = os.getcwd()

    build_dir = os.path.abspath(build_dir)
    venv_dir = os.path.abspath(venv_dir)
    mnist_dir = os.path.abspath(build_dir + '/examples/mnist/')
    axpy_dir = os.path.abspath(build_dir + '/examples/')
    test_dir = os.path.join(build_dir, "test")
    test_dir = os.path.join(test_dir, "python")

    if not os.path.isdir(test_dir):
        raise Exception("test directory doesn't exist: " + test_dir)

    # Change the directory to the test_dir
    os.chdir(test_dir)

    # Load venv
    load_venv(venv_dir)

    # Next run the ngraph-tensorflow python tests
    command_executor(["pip", "install", "-U", "pytest"])
    command_executor(["pip", "install", "-U", "keras==2.3.1"])
    command_executor(["pip", "install", "-U", "psutil"])

    cmd = 'python -m pytest ' + (
        '--junitxml=%s/xunit_pytest.xml' %
        build_dir) + " --ignore=" + build_dir + "/test/python/bfloat16"
    env = os.environ.copy()
    new_paths = venv_dir + '/bin/python3:' + os.path.abspath(
        build_dir) + ":" + os.path.abspath(axpy_dir) + ":" + os.path.abspath(
            mnist_dir)
    if 'PYTHONPATH' in env:
        env["PYTHONPATH"] = new_paths + ":" + env["PYTHONPATH"]
    else:
        env["PYTHONPATH"] = new_paths
    ps = Popen(cmd, shell=True, env=env)
    so, se = ps.communicate()
    errcode = ps.returncode
    assert errcode == 0, "Error in running command: " + cmd
    os.chdir(root_pwd)
예제 #4
0
def run_bazel_build_test(venv_dir, build_dir):
    # Load the virtual env
    venv_dir_absolute = load_venv(venv_dir)

    # Next patch the TensorFlow so that the tests run using ngraph_bridge
    root_pwd = os.getcwd()

    # Now run the configure
    command_executor(['bash', 'configure_bazel.sh'])

    # Build the bridge
    command_executor(['bazel', 'build', 'libngraph_bridge.so'])

    # Build the backend
    command_executor(['bazel', 'build', '@ngraph//:libinterpreter_backend.so'])

    # Return to the original directory
    os.chdir(root_pwd)
예제 #5
0
def run_bazel_build_test(venv_dir, build_dir):
    # Load the virtual env
    venv_dir_absolute = load_venv(venv_dir)

    # Next patch the TensorFlow so that the tests run using ngraph_bridge
    root_pwd = os.getcwd()

    # Now run the configure
    command_executor(['bash', 'configure_bazel.sh'])

    # Build the cpp app - hello_tf
    command_executor(['bazel', 'build', 'hello_tf'])

    # Run the cpp app - hello_tf
    command_executor(['bazel-bin/hello_tf'])

    # Now built the bigger app
    command_executor(['bazel', 'build', 'infer_multiple_networks'])

    # Return to the original directory
    os.chdir(root_pwd)
예제 #6
0
def main():
    '''
    Tests nGraph-TensorFlow Python 3. This script needs to be run after 
    running build_ngtf.py which builds the ngraph-tensorflow-bridge
    and installs it to a virtual environment that would be used by this script.
    '''
    parser = argparse.ArgumentParser()
    parser.add_argument('--test_examples',
                        help="Builds and tests the examples.\n",
                        action="store_true")

    parser.add_argument('--gpu_unit_tests_enable',
                        help="Builds and tests the examples.\n",
                        action="store_true")

    arguments = parser.parse_args()

    #-------------------------------
    # Recipe
    #-------------------------------

    root_pwd = os.getcwd()

    # Constants
    build_dir = 'build_cmake'
    venv_dir = 'build_cmake/venv-tf-py3'
    tf_src_dir = 'build_cmake/tensorflow'

    if (platform.system() != 'Darwin'):
        # Run the bazel based buil
        run_bazel_build_test(venv_dir, build_dir)

    # First run the C++ gtests
    run_ngtf_gtests(build_dir, None)

    # If the GPU tests are requested, then run them as well
    if (arguments.gpu_unit_tests_enable):
        os.environ['NGRAPH_TF_BACKEND'] = 'GPU'
        run_ngtf_gtests(
            build_dir,
            str("-ArrayOps.Quanti*:ArrayOps.Dequant*:BackendManager.BackendAssignment:"
                "MathOps.AnyKeepDims:MathOps.AnyNegativeAxis:MathOps.AnyPositiveAxis:"
                "MathOps.AllKeepDims:MathOps.AllNegativeAxis:MathOps.AllPositiveAxis:"
                "NNOps.Qu*:NNOps.SoftmaxZeroDimTest*:"
                "NNOps.SparseSoftmaxCrossEntropyWithLogits"))

    os.environ['NGRAPH_TF_BACKEND'] = 'CPU'

    # Next run Python unit tests
    load_venv(venv_dir)
    run_ngtf_pytests(venv_dir, build_dir)

    if (arguments.test_examples):
        # Run the C++ example build/run test
        run_cpp_example_test('build')

    # Next run the TensorFlow python tests
    run_tensorflow_pytests(venv_dir, build_dir, './', tf_src_dir)

    # Finally run Resnet50 based training and inferences
    run_resnet50(build_dir)

    os.chdir(root_pwd)