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

feat: add multi-output support #396

Merged
merged 2 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitleaksignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@
2d3b4ca188efb338c03d8d2c921ef39ffc5537e3:tests/deployment/test_deployment.py:generic-api-key:59
198d3fef188aaf3e3a582b9f7943f7ac6e9b5186:tests/deployment/test_deployment.py:generic-api-key:59
5abc7e86bb192e1f9f829bb2f22173c9d663e1d1:use_case_examples/credit_scoring/CreditScoringWithGraphics.ipynb:easypost-test-api-token:1414
e2904473898ddd325f245f4faca526a0e9520f49:builders/Dockerfile.zamalang-env:generic-api-key:5
a99389ee01cbb972e46a892d3d0e9c7f8ee23f59:use_case_examples/training/analyze.ipynb:easypost-api-token:4651
a99389ee01cbb972e46a892d3d0e9c7f8ee23f59:use_case_examples/training/analyze.ipynb:aws-access-token:18379
f41de03048a9ed27946b875e81b34138bb4bb17b:use_case_examples/training/analyze.ipynb:aws-access-token:6404
e2904473898ddd325f245f4faca526a0e9520f49:builders/Dockerfile.zamalang-env:generic-api-key:5
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ OPEN_PR="true"
# Force the installation of a Concrete Python version, which is very useful with nightly versions
# /!\ WARNING /!\: This version should NEVER be a wildcard as it might create some
# issues when trying to run it in the future.
CONCRETE_PYTHON_VERSION="concrete-python==2.5.0rc1"
CONCRETE_PYTHON_VERSION="concrete-python==2023.12.5"
jfrery marked this conversation as resolved.
Show resolved Hide resolved

# Force the installation of Concrete Python's latest version, release-candidates included
# CONCRETE_PYTHON_VERSION="$$(poetry run python \
Expand Down Expand Up @@ -47,7 +47,7 @@ setup_env:
fi

echo "Installing $(CONCRETE_PYTHON_VERSION)" && \
poetry run python -m pip install -U --pre "$(CONCRETE_PYTHON_VERSION)" --no-deps
poetry run python -m pip install -U --pre "$(CONCRETE_PYTHON_VERSION)"
Copy link
Collaborator

Choose a reason for hiding this comment

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

there was not a reason for us to have --no-deps?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure, but it breaks if we don't have dependencies

Copy link
Collaborator

Choose a reason for hiding this comment

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

weird but ok

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not so weird imo, my understanding is that before our dependencies were a superset of concrete-python's. Now that they need z3 for bit-width assignment this breaks on our side because we wouldn't be installing it with --no-deps

Copy link
Collaborator

@RomanBredehoft RomanBredehoft Dec 7, 2023

Choose a reason for hiding this comment

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

ok interesting then !

"$(MAKE)" fix_omp_issues_for_intel_mac

.PHONY: sync_env # Synchronise the environment
Expand Down
1 change: 0 additions & 1 deletion benchmarks/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@
enable_unsafe_features=True,
use_insecure_key_cache=True,
insecure_key_cache_location="ConcreteNumpyKeyCache",
jit=False,
)


