Getting error(compiling the simple example) in concrete-ML

!pip install virtualenv
!virtualenv venv
!source venv/bin/activate
!pip install -U pip wheel setuptools

!pip install concrete-ml

from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from concrete.ml.sklearn import LogisticRegression

Lets create a synthetic data-set

x, y = make_classification(n_samples=100, class_sep=2, n_features=30, random_state=42)

Split the data-set into a train and test set

X_train, X_test, y_train, y_test = train_test_split(
x, y, test_size=0.2, random_state=42
)

Now we train in the clear and quantize the weights

model = LogisticRegression(n_bits=8)
model.fit(X_train, y_train)

We can simulate the predictions in the clear

y_pred_clear = model.predict(X_test)

We then compile on a representative set

model.compile(X_train)

Finally we run the inference on encrypted inputs !

y_pred_fhe = model.predict(X_test, fhe=“execute”)

print(“In clear :”, y_pred_clear)
print(“In FHE :”, y_pred_fhe)
print(f"Similarity: {int((y_pred_fhe == y_pred_clear).mean()*100)}%")

Output:

# In clear  : [0 0 0 0 1 0 1 0 1 1 0 0 1 0 0 1 1 1 0 0]
# In FHE    : [0 0 0 0 1 0 1 0 1 1 0 0 1 0 0 1 1 1 0 0]
# Similarity: 100%

RuntimeError Traceback (most recent call last)
RuntimeError: module compiled against API version 0x10 but this version of numpy is 0xf

ImportError Traceback (most recent call last)
in <cell line: 1>()
----> 1 from sklearn.datasets import make_classification
2 from sklearn.model_selection import train_test_split
3 from concrete.ml.sklearn import LogisticRegression
4
5 # Lets create a synthetic data-set

7 frames
/usr/local/lib/python3.10/dist-packages/numpy/testing/_private/utils.py in
23 intp, float32, empty, arange, array_repr, ndarray, isnat, array)
24 from numpy import isfinite, isnan, isinf
—> 25 import numpy.linalg.lapack_lite
26
27 from io import StringIO

ImportError: numpy.core.multiarray failed to import

Hello @Rish,
Are you using Google Collab ? Also, could you give us the different versions (mostly concrete-ml and numpy) you are using (with pip show for example) ?

Thanks !

Yes ,I am running it in colab…
Here are the results from (pip show)
Name: concrete-ml
Version: 1.1.0
Name: numpy
Version: 1.23.5

Thanks for your quick answer ! I was able to reproduce the error indeed, but I believe that restarting the runtime and executing the cells made it working ! Do you confirm that this is also your case ?

Ya thankyou ,it worked(but can you explain whats the use of onnx ,is concrete-ml compatible with gpus while inferencing)
Just to confirm I believe all the use case examples(mentioned in concerete-ml github) will run in google colab,is that so?

You’re welcome, great to know that it works well :slightly_smiling_face:

We did not try to run our use case examples on google collab, but we have no reason to believe that it won’t work ! We have only tested them using Jupyter notebooks.

Regarding GPUs, unfortunately it is not yet supported in Concrete-ML.

Finally, ONNX is a frameworks that lets us easily import models (from Torch, Keras) and compile them for FHE execution. Feel free to have a look at our documentation page on this topic :grin:

Hope this helps !

Thannkyou for assisting me in my initial journey of concrete ML

2 Likes