diff --git a/script/make_utils/run_use_case_examples.sh b/script/make_utils/run_use_case_examples.sh index 4bf17dfe68..d678cc0e38 100755 --- a/script/make_utils/run_use_case_examples.sh +++ b/script/make_utils/run_use_case_examples.sh @@ -42,13 +42,17 @@ install_concrete_ml() { } install_requirements() { - if [ -f "requirements.txt" ]; then + local example_dir=$1 + if [ -f "${example_dir}/requirements.txt" ]; then + pushd "$example_dir" if pip install -r requirements.txt; then echo "Requirements installed successfully." else echo "Failed to install requirements." + popd return 1 fi + popd fi } @@ -64,12 +68,12 @@ run_example() { echo "*** Running example: $example_name ***" setup_virtualenv "$example_name" install_concrete_ml || return - install_requirements || return + install_requirements "$example_dir" || return echo "Running use case example using Makefile..." make -C "$example_dir" run_example - local result="${PIPESTATUS[0]}" + local result=$? if [ "$result" -ne 0 ]; then echo "Failure in example $example_name." diff --git a/use_case_examples/cifar/cifar_brevitas_finetuning/requirements.txt b/use_case_examples/cifar/cifar_brevitas_finetuning/requirements.txt deleted file mode 100644 index 9319c81c08..0000000000 --- a/use_case_examples/cifar/cifar_brevitas_finetuning/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -concrete-ml -jupyter -torchvision diff --git a/use_case_examples/cifar/cifar_brevitas_training/requirements.txt b/use_case_examples/cifar/cifar_brevitas_training/requirements.txt deleted file mode 100644 index 9319c81c08..0000000000 --- a/use_case_examples/cifar/cifar_brevitas_training/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -concrete-ml -jupyter -torchvision diff --git a/use_case_examples/credit_scoring/requirements.txt b/use_case_examples/credit_scoring/requirements.txt deleted file mode 100644 index 56b78ae9f5..0000000000 --- a/use_case_examples/credit_scoring/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -concrete-ml -jupyter -pandas diff --git a/use_case_examples/disease_prediction/requirements.txt b/use_case_examples/disease_prediction/requirements.txt deleted file mode 100644 index 1709ea8a17..0000000000 --- a/use_case_examples/disease_prediction/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -concrete-ml -jupyter -pandas -matplotlib diff --git a/use_case_examples/federated_learning/Makefile b/use_case_examples/federated_learning/Makefile index 6a5f3bd9bf..2f8985dea3 100644 --- a/use_case_examples/federated_learning/Makefile +++ b/use_case_examples/federated_learning/Makefile @@ -8,7 +8,9 @@ PYTHON_RUN=python run_example: run_sh load_to_cml run_sh: + @echo "Running federated learning training script..." @./run.sh load_to_cml: - @$(PYTHON_RUN) load_to_cml.py \ No newline at end of file + @echo "Loading and compiling the model with Concrete ML..." + @$(PYTHON_RUN) load_to_cml.py diff --git a/use_case_examples/federated_learning/requirements.txt b/use_case_examples/federated_learning/requirements.txt index 6aeb787dfe..e236308c1b 100644 --- a/use_case_examples/federated_learning/requirements.txt +++ b/use_case_examples/federated_learning/requirements.txt @@ -1,3 +1,2 @@ flwr~=1.4.0 openml~=0.13.1 -concrete-ml diff --git a/use_case_examples/hybrid_model/Makefile b/use_case_examples/hybrid_model/Makefile new file mode 100644 index 0000000000..c2ae4efdc8 --- /dev/null +++ b/use_case_examples/hybrid_model/Makefile @@ -0,0 +1,13 @@ +# Useful for jupyter notebooks +export LC_ALL=en_US.UTF-8 +export LANG=en_US.UTF-8 + +EXAMPLE_NAME=hybrid_model + +run_example: compile_model serve_model + +compile_model: + @python compile_hybrid_llm.py + +serve_model: + @./serve.sh \ No newline at end of file diff --git a/use_case_examples/titanic/KaggleTitanic.ipynb b/use_case_examples/titanic/KaggleTitanic.ipynb index f36516a249..cf10fe7006 100644 --- a/use_case_examples/titanic/KaggleTitanic.ipynb +++ b/use_case_examples/titanic/KaggleTitanic.ipynb @@ -26,16 +26,15 @@ "cell_type": "code", "execution_count": 1, "id": "7c415ea3", - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "No CUDA runtime is found, using CUDA_HOME='/usr/local/cuda'\n" - ] + "metadata": { + "execution": { + "iopub.execute_input": "2024-04-15T12:55:09.428391Z", + "iopub.status.busy": "2024-04-15T12:55:09.428217Z", + "iopub.status.idle": "2024-04-15T12:55:11.159927Z", + "shell.execute_reply": "2024-04-15T12:55:11.159435Z" } - ], + }, + "outputs": [], "source": [ "import time\n", "\n", @@ -52,7 +51,14 @@ "cell_type": "code", "execution_count": 2, "id": "ba063203", - "metadata": {}, + "metadata": { + "execution": { + "iopub.execute_input": "2024-04-15T12:55:11.162868Z", + "iopub.status.busy": "2024-04-15T12:55:11.162007Z", + "iopub.status.idle": "2024-04-15T12:55:11.196630Z", + "shell.execute_reply": "2024-04-15T12:55:11.196292Z" + } + }, "outputs": [ { "name": "stdout", @@ -67,7 +73,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "/tmp/virtualenv_titanic/lib/python3.8/site-packages/pandas/core/dtypes/common.py:1687: DeprecationWarning: Converting `np.inexact` or `np.floating` to a dtype is deprecated. The current result is `float64` which is not strictly correct.\n", + "/home/jfrery/concrete-ml/.venv/lib/python3.10/site-packages/pandas/core/dtypes/common.py:1691: DeprecationWarning: Converting `np.inexact` or `np.floating` to a dtype is deprecated. The current result is `float64` which is not strictly correct.\n", " npdtype = np.dtype(dtype)\n" ] } @@ -101,7 +107,14 @@ "cell_type": "code", "execution_count": 3, "id": "f5f3802c", - "metadata": {}, + "metadata": { + "execution": { + "iopub.execute_input": "2024-04-15T12:55:11.198427Z", + "iopub.status.busy": "2024-04-15T12:55:11.198262Z", + "iopub.status.idle": "2024-04-15T12:55:11.201790Z", + "shell.execute_reply": "2024-04-15T12:55:11.201503Z" + } + }, "outputs": [], "source": [ "train_data, test_data = train_test_split(all_data, test_size=len(all_data.index) - 891)\n", @@ -120,7 +133,14 @@ "cell_type": "code", "execution_count": 4, "id": "ae653f6f", - "metadata": {}, + "metadata": { + "execution": { + "iopub.execute_input": "2024-04-15T12:55:11.203432Z", + "iopub.status.busy": "2024-04-15T12:55:11.203226Z", + "iopub.status.idle": "2024-04-15T12:55:11.212412Z", + "shell.execute_reply": "2024-04-15T12:55:11.212153Z" + } + }, "outputs": [ { "data": { @@ -161,115 +181,108 @@ " \n", " \n", " \n", - " 995\n", + " 1297\n", " 3\n", " 0.0\n", - " Markoff, Mr. Marin\n", + " Wiseman, Mr. Phillippe\n", " male\n", - " 35.0\n", + " <NA>\n", " 0\n", " 0\n", - " 349213\n", - " 7.8958\n", + " A/4. 34244\n", + " 7.25\n", " <NA>\n", - " C\n", + " S\n", " <NA>\n", " <NA>\n", " <NA>\n", " \n", " \n", - " 1147\n", + " 778\n", " 3\n", - " 0.0\n", - " Riihivouri, Miss. Susanna Juhantytar 'Sanni'\n", + " 1.0\n", + " Dowdell, Miss. Elizabeth\n", " female\n", - " 22.0\n", + " 30.0\n", " 0\n", " 0\n", - " 3101295\n", - " 39.6875\n", + " 364516\n", + " 12.475\n", " <NA>\n", " S\n", + " 13\n", " <NA>\n", - " <NA>\n", - " <NA>\n", + " Union Hill, NJ\n", " \n", " \n", - " 485\n", - " 2\n", + " 921\n", + " 3\n", " 0.0\n", - " Levy, Mr. Rene Jacques\n", + " Keefe, Mr. Arthur\n", " male\n", - " 36.0\n", + " <NA>\n", " 0\n", " 0\n", - " SC/Paris 2163\n", - " 12.875\n", - " D\n", - " C\n", + " 323592\n", + " 7.25\n", + " <NA>\n", + " S\n", + " A\n", " <NA>\n", " <NA>\n", - " Montreal, PQ\n", " \n", " \n", - " 1265\n", - " 3\n", + " 313\n", + " 1\n", " 0.0\n", - " Van Impe, Miss. Catharina\n", - " female\n", - " 10.0\n", + " Widener, Mr. Harry Elkins\n", + " male\n", + " 27.0\n", " 0\n", " 2\n", - " 345773\n", - " 24.15\n", - " <NA>\n", - " S\n", - " <NA>\n", + " 113503\n", + " 211.5\n", + " C82\n", + " C\n", " <NA>\n", " <NA>\n", + " Elkins Park, PA\n", " \n", " \n", - " 632\n", - " 3\n", - " 0.0\n", - " Andersson, Mrs. Anders Johan (Alfrida Konstant...\n", + " 572\n", + " 2\n", + " 1.0\n", + " Trout, Mrs. William H (Jessie L)\n", " female\n", - " 39.0\n", - " 1\n", - " 5\n", - " 347082\n", - " 31.275\n", + " 28.0\n", + " 0\n", + " 0\n", + " 240929\n", + " 12.65\n", " <NA>\n", " S\n", " <NA>\n", " <NA>\n", - " Sweden Winnipeg, MN\n", + " Columbus, OH\n", " \n", " \n", "\n", "" ], "text/plain": [ - " pclass survived name \n", - "995 3 0.0 Markoff, Mr. Marin \\\n", - "1147 3 0.0 Riihivouri, Miss. Susanna Juhantytar 'Sanni' \n", - "485 2 0.0 Levy, Mr. Rene Jacques \n", - "1265 3 0.0 Van Impe, Miss. Catharina \n", - "632 3 0.0 Andersson, Mrs. Anders Johan (Alfrida Konstant... \n", - "\n", - " sex age sibsp parch ticket fare cabin embarked boat \n", - "995 male 35.0 0 0 349213 7.8958 C \\\n", - "1147 female 22.0 0 0 3101295 39.6875 S \n", - "485 male 36.0 0 0 SC/Paris 2163 12.875 D C \n", - "1265 female 10.0 0 2 345773 24.15 S \n", - "632 female 39.0 1 5 347082 31.275 S \n", + " pclass survived name sex age sibsp \\\n", + "1297 3 0.0 Wiseman, Mr. Phillippe male 0 \n", + "778 3 1.0 Dowdell, Miss. Elizabeth female 30.0 0 \n", + "921 3 0.0 Keefe, Mr. Arthur male 0 \n", + "313 1 0.0 Widener, Mr. Harry Elkins male 27.0 0 \n", + "572 2 1.0 Trout, Mrs. William H (Jessie L) female 28.0 0 \n", "\n", - " body home.dest \n", - "995 \n", - "1147 \n", - "485 Montreal, PQ \n", - "1265 \n", - "632 Sweden Winnipeg, MN " + " parch ticket fare cabin embarked boat body home.dest \n", + "1297 0 A/4. 34244 7.25 S \n", + "778 0 364516 12.475 S 13 Union Hill, NJ \n", + "921 0 323592 7.25 S A \n", + "313 2 113503 211.5 C82 C Elkins Park, PA \n", + "572 0 240929 12.65 S Columbus, OH " ] }, "execution_count": 4, @@ -304,9 +317,16 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "id": "737d6fdb", - "metadata": {}, + "metadata": { + "execution": { + "iopub.execute_input": "2024-04-15T12:55:11.214136Z", + "iopub.status.busy": "2024-04-15T12:55:11.213947Z", + "iopub.status.idle": "2024-04-15T12:55:11.217845Z", + "shell.execute_reply": "2024-04-15T12:55:11.217557Z" + } + }, "outputs": [ { "name": "stdout", @@ -317,16 +337,16 @@ "survived 0\n", "name 0\n", "sex 0\n", - "age 173\n", + "age 177\n", "sibsp 0\n", "parch 0\n", "ticket 0\n", - "fare 0\n", - "cabin 691\n", + "fare 1\n", + "cabin 698\n", "embarked 1\n", - "boat 556\n", - "body 806\n", - "home.dest 378\n", + "boat 560\n", + "body 809\n", + "home.dest 395\n", "dtype: int64 \n", "\n", "--- Test data ---\n", @@ -334,16 +354,16 @@ "survived 0\n", "name 0\n", "sex 0\n", - "age 90\n", + "age 86\n", "sibsp 0\n", "parch 0\n", "ticket 0\n", - "fare 1\n", - "cabin 323\n", + "fare 0\n", + "cabin 316\n", "embarked 1\n", - "boat 267\n", - "body 382\n", - "home.dest 186\n", + "boat 263\n", + "body 379\n", + "home.dest 169\n", "dtype: int64\n" ] } @@ -365,9 +385,16 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "id": "0266c622", - "metadata": {}, + "metadata": { + "execution": { + "iopub.execute_input": "2024-04-15T12:55:11.219358Z", + "iopub.status.busy": "2024-04-15T12:55:11.219153Z", + "iopub.status.idle": "2024-04-15T12:55:11.249595Z", + "shell.execute_reply": "2024-04-15T12:55:11.249220Z" + } + }, "outputs": [ { "name": "stdout", @@ -401,9 +428,16 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 7, "id": "35d9ceb9", - "metadata": {}, + "metadata": { + "execution": { + "iopub.execute_input": "2024-04-15T12:55:11.251751Z", + "iopub.status.busy": "2024-04-15T12:55:11.251563Z", + "iopub.status.idle": "2024-04-15T12:55:11.254924Z", + "shell.execute_reply": "2024-04-15T12:55:11.254563Z" + } + }, "outputs": [], "source": [ "drop_column = [\"cabin\", \"boat\", \"body\", \"home.dest\", \"ticket\"]\n", @@ -425,9 +459,16 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "id": "565ec656", - "metadata": {}, + "metadata": { + "execution": { + "iopub.execute_input": "2024-04-15T12:55:11.256816Z", + "iopub.status.busy": "2024-04-15T12:55:11.256648Z", + "iopub.status.idle": "2024-04-15T12:55:11.261945Z", + "shell.execute_reply": "2024-04-15T12:55:11.261391Z" + } + }, "outputs": [], "source": [ "for dataset in datasets:\n", @@ -457,9 +498,16 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 9, "id": "ff3e032d", - "metadata": {}, + "metadata": { + "execution": { + "iopub.execute_input": "2024-04-15T12:55:11.264353Z", + "iopub.status.busy": "2024-04-15T12:55:11.264087Z", + "iopub.status.idle": "2024-04-15T12:55:11.277380Z", + "shell.execute_reply": "2024-04-15T12:55:11.276939Z" + } + }, "outputs": [], "source": [ "def get_bin_labels(bin_name, number_of_bins):\n", @@ -498,9 +546,16 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 10, "id": "638f3f6c", - "metadata": {}, + "metadata": { + "execution": { + "iopub.execute_input": "2024-04-15T12:55:11.279217Z", + "iopub.status.busy": "2024-04-15T12:55:11.279066Z", + "iopub.status.idle": "2024-04-15T12:55:11.283409Z", + "shell.execute_reply": "2024-04-15T12:55:11.283123Z" + } + }, "outputs": [ { "name": "stdout", @@ -514,17 +569,17 @@ "Dr 8\n", "Rev 8\n", "Col 4\n", - "Ms 2\n", "Major 2\n", "Mlle 2\n", - "Lady 1\n", - "Mme 1\n", + "Ms 2\n", "Countess 1\n", - "Dona 1\n", - "Sir 1\n", - "Jonkheer 1\n", "Capt 1\n", + "Jonkheer 1\n", + "Dona 1\n", "Don 1\n", + "Sir 1\n", + "Mme 1\n", + "Lady 1\n", "Name: count, dtype: Int64\n" ] } @@ -545,9 +600,16 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 11, "id": "498273da", - "metadata": {}, + "metadata": { + "execution": { + "iopub.execute_input": "2024-04-15T12:55:11.285160Z", + "iopub.status.busy": "2024-04-15T12:55:11.284890Z", + "iopub.status.idle": "2024-04-15T12:55:11.288911Z", + "shell.execute_reply": "2024-04-15T12:55:11.288631Z" + } + }, "outputs": [], "source": [ "uncommon_titles = titles[titles < 10].index\n", @@ -570,9 +632,16 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 12, "id": "1b0539c6", - "metadata": {}, + "metadata": { + "execution": { + "iopub.execute_input": "2024-04-15T12:55:11.290520Z", + "iopub.status.busy": "2024-04-15T12:55:11.290265Z", + "iopub.status.idle": "2024-04-15T12:55:11.295907Z", + "shell.execute_reply": "2024-04-15T12:55:11.295643Z" + } + }, "outputs": [], "source": [ "categorical_features = train_data.select_dtypes(exclude=np.number).columns\n", @@ -590,9 +659,16 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 13, "id": "457b1c5d", - "metadata": {}, + "metadata": { + "execution": { + "iopub.execute_input": "2024-04-15T12:55:11.297593Z", + "iopub.status.busy": "2024-04-15T12:55:11.297397Z", + "iopub.status.idle": "2024-04-15T12:55:11.300068Z", + "shell.execute_reply": "2024-04-15T12:55:11.299798Z" + } + }, "outputs": [], "source": [ "target = \"survived\"\n", @@ -616,15 +692,22 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 14, "id": "2cc269e1", - "metadata": {}, + "metadata": { + "execution": { + "iopub.execute_input": "2024-04-15T12:55:11.301609Z", + "iopub.status.busy": "2024-04-15T12:55:11.301415Z", + "iopub.status.idle": "2024-04-15T12:55:16.553649Z", + "shell.execute_reply": "2024-04-15T12:55:16.553213Z" + } + }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Best hyper-parameters found in 7.98s : {'learning_rate': 1, 'max_depth': 2, 'n_estimators': 4}\n" + "Best hyper-parameters found in 5.25s : {'learning_rate': 0.01, 'max_depth': 3, 'n_estimators': 2}\n" ] } ], @@ -665,15 +748,22 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 15, "id": "9cc1cc89", - "metadata": {}, + "metadata": { + "execution": { + "iopub.execute_input": "2024-04-15T12:55:16.556569Z", + "iopub.status.busy": "2024-04-15T12:55:16.556203Z", + "iopub.status.idle": "2024-04-15T12:55:49.740591Z", + "shell.execute_reply": "2024-04-15T12:55:49.740199Z" + } + }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Best hyper-parameters found in 40.99s : {'learning_rate': 0.1, 'max_depth': 4, 'n_bits': 2, 'n_estimators': 4}\n" + "Best hyper-parameters found in 33.18s : {'learning_rate': 0.1, 'max_depth': 3, 'n_bits': 2, 'n_estimators': 2}\n" ] } ], @@ -708,17 +798,24 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 16, "id": "749c026d", - "metadata": {}, + "metadata": { + "execution": { + "iopub.execute_input": "2024-04-15T12:55:49.742583Z", + "iopub.status.busy": "2024-04-15T12:55:49.742381Z", + "iopub.status.idle": "2024-04-15T12:56:42.238154Z", + "shell.execute_reply": "2024-04-15T12:56:42.237575Z" + } + }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Key generation time: 0.94s\n", - "Total execution time for 418 inferences: 65.49s\n", - "Execution time per inference in FHE: 0.16s\n" + "Key generation time: 0.39s\n", + "Total execution time for 418 inferences: 51.77s\n", + "Execution time per inference in FHE: 0.12s\n" ] } ], @@ -761,16 +858,23 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 17, "id": "82bb69dd", - "metadata": {}, + "metadata": { + "execution": { + "iopub.execute_input": "2024-04-15T12:56:42.241154Z", + "iopub.status.busy": "2024-04-15T12:56:42.240625Z", + "iopub.status.idle": "2024-04-15T12:56:42.245207Z", + "shell.execute_reply": "2024-04-15T12:56:42.244763Z" + } + }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Prediction similarity between both Concrete ML models (quantized clear and FHE): 100.00%\n", - "Accuracy of prediction in FHE on the test set 78.23%\n" + "Accuracy of prediction in FHE on the test set 81.10%\n" ] } ], @@ -800,6 +904,18 @@ "metadata": { "execution": { "timeout": 10800 + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.12" } }, "nbformat": 4, diff --git a/use_case_examples/titanic/requirements.txt b/use_case_examples/titanic/requirements.txt deleted file mode 100644 index 56b78ae9f5..0000000000 --- a/use_case_examples/titanic/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -concrete-ml -jupyter -pandas