Expand Down
4 changes: 2 additions & 2 deletions deps_licenses/licenses_linux_user.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ certifi, 2023.7.22, Mozilla Public License 2.0 (MPL 2.0)
charset-normalizer, 3.2.0, MIT License
click, 8.1.7, BSD License
coloredlogs, 15.0.1, MIT License
concrete-python, 2.5.0rc1, BSD-3-Clause
concrete-python, 2023.12.5, BSD-3-Clause
dependencies, 2.0.1, BSD License
dill, 0.3.7, BSD License
exceptiongroup, 1.1.3, MIT License
Expand Down Expand Up @@ -72,4 +72,4 @@ typing_extensions, 4.5.0, Python Software Foundation License
urllib3, 1.26.16, MIT License
uvicorn, 0.21.1, BSD License
xgboost, 1.6.2, Apache Software License
z3-solver, 4.12.2.0, MIT License
z3-solver, 4.12.3.0, MIT License
2 changes: 1 addition & 1 deletion deps_licenses/licenses_linux_user.txt.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6e23de913fba55c72e9420fdef5e78de
b19adb1c64bd8c6e86f8374568b1cca7
4 changes: 2 additions & 2 deletions deps_licenses/licenses_mac_intel_user.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ certifi, 2023.7.22, Mozilla Public License 2.0 (MPL 2.0)
charset-normalizer, 3.2.0, MIT License
click, 8.1.7, BSD License
coloredlogs, 15.0.1, MIT License
concrete-python, 2.5.0rc1, BSD-3-Clause
concrete-python, 2023.12.5, BSD-3-Clause
dependencies, 2.0.1, BSD License
dill, 0.3.7, BSD License
exceptiongroup, 1.1.3, MIT License
Expand Down Expand Up @@ -68,4 +68,4 @@ typing_extensions, 4.5.0, Python Software Foundation License
urllib3, 1.26.16, MIT License
uvicorn, 0.21.1, BSD License
xgboost, 1.6.2, Apache Software License
z3-solver, 4.12.2.0, MIT License
z3-solver, 4.12.3.0, MIT License
2 changes: 1 addition & 1 deletion deps_licenses/licenses_mac_intel_user.txt.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6e23de913fba55c72e9420fdef5e78de
b19adb1c64bd8c6e86f8374568b1cca7
4 changes: 2 additions & 2 deletions deps_licenses/licenses_mac_silicon_user.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ certifi, 2023.7.22, Mozilla Public License 2.0 (MPL 2.0)
charset-normalizer, 3.2.0, MIT License
click, 8.1.7, BSD License
coloredlogs, 15.0.1, MIT License
concrete-python, 2.5.0rc1, BSD-3-Clause
concrete-python, 2023.12.5, BSD-3-Clause
dependencies, 2.0.1, BSD License
dill, 0.3.7, BSD License
exceptiongroup, 1.1.3, MIT License
Expand Down Expand Up @@ -68,4 +68,4 @@ typing_extensions, 4.5.0, Python Software Foundation License
urllib3, 1.26.16, MIT License
uvicorn, 0.21.1, BSD License
xgboost, 1.6.2, Apache Software License
z3-solver, 4.12.2.0, MIT License
z3-solver, 4.12.3.0, MIT License
2 changes: 1 addition & 1 deletion deps_licenses/licenses_mac_silicon_user.txt.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6e23de913fba55c72e9420fdef5e78de
b19adb1c64bd8c6e86f8374568b1cca7
8,608 changes: 4,106 additions & 4,502 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ readme = "README.md"
# Investigate if it is better to fix specific versions or use lower and upper bounds
# FIXME: https://github.com/zama-ai/concrete-ml-internal/issues/2665
python = ">=3.8.1,<3.11"
concrete-python = "2.5.0-rc1 "
#concrete-python = "2023.11.5"
Copy link
Collaborator

Choose a reason for hiding this comment

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

is it right to comment this ? why not keeping the2.5.0-rc1 version to make poetry consider more realistic constraint in the dependencies to install ? this is an open question, not sure of this answer

Copy link
Collaborator Author

@fd0r fd0r Dec 7, 2023

Choose a reason for hiding this comment

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

I think it's best to comment if the value can't be installed by the user.

This way if a user tries to install main it will crash at import saying that it's missing Concrete Python instead of having the issue later on.

But not a strong opinion tbh.

Copy link
Collaborator

Choose a reason for hiding this comment

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

hmm got it yes, did not realize that for some times our public repo won't be possible to build from source by any external users since nightlies are private !

