Skip to content
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

fix: downgrade torch for mac intel support [to be closed soon] #796

Closed
wants to merge 3 commits into from

Conversation

bcm-at-zama
Copy link
Contributor

@cla-bot cla-bot bot added the cla-signed label Jul 18, 2024
@@ -43,7 +43,7 @@ setuptools = "65.6.3"
skops = {version = "0.5.0"}
xgboost = "1.6.2"
skorch = "0.11.0"
torch = "2.3.1"
torch = "2.2.2"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no way to say "Mac intel" but they are ways to say "Mac"

foo = [
    { platform = "darwin", url = "https://example.com/foo-1.0.0-py3-none-macosx_11_0_arm64.whl" },
    { platform = "linux", version = "^1.0", source = "pypi" },
]

Do we really want to have versions which differ between OSs, however?

@bcm-at-zama
Copy link
Contributor Author

If you don't mind, I'd like also to use a new CP, which fixes an issue for Mac intel. Let me add it to the Makefile

@bcm-at-zama
Copy link
Contributor Author

I currently can't sync_env. Trying to fix this

@bcm-at-zama
Copy link
Contributor Author

Works at 89f2db1

@bcm-at-zama
Copy link
Contributor Author

Works with 9f2db179bfbe6e095bb672ed58dae3ec3bdd15b + 2.7.0.dev20240709

@bcm-at-zama
Copy link
Contributor Author

rm -rf .venv; python3.8 -m venv .venv; source .venv/bin/activate; poetry lock; make sync_env

works as well. So let me update the toml, step by step

@bcm-at-zama
Copy link
Contributor Author

bcm-at-zama commented Jul 19, 2024

Still works after

diff --git a/pyproject.toml b/pyproject.toml
index 09556f4d..97f248ac 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -51,7 +51,7 @@ onnxoptimizer = "0.3.13"
 # onnxruntime versions supported by onnx versions and opsets can be found here : 
 # https://onnxruntime.ai/docs/reference/compatibility.html#onnx-opset-support
 onnxruntime = "1.18"
-hummingbird-ml = {version="0.4.8", extras = ["onnx"]}
+hummingbird-ml = {version="0.4.11", extras = ["onnx"]}
 scikit-learn = "1.1.3"
 scipy = "1.10.1"
 numpy = "1.23.5"
@@ -110,14 +110,6 @@ ruff = "^0.0.191"
 myst_parser = "0.19.1"
 flake8-bugbear = "23.2.13"
 flake8 = "6.0.0"
-# The following was inspired from https://github.com/python-poetry/poetry/issues/8271
-# Note: upgrading tensorflow to >= 2.14 requires dropping support for Python 3.8
-tensorflow = {version = "2.13.1"}
-tensorflow-macos = {version = "2.13.0", platform = "darwin", markers = "platform_machine=='arm64'" }
-tensorflow-metal = {version = "1.1.0", markers="sys_platform == 'darwin' and platform_machine == 'arm'"}
-tensorflow-io-gcs-filesystem = [
-    {version = "0.34.0", markers = "platform_machine!='arm64' or platform_system!='Darwin'" },
-]
 ipython = "^8.10.0"
 markdown-it-py = "2.2.0"
 torchvision = "0.14.1"
@@ -145,6 +137,7 @@ filterwarnings = [
     "ignore:lbfgs failed to converge,*:sklearn.exceptions.ConvergenceWarning",
     "ignore:Maximum number of iteration reached before convergence.*:sklearn.exceptions.ConvergenceWarning",
     "ignore:jax.xla_computation is deprecated. Please use the AOT APIs.",
+    "ignore:Named tensors and all their associated APIs*",
 ]
 
 [tool.semantic_release]

@bcm-at-zama
Copy link
Contributor Author

The first issue happens with

diff --git a/pyproject.toml b/pyproject.toml
index 97f248ac..b60d56e0 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -44,8 +44,8 @@ skops = {version = "0.5.0"}
 xgboost = "1.6.2"
 skorch = "0.11.0"
 torch = "1.13.1"
-typing-extensions = "4.5.0"
-brevitas = "0.8.0"
+typing-extensions = "^4.5.0"
+brevitas = "0.10.2"
 onnx = "1.16.1"
 onnxoptimizer = "0.3.13"
 # onnxruntime versions supported by onnx versions and opsets can be found here : 

