From b4ffcf8258cc7bcd4a97303efd53d6e6c01904d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20Dupr=C3=A9?= Date: Thu, 7 Mar 2019 13:08:02 +0100 Subject: [PATCH] Fixes #31, add option numpy_version, skip_keras_test to the parser of build.py, add flag PRIVATE for the python bindings (#544) * add option numpy_version to build against the installed numpy version and not 1.15.0 (hardcoded version number), default is still 1.15.0 * add option skip_keras_test to skip keras test even if keras is installed (still enabled by default) disable unnecessary warnings about ubuntu * enable option PRIVATE for the compilation of the Python bindings (settings recommended on pybind11 documentation) * test on debian 9 --- cmake/onnxruntime_python.cmake | 2 +- onnxruntime/python/onnxruntime_validation.py | 3 -- tools/ci_build/build.py | 29 ++++++++++++-------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/cmake/onnxruntime_python.cmake b/cmake/onnxruntime_python.cmake index c7df6a7de3..efe411d46b 100644 --- a/cmake/onnxruntime_python.cmake +++ b/cmake/onnxruntime_python.cmake @@ -86,7 +86,7 @@ elseif (APPLE) BUILD_WITH_INSTALL_RPATH TRUE INSTALL_RPATH_USE_LINK_PATH FALSE) else() - target_link_libraries(onnxruntime_pybind11_state ${onnxruntime_pybind11_state_libs} ${PYTHON_LIBRARY} ${ONNXRUNTIME_SO_LINK_FLAG} debug ${onnxruntime_EXTERNAL_LIBRARIES_DEBUG} optimized ${onnxruntime_EXTERNAL_LIBRARIES}) + target_link_libraries(onnxruntime_pybind11_state PRIVATE ${onnxruntime_pybind11_state_libs} ${PYTHON_LIBRARY} ${ONNXRUNTIME_SO_LINK_FLAG} debug ${onnxruntime_EXTERNAL_LIBRARIES_DEBUG} optimized ${onnxruntime_EXTERNAL_LIBRARIES}) set_target_properties(onnxruntime_pybind11_state PROPERTIES LINK_FLAGS "-Xlinker -rpath=\$ORIGIN") endif() diff --git a/onnxruntime/python/onnxruntime_validation.py b/onnxruntime/python/onnxruntime_validation.py index b337395d87..7350fe6655 100644 --- a/onnxruntime/python/onnxruntime_validation.py +++ b/onnxruntime/python/onnxruntime_validation.py @@ -47,9 +47,6 @@ def check_distro_info(): # warn the user ONNX Runtime may not work out of the box __my_distro__ = __my_distro__.lower() __my_distro_ver__ = __my_distro_ver__.lower() - - if __my_distro__ != 'ubuntu' and __my_distro_ver__ != '16.04': - warnings.warn('Unsupported Linux distribution (%s-%s). ONNX Runtime supports Ubuntu 16.04 only.' % (__my_distro__, __my_distro_ver__)) elif __my_system__ == 'darwin': __my_distro__ = __my_system__ __my_distro_ver__ = platform.release().lower() diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index fd425d9f13..08e70e674a 100755 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -79,6 +79,9 @@ Use the individual flags to only run the specified stages. # Python bindings parser.add_argument("--enable_pybind", action='store_true', help="Enable Python Bindings.") parser.add_argument("--build_wheel", action='store_true', help="Build Python Wheel. ") + parser.add_argument("--numpy_version", default='1.15.0', help="Installs a specific version of numpy " + "before building the python binding.") + parser.add_argument("--skip-keras-test", action='store_true', help="Skip tests with Keras if keras is installed") # C-Sharp bindings parser.add_argument("--build_csharp", action='store_true', help="Build C#.Net DLL and NuGet package") @@ -195,8 +198,9 @@ def install_ubuntu_deps(args): except Exception as e: raise BuildError("Error setting up required APT packages. {}".format(str(e))) -def install_python_deps(): - dep_packages = ['setuptools', 'wheel', 'numpy==1.15.0'] +def install_python_deps(numpy_version=""): + dep_packages = ['setuptools', 'wheel'] + dep_packages.append('numpy==%s' % numpy_version if numpy_version else 'numpy') run_subprocess([sys.executable, '-m', 'pip', 'install', '--trusted-host', 'files.pythonhosted.org'] + dep_packages) def check_md5(filename, expected_md5): @@ -465,15 +469,16 @@ def run_onnxruntime_tests(args, source_dir, ctest_path, build_dir, configs, enab run_subprocess([os.path.join(cwd,'onnx_test_runner'), 'test_models'], cwd=cwd) if config != 'Debug': run_subprocess([sys.executable, 'onnx_backend_test_series.py'], cwd=cwd, dll_path=dll_path) - try: - import onnxmltools - import keras - onnxml_test = True - except ImportError: - warnings.warn("onnxmltools and keras are not installed. Following test cannot be run.") - onnxml_test = False - if onnxml_test: - run_subprocess([sys.executable, 'onnxruntime_test_python_keras.py'], cwd=cwd, dll_path=dll_path) + if not args.skip_keras_test: + try: + import onnxmltools + import keras + onnxml_test = True + except ImportError: + warnings.warn("onnxmltools and keras are not installed. Following test cannot be run.") + onnxml_test = False + if onnxml_test: + run_subprocess([sys.executable, 'onnxruntime_test_python_keras.py'], cwd=cwd, dll_path=dll_path) def run_onnx_tests(build_dir, configs, onnx_test_data_dir, provider, enable_parallel_executor_test, num_parallel_models): for config in configs: @@ -570,7 +575,7 @@ def main(): if not is_docker(): install_python_deps() if (args.enable_pybind and is_windows()): - install_python_deps() + install_python_deps(args.numpy_version) if (not args.skip_submodule_sync): update_submodules(source_dir)