wonder if we could do something about that (tag the latest "CML commit usable from external users" ? avoid nightlies as much as possible ? don't know ! but not very important for now)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure how well pypi handles nightly but maybe we could publish the nightlies that we use to pypi if there is no IP blocker.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that's the main issue with nightly, I believe we don't want them to be public, only rc should

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe we should them for a rc once we see that the nightly is working for us?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I thought about it as well indeed, but at the same time @bcm-at-zama said that me way want to avoid too many public releases ! So maybe something to discuss about it, but from it looks like it may not be worth to put too much effort in all of this (we usually don't keep nightlies long enough). @andrei-stoian-zama seemed to say that we would ask for anticipated rc mostly if users ask for it

setuptools = "65.6.3"
skops = {version = "0.5.0"}
xgboost = "1.6.2"
Expand Down Expand Up @@ -150,3 +150,7 @@ line-length = 100
# The tool looks to report 'imported but unused (F401)' while actually the function is used by
# package which import the __init__.py
"**/__init__.py" = ["F401"]

# Add a setuptools_scm section to avoid warnings
[tool.setuptools_scm]
RomanBredehoft marked this conversation as resolved.
Show resolved Hide resolved

7 changes: 0 additions & 7 deletions src/concrete/ml/deployment/fhe_client_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,6 @@ def save(self, via_mlir: bool = False):
)
self.model.check_model_is_compiled()

# Model must be compiled with jit=False
# In a jit model, everything is in memory so it is not serializable.
assert_true(
not self.model.fhe_circuit.configuration.jit,
"The model must be compiled with the configuration option jit=False.",
)

# Export the quantizers
json_path = self._export_model_to_json()

Expand Down
8 changes: 5 additions & 3 deletions src/concrete/ml/onnx/onnx_impl_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import numpy
from concrete.fhe import conv as cnp_conv
from concrete.fhe import ones as cnp_ones
from concrete.fhe.tracing import Tracer

from ..common.debugging import assert_true

Expand All @@ -14,7 +15,7 @@ def numpy_onnx_pad(
pads: Tuple[int, ...],
pad_value: Union[float, int, numpy.ndarray] = 0,
int_only: bool = False,
) -> numpy.ndarray:
) -> Union[numpy.ndarray, Tracer]:
jfrery marked this conversation as resolved.
Show resolved Hide resolved
"""Pad a tensor according to ONNX spec, using an optional custom pad value.

Args:
Expand Down Expand Up @@ -52,6 +53,7 @@ def numpy_onnx_pad(
else:
# Floating point mode
x_pad = numpy.ones(padded_shape, dtype=numpy.float32) * pad_value
assert isinstance(x_pad, (numpy.ndarray, Tracer))

# Create the indices for slice assignment, copy all on batch size and channels dimension
indices = [slice(None), slice(None)] + [
Expand Down Expand Up @@ -159,7 +161,7 @@ def onnx_avgpool_compute_norm_const(
pads: Tuple[int, ...],
strides: Tuple[int, ...],
ceil_mode: int,
) -> Union[numpy.ndarray, float]:
) -> Union[numpy.ndarray, float, Tracer]:
"""Compute the average pooling normalization constant.

This constant can be a tensor of the same shape as the input or a scalar.
Expand Down Expand Up @@ -220,6 +222,6 @@ def onnx_avgpool_compute_norm_const(
else:
# For the PyTorch mode, only positions with all valid indices are used so
# the averaging is done over the number of cells in the kernel
norm_const = numpy.prod(kernel_shape)
norm_const = float(numpy.prod(numpy.array(kernel_shape)))

return norm_const
23 changes: 23 additions & 0 deletions src/concrete/ml/pytest/torch_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,29 @@
# pylint: disable=too-many-lines


class MultiOutputModel(nn.Module):
"""Multi-output model."""

def __init__(
self,
) -> None:
"""Torch Model."""
super().__init__()
self.value = 3.0

def forward(self, x, y):
"""Forward pass.

Args:
x (torch.Tensor): The input of the model.
y (torch.Tensor): The input of the model.

Returns:
Tuple[torch.Tensor. torch.Tensor]: Output of the network.
"""
return x + y + self.value, (x - y) ** 2
fd0r marked this conversation as resolved.
Show resolved Hide resolved


class SimpleNet(torch.nn.Module):
"""Fake torch model used to generate some onnx."""

Expand Down
Loading
Loading