-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable Virtual Environments in testing #2191
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pfultz2 This is a draft version, needs to be cleaned up and improved.
I have asked some questions for clarification/feedback.
Please feel free to leave more comments/feedback that you may have.
Thanks!
test/py/CMakeLists.txt
Outdated
add_test (NAME SETUP_VENV COMMAND "${Python3_EXECUTABLE}" -m pip install -r ${REQUIREMENTS_FILE}) | ||
set_tests_properties(SETUP_VENV PROPERTIES FIXTURES_REQUIRED INIT_VENV) | ||
set_tests_properties(SETUP_VENV PROPERTIES FIXTURES_SETUP ${FIXTURE_NAME}) | ||
endfunction() | ||
|
||
function(add_py_test NAME SCRIPT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function iterates over all the available python versions on the system from the ones specified in PythonModules
: (PYTHON_SEARCH_VERSIONS 2.7 3.5 3.6 3.7 3.8 3.9 3.10
).
For enabling virtual environments, do we need to consider python 2.7
too? Current implementation of virtual environment is assuming we only work with Python 3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For posterity; we discussed this and disabled python 2.7
.
tools/install_prereqs.sh
Outdated
@@ -51,6 +51,7 @@ else | |||
openmp-extras \ | |||
python3-dev \ | |||
python3-pip \ | |||
python3.8-venv \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we would need to add it for sles
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sles supports a different level of python (3.7?), Ubuntu 22.04 supports python3.10. I think you'll need to just install the default python3-venv and not be explicit to 3.8
test/py/CMakeLists.txt
Outdated
@@ -44,6 +66,9 @@ endfunction() | |||
add_dependencies(tests migraphx_py) | |||
add_dependencies(check migraphx_py) | |||
|
|||
add_py_venv_fixture( | |||
${FIX_NAME} ${VENV_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/REQUIREMENTS.TXT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The REQUIREMENTS.TXT
file lives under test/py
, is there a better place for having this file reside?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be lower case: requirements.txt
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I have also added a requirements-sles.txt
for package requirements on sles.
test/py/CMakeLists.txt
Outdated
set (ENV{VIRTUAL_ENV} ${VENV_DIR}) | ||
set (Python3_FIND_VIRTUALENV ONLY) | ||
unset (Python3_EXECUTABLE) | ||
find_package (Python3 COMPONENTS Interpreter Development) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these lines be moved to a function since we also have these same lines in add_py_venv_fixture
function (35-38)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dont use find_package
to find python. Instead do set(PYTHON_EXECUTABLE ${VENV_DIR}/${PYTHON_VERSION}/bin/python)
.
test/py/REQUIREMENTS.TXT
Outdated
onnx==1.10.2 | ||
numpy==1.21.6 | ||
typing==3.7.4 | ||
pytest==6.0.1 | ||
packaging==23.0 | ||
protobuf==3.20.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any other requirements that we should add here?
Codecov Report
@@ Coverage Diff @@
## develop #2191 +/- ##
========================================
Coverage 91.45% 91.45%
========================================
Files 433 433
Lines 16174 16174
========================================
Hits 14792 14792
Misses 1382 1382 |
This build is OK for merge ✅ |
🔴bert_base_cased_fp16: FAILED: MIGraphX is not within tolerance - check verbose output🔴bert_large_uncased_fp16: FAILED: MIGraphX is not within tolerance - check verbose output🔴distilgpt2_fp16: FAILED: MIGraphX is not within tolerance - check verbose output |
test/py/CMakeLists.txt
Outdated
|
||
function(add_py_venv_fixture FIXTURE_NAME VIRTUAL_ENV_DIR REQUIREMENTS_FILE) | ||
message("Attempting to create virtual environment: ${VIRTUAL_ENV_DIR}") | ||
find_package (Python3 COMPONENTS Interpreter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dont call find_package(Python3)
as this could get a different python version. Instead this should take the PYTHON_EXECUTABLE
as an input parameter.
test/py/CMakeLists.txt
Outdated
set (Python3_FIND_VIRTUALENV ONLY) | ||
unset (Python3_EXECUTABLE) | ||
find_package (Python3 COMPONENTS Interpreter Development) | ||
add_test (NAME SETUP_VENV COMMAND "${Python3_EXECUTABLE}" -m pip install -r ${REQUIREMENTS_FILE}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use ${VIRTUAL_ENV_DIR}/bin/python
.
test/py/CMakeLists.txt
Outdated
add_test (NAME SETUP_VENV COMMAND "${Python3_EXECUTABLE}" -m pip install -r ${REQUIREMENTS_FILE}) | ||
set_tests_properties(SETUP_VENV PROPERTIES FIXTURES_REQUIRED INIT_VENV) | ||
set_tests_properties(SETUP_VENV PROPERTIES FIXTURES_SETUP ${FIXTURE_NAME}) | ||
endfunction() | ||
|
||
function(add_py_test NAME SCRIPT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should take VENV
as input parameter.
test/py/CMakeLists.txt
Outdated
function(add_py_venv_fixture FIXTURE_NAME VIRTUAL_ENV_DIR REQUIREMENTS_FILE) | ||
message("Attempting to create virtual environment: ${VIRTUAL_ENV_DIR}") | ||
find_package (Python3 COMPONENTS Interpreter) | ||
add_test (NAME INITIALIZE_VENV COMMAND "${Python3_EXECUTABLE}" -m venv ${VIRTUAL_ENV_DIR}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of the test should be ${FIXTURE_NAME}_initialize_env
to avoid conflicts with different python versions or fixtures.
test/py/CMakeLists.txt
Outdated
message("Attempting to create virtual environment: ${VIRTUAL_ENV_DIR}") | ||
find_package (Python3 COMPONENTS Interpreter) | ||
add_test (NAME INITIALIZE_VENV COMMAND "${Python3_EXECUTABLE}" -m venv ${VIRTUAL_ENV_DIR}) | ||
set_tests_properties(INITIALIZE_VENV PROPERTIES FIXTURES_SETUP INIT_VENV) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fixture setup name should ${FIXTURE_NAME}_INIT_VENV
.
test/py/CMakeLists.txt
Outdated
@@ -44,6 +66,9 @@ endfunction() | |||
add_dependencies(tests migraphx_py) | |||
add_dependencies(check migraphx_py) | |||
|
|||
add_py_venv_fixture( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be called inside add_py_test
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made the change to call it inside add_py_test
but I was hitting issues with the unique naming of tests. The reason is that add_py_test
is called multiple times for different tests (ref, save_load, op etc) and the naming we were using for the test name was based on python version only so cmake configure complained that we are having duplicate test names for add_test
. I tried checking for the existence of the venv directory to introduce a condition to only add tests if the venv for a particular python version does not exist, but the issue was that the venv directory is created during build step and cmake would fail (complain about duplicate names for add_test
) at the configure step when it would not see the directory.
To fix this, I moved add_py_venv_fixture
to outside of add_py_test
. Inside add_py_venv_fixture
, I iterate over all available Python versions. This might not be the most elegant solution, so I am open to suggestions for a better solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed this on Friday with Paul, and he suggested to check if a test already exists before adding tests for init/setup venv to resolve the issue with duplication of test names. I have now made that change and add_py_venv_fixture
is being called inside add_py_test
.
test/py/CMakeLists.txt
Outdated
|
||
add_test(NAME py_${PYTHON_VERSION}_initialize_env COMMAND ${PYTHON_EXECUTABLE} -m venv ${VIRTUAL_ENV_DIR} --clear) | ||
set_tests_properties(py_${PYTHON_VERSION}_initialize_env PROPERTIES FIXTURES_SETUP ${PYTHON_VERSION}_INIT_VENV) | ||
set(ENV{VIRTUAL_ENV} ${VIRTUAL_ENV_DIR}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are using the path to python in the virtual environment, this might not be needed. Should I remove this?
Edit: set(ENV{VIRTUAL_ENV} ${VIRTUAL_ENV_DIR})
is similar to activating the virtual env.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This env variable wont be applied when running the test, so this can be removed.
00c01be
to
a39bb79
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Unless @pfultz2 has anything else
Perf errors are from another issue I think we've already resolved on develop.
@pfultz2 I have made changes to the requirement files for python version specific requirement files. Can you please take a look to see if this looks good? |
test/py/base-requirements.txt
Outdated
# THE SOFTWARE. | ||
##################################################################################### | ||
|
||
pytest==6.0.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think we need pytest, but we do need numpy for our tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed pytest
, it was needed for onnx.
Tests pass without numpy
. So I have kept this file empty, I can add numpy
if you feel it should be here.
test/py/requirements-python-3.6.txt
Outdated
onnx==1.10.2 | ||
protobuf==3.19.6 | ||
numpy==1.19.5 | ||
packaging==21.3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this file, we should just disable the onnx tests when using python 3.6.
test/py/requirements-python-all.txt
Outdated
onnx==1.14.1 | ||
protobuf==3.20.2 | ||
numpy==1.21.6 | ||
packaging==23.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be named requirements-onnx.txt.
test/py/CMakeLists.txt
Outdated
add_py_test(gpu_offload test_gpu_offload.py ${VENV} WORKING_DIRECTORY ${TEST_ONNX_DIR}) | ||
add_py_test(gpu test_gpu.py ${VENV} WORKING_DIRECTORY ${TEST_ONNX_DIR}) | ||
add_py_test(array test_array.py ${VENV} WORKING_DIRECTORY ${TEST_ONNX_DIR}) | ||
add_py_test(backend onnx_backend_test.py ${VENV} WORKING_DIRECTORY ${TEST_ONNX_DIR}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Onnx backend should be using a different virtual environment, and this should be disabled on python 3.6.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have disabled the onnx backend tests on python 3.6. I am open to a more elegant solution if you think we can have an alternate way to disable this.
test/py/CMakeLists.txt
Outdated
if(${PYTHON_VERSION} STREQUAL "3.6") | ||
add_py_venv_fixture(${PYTHON_VERSION} ${PYTHON_EXECUTABLE} ${VENV_DIR}/${PYTHON_VERSION} ${REQUIREMENTS_PYTHON_36}) | ||
else() | ||
add_py_venv_fixture(${PYTHON_VERSION} ${PYTHON_EXECUTABLE} ${VENV_DIR}/${PYTHON_VERSION} ${REQUIREMENTS_PYTHON_ALL}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The add_py_env_fixture
probably needs to be called outside of the function since tests will use different virtual environments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have taken the function out of add_py_test
.
test/py/CMakeLists.txt
Outdated
foreach(PYTHON_VERSION ${PYTHON_VERSIONS}) | ||
set (ENV_COMMAND ${CMAKE_COMMAND} -E env | ||
"PYTHONPATH=$<TARGET_FILE_DIR:migraphx_pybind_${PYTHON_VERSION}>" | ||
"PYTHONMALLOC=debug" | ||
"MALLOC_CHECK_=3" | ||
) | ||
set(PYTHON_EXECUTABLE ${PYTHON_${PYTHON_VERSION}_EXECUTABLE}) | ||
if(${PYTHON_VERSION} STREQUAL "3.6") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this, we shouldn't have python specific versions of the requirements.
@pfultz2 Thanks for taking a look and providing feedback. I have tried to address the comments. Can you please take a look to see if I have addressed the comments correctly? I am not a 100% sure if the current implementation is how you wanted it. Side note: The backend test seems to be timing out, I am investigating that but thought to put this up in the meanwhile to get your feedback on the implementation approach. |
The timing out of backend test was system related. A reboot of the system helped fix the issue. |
115b84e
to
afe6260
Compare
afe6260
to
e6f9f5e
Compare
Looks like we have also have try/except clause in another test Should we also remove this try except clause or leave it as is? @pfultz2 |
That should be removed as well. |
Thanks! Removed through #2316. |
Updated with develop branch to pull fix of cppcheck issue that has been fixed by df5f8c9. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, but as a followup we should add a flag to disable the virtual environments so we arent installing these packages everytime we are running tests in the CI.
@pfultz2 Thanks for approving the PR and for all your suggestions/feedback during the course of it. I have opened an issue to add a flag to disable virtual environments: #2324 |
This sets up the virtual environments for running python onnx tests.
ctest's fixtures are used to ensure that the virtual environment is
set up before the tests are run.