It sync_env well, but it

  File "/Users/benoitchevalliermames/Documents/Zama/Git/concrete-ml/.venv/lib/python3.8/site-packages/brevitas/core/scaling/pre_scaling.py", line 198
    """Takes weights, input bit-width, and input sign as input and returns the pre-clipping
    ^
SyntaxError: invalid escape sequence \c

and

  File "/Users/benoitchevalliermames/Documents/Zama/Git/concrete-ml/.venv/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1337, in _preparse
    self.issue_config_time_warning(
  File "/Users/benoitchevalliermames/Documents/Zama/Git/concrete-ml/.venv/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1468, in issue_config_time_warning
    warnings.warn(warning, stacklevel=stacklevel)
pytest.PytestConfigWarning: could not load initial conftests: /Users/benoitchevalliermames/Documents/Zama/Git/concrete-ml/conftest.py
make[2]: *** [pytest_internal] Error 1
make[1]: *** [pytest_internal_parallel] Error 2
make: *** [pytest] Error 2

@bcm-at-zama
Copy link
Contributor Author

Works with

diff --git a/pyproject.toml b/pyproject.toml
index 97f248ac..f8fd56db 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -44,7 +44,7 @@ skops = {version = "0.5.0"}
 xgboost = "1.6.2"
 skorch = "0.11.0"
 torch = "1.13.1"
-typing-extensions = "4.5.0"
+typing-extensions = "^4.5.0"
 brevitas = "0.8.0"
 onnx = "1.16.1"
 onnxoptimizer = "0.3.13"

so the first issue is with brevitas

@bcm-at-zama
Copy link
Contributor Author

With

diff --git a/Makefile b/Makefile
index 3dd3d545..eb8f83e6 100644
--- a/Makefile
+++ b/Makefile
@@ -55,7 +55,7 @@ setup_env:
 
 	echo "Installing $(CONCRETE_PYTHON_VERSION)" && \
 	poetry run python -m pip install -U --pre --extra-index-url https://pypi.zama.ai/cpu "$(CONCRETE_PYTHON_VERSION)"
-	"$(MAKE)" fix_omp_issues_for_intel_mac
+	# "$(MAKE)" fix_omp_issues_for_intel_mac
 	poetry run python -c "import skorch" || true # Details above
 
 .PHONY: sync_env # Synchronise the environment
diff --git a/pyproject.toml b/pyproject.toml
index f8fd56db..62bd8e81 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -43,7 +43,7 @@ setuptools = "65.6.3"
 skops = {version = "0.5.0"}
 xgboost = "1.6.2"
 skorch = "0.11.0"
-torch = "1.13.1"
+torch = "2.2.2"
 typing-extensions = "^4.5.0"
 brevitas = "0.8.0"
 onnx = "1.16.1"
@@ -112,7 +112,7 @@ flake8-bugbear = "23.2.13"
 flake8 = "6.0.0"
 ipython = "^8.10.0"
 markdown-it-py = "2.2.0"
-torchvision = "0.14.1"
+torchvision = "0.17.2"
 
 [build-system]
 requires = ["poetry-core>=1.0.0"]

it installs but fails to run pytest. Possibly because of omp issues

@bcm-at-zama
Copy link
Contributor Author

Works for

git diff script Makefile pyproject.toml | cat
diff --git a/pyproject.toml b/pyproject.toml
index f8fd56db..62bd8e81 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -43,7 +43,7 @@ setuptools = "65.6.3"
 skops = {version = "0.5.0"}
 xgboost = "1.6.2"
 skorch = "0.11.0"
-torch = "1.13.1"
+torch = "2.2.2"
 typing-extensions = "^4.5.0"
 brevitas = "0.8.0"
 onnx = "1.16.1"
@@ -112,7 +112,7 @@ flake8-bugbear = "23.2.13"
 flake8 = "6.0.0"
 ipython = "^8.10.0"
 markdown-it-py = "2.2.0"
-torchvision = "0.14.1"
+torchvision = "0.17.2"
 
 [build-system]
 requires = ["poetry-core>=1.0.0"]
diff --git a/script/make_utils/fix_omp_issues_for_intel_mac.sh b/script/make_utils/fix_omp_issues_for_intel_mac.sh
index 826cf60f..89c701a9 100755
--- a/script/make_utils/fix_omp_issues_for_intel_mac.sh
+++ b/script/make_utils/fix_omp_issues_for_intel_mac.sh
@@ -3,7 +3,7 @@
 # Fix OMP issues for macOS Intel, https://github.com/zama-ai/concrete-ml-internal/issues/3951
 # This should be avoided for macOS with arm64 architecture
 
-set -ex
+set -e
 
 UNAME=$(uname)
 MACHINE=$(uname -m)
@@ -21,13 +21,36 @@ then
     WHICH_VENV=$(command -v python | sed -e "s@bin/python@@")
     WHICH_PYTHON=$(python -c 'import sys; print(f"python{sys.version_info.major}.{sys.version_info.minor}")')
 
+    # cd "${WHICH_VENV}"/lib/"${WHICH_PYTHON}"
+
+    # LIST_OF_OMP_DYLIBS=`find . -name "*omp*.dylib"`
+
+    # for X in $LIST_OF_OMP_DYLIBS
+    # do
+    #     if [[ "$X" != *"concrete"* ]]; then
+    #         echo "rm $X"
+    #         echo "ln -s .site-packages/concrete/.dylibs/libomp.dylib $X"
+    #     fi
+    # done
+
+    # exit -1
+
     # The error is specific to python version
     if [ "$PYTHON_VERSION" == "3.8" ] || [ "$PYTHON_VERSION" == "3.9" ]
     then
+        # rm "${WHICH_VENV}"/lib/"${WHICH_PYTHON}"/site-packages/torch/lib/libiomp5.dylib
+        # ln -s "${WHICH_VENV}"/lib/"${WHICH_PYTHON}"/site-packages/concrete/.dylibs/libomp.dylib "${WHICH_VENV}"/lib/"${WHICH_PYTHON}"/site-packages/torch/lib/libiomp5.dylib
+        # rm "${WHICH_VENV}"/lib/"${WHICH_PYTHON}"/site-packages/functorch/.dylibs/libiomp5.dylib
+        # ln -s "${WHICH_VENV}"/lib/"${WHICH_PYTHON}"/site-packages/concrete/.dylibs/libomp.dylib "${WHICH_VENV}"lib/"${WHICH_PYTHON}"/site-packages/functorch/.dylibs/libiomp5.dylib
+
+        rm "${WHICH_VENV}"/lib/"${WHICH_PYTHON}"/site-packages/xgboost/.dylibs/libomp.dylib
+        ln -s "${WHICH_VENV}"/lib/"${WHICH_PYTHON}"/site-packages/concrete/.dylibs/libomp.dylib "${WHICH_VENV}"/lib/"${WHICH_PYTHON}"/site-packages/xgboost/.dylibs/libomp.dylib
+        rm "${WHICH_VENV}"/lib/"${WHICH_PYTHON}"/site-packages/torch/.dylibs/libiomp5.dylib
+        ln -s "${WHICH_VENV}"/lib/"${WHICH_PYTHON}"/site-packages/concrete/.dylibs/libomp.dylib "${WHICH_VENV}"/lib/"${WHICH_PYTHON}"/site-packages/torch/.dylibs/libiomp5.dylib
         rm "${WHICH_VENV}"/lib/"${WHICH_PYTHON}"/site-packages/torch/lib/libiomp5.dylib
         ln -s "${WHICH_VENV}"/lib/"${WHICH_PYTHON}"/site-packages/concrete/.dylibs/libomp.dylib "${WHICH_VENV}"/lib/"${WHICH_PYTHON}"/site-packages/torch/lib/libiomp5.dylib
-        rm "${WHICH_VENV}"/lib/"${WHICH_PYTHON}"/site-packages/functorch/.dylibs/libiomp5.dylib
-        ln -s "${WHICH_VENV}"/lib/"${WHICH_PYTHON}"/site-packages/concrete/.dylibs/libomp.dylib "${WHICH_VENV}"lib/"${WHICH_PYTHON}"/site-packages/functorch/.dylibs/libiomp5.dylib
+        rm "${WHICH_VENV}"/lib/"${WHICH_PYTHON}"/site-packages/sklearn/.dylibs/libomp.dylib
+        ln -s "${WHICH_VENV}"/lib/"${WHICH_PYTHON}"/site-packages/concrete/.dylibs/libomp.dylib "${WHICH_VENV}"/lib/"${WHICH_PYTHON}"/site-packages/sklearn/.dylibs/libomp.dylib
 
     elif [ "$PYTHON_VERSION" == "3.10" ]
     then

That's a good sign

@bcm-at-zama
Copy link
Contributor Author

Able to make it work for 3.8 to 3.10 without changing brevitas for now. Now, trying to change brevitas

@bcm-at-zama
Copy link
Contributor Author

So, no:

git diff pyproject.toml
diff --git a/pyproject.toml b/pyproject.toml
index 62bd8e81..97130190 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -45,7 +45,7 @@ xgboost = "1.6.2"
 skorch = "0.11.0"
 torch = "2.2.2"
 typing-extensions = "^4.5.0"
-brevitas = "0.8.0"
+brevitas = "0.10.2"
 onnx = "1.16.1"
 onnxoptimizer = "0.3.13"
 # onnxruntime versions supported by onnx versions and opsets can be found here : 

makes it fail.

  File "/Users/benoitchevalliermames/Documents/Zama/Git/concrete-ml/.venv/lib/python3.10/site-packages/brevitas/core/scaling/pre_scaling.py", line 198
    """Takes weights, input bit-width, and input sign as input and returns the pre-clipping
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: invalid escape sequence '\c'

@bcm-at-zama
Copy link
Contributor Author

Will be superseded by #798

@bcm-at-zama bcm-at-zama changed the title fix: downgrade torch for mac intel support fix: downgrade torch for mac intel support [to be closed soon] Jul 19, 2024
@bcm-at-zama
Copy link
Contributor Author

Superseded by #798

@andrei-stoian-zama andrei-stoian-zama deleted the downgrade_torch_for_mac_intel_4547 branch October 17, 2024 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant