Skip to content

Commit

Permalink
feat: upgrade pytorch to 2.3.1, brevitas to 0.10 (#788)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-stoian-zama authored Jul 17, 2024
1 parent 89f2db1 commit c3d7c81
Show file tree
Hide file tree
Showing 23 changed files with 852 additions and 1,223 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ setup_env:
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
poetry run python -c "import skorch" || true # Details above
poetry run python -c "from brevitas.core.scaling import AccumulatorAwareParameterPreScaling" || true # Details above

.PHONY: sync_env # Synchronise the environment
sync_env:
Expand Down
41 changes: 27 additions & 14 deletions deps_licenses/licenses_linux_user.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,42 @@
Name, Version, License
Jinja2, 3.1.4, BSD License
MarkupSafe, 2.1.5, BSD License
PyYAML, 6.0.1, MIT License
brevitas, 0.8.0, UNKNOWN
certifi, 2024.6.2, Mozilla Public License 2.0 (MPL 2.0)
brevitas, 0.10.2, UNKNOWN
certifi, 2024.7.4, Mozilla Public License 2.0 (MPL 2.0)
charset-normalizer, 3.3.2, MIT License
coloredlogs, 15.0.1, MIT License
concrete-python, 2.7.0, BSD-3-Clause
dependencies, 2.0.1, BSD License
dill, 0.3.8, BSD License
filelock, 3.15.3, The Unlicense (Unlicense)
filelock, 3.15.4, The Unlicense (Unlicense)
flatbuffers, 24.3.25, Apache Software License
fsspec, 2024.6.0, BSD License
fsspec, 2024.6.1, BSD License
huggingface-hub, 0.23.4, Apache Software License
humanfriendly, 10.0, MIT License
hummingbird-ml, 0.4.8, MIT License
hummingbird-ml, 0.4.11, MIT License
idna, 3.7, BSD License
importlib_resources, 6.4.0, Apache Software License
joblib, 1.4.2, BSD License
jsonpickle, 3.2.2, BSD License
mpmath, 1.3.0, BSD License
networkx, 3.1, BSD License
numpy, 1.23.5, BSD License
nvidia-cublas-cu11, 11.10.3.66, Other/Proprietary License
nvidia-cuda-nvrtc-cu11, 11.7.99, Other/Proprietary License
nvidia-cuda-runtime-cu11, 11.7.99, Other/Proprietary License
nvidia-cudnn-cu11, 8.5.0.96, Other/Proprietary License
nvidia-cublas-cu12, 12.1.3.1, Other/Proprietary License
nvidia-cuda-cupti-cu12, 12.1.105, Other/Proprietary License
nvidia-cuda-nvrtc-cu12, 12.1.105, Other/Proprietary License
nvidia-cuda-runtime-cu12, 12.1.105, Other/Proprietary License
nvidia-cudnn-cu12, 8.9.2.26, Other/Proprietary License
nvidia-cufft-cu12, 11.0.2.54, Other/Proprietary License
nvidia-curand-cu12, 10.3.2.106, Other/Proprietary License
nvidia-cusolver-cu12, 11.4.5.107, Other/Proprietary License
nvidia-cusparse-cu12, 12.1.0.106, Other/Proprietary License
nvidia-nccl-cu12, 2.20.5, Other/Proprietary License
nvidia-nvjitlink-cu12, 12.5.82, Other/Proprietary License
nvidia-nvtx-cu12, 12.1.105, Other/Proprietary License
onnx, 1.16.1, Apache License v2.0
onnxconverter-common, 1.13.0, MIT License
onnxmltools, 1.11.0, Apache Software License
onnxmltools, 1.12.0, Apache Software License
onnxoptimizer, 0.3.13, Apache License v2.0
onnxruntime, 1.18.0, MIT License
packaging, 24.1, Apache Software License; BSD License
Expand All @@ -39,16 +49,19 @@ requests, 2.32.3, Apache Software License
scikit-learn, 1.1.3, BSD License
scipy, 1.10.1, BSD License
six, 1.16.0, MIT License
skl2onnx, 1.12, Apache Software License
skl2onnx, 1.17.0, Apache Software License
skops, 0.5.0, MIT
skorch, 0.11.0, new BSD 3-Clause
sympy, 1.12.1, BSD License
sympy, 1.13.0, BSD License
tabulate, 0.8.10, MIT License
threadpoolctl, 3.5.0, BSD License
torch, 1.13.1, BSD License
torch, 2.3.1, BSD License
tqdm, 4.66.4, MIT License; Mozilla Public License 2.0 (MPL 2.0)
typing_extensions, 4.5.0, Python Software Foundation License
triton, 2.3.1, MIT License
typing_extensions, 4.12.2, Python Software Foundation License
tzdata, 2024.1, Apache Software License
unfoldNd, 0.2.2, MIT License
urllib3, 2.2.2, MIT License
xgboost, 1.6.2, Apache Software License
z3-solver, 4.13.0.0, MIT License
zipp, 3.19.2, 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 @@
adb925c3b7be3e651975febcf49b6543
6d367701c3ef5eff8763f4e994e03681
40 changes: 4 additions & 36 deletions docs/deep-learning/onnx_support.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,22 @@ This example uses Post-Training Quantization, i.e., the quantization is not perf
```python
import numpy
import onnx
import tensorflow
import tf2onnx

from concrete.ml.torch.compile import compile_onnx_model
from concrete.fhe.compilation import Configuration


class FC(tensorflow.keras.Model):
"""A fully-connected model."""

def __init__(self):
super().__init__()
hidden_layer_size = 10
output_size = 5

self.dense1 = tensorflow.keras.layers.Dense(
hidden_layer_size,
activation=tensorflow.nn.relu,
)
self.dense2 = tensorflow.keras.layers.Dense(output_size, activation=tensorflow.nn.relu6)
self.flatten = tensorflow.keras.layers.Flatten()

def call(self, inputs):
"""Forward function."""
x = self.flatten(inputs)
x = self.dense1(x)
x = self.dense2(x)
return self.flatten(x)


n_bits = 6
input_output_feature = 2
input_output_feature = 5
input_shape = (input_output_feature,)
num_inputs = 1
n_examples = 5000

# Define the Keras model
keras_model = FC()
keras_model.build((None,) + input_shape)
keras_model.compute_output_shape(input_shape=(None, input_output_feature))

# Create random input
input_set = numpy.random.uniform(-100, 100, size=(n_examples, *input_shape))

# Convert to ONNX
tf2onnx.convert.from_keras(keras_model, opset=14, output_path="tmp.model.onnx")

onnx_model = onnx.load("tmp.model.onnx")
onnx_model = onnx.load(f"tests/data/tf_onnx/fc_{input_output_feature}.onnx")
onnx.checker.check_model(onnx_model)

# Compile
Expand All @@ -83,7 +51,7 @@ print("Equality: ", numpy.sum(y_clear == y_fhe), "over", numpy.size(y_
```

{% hint style="warning" %}
While Keras was used in this example, it is not officially supported. Additional work is needed to test all of Keras's types of layers and models.
While a Keras ONNX model was used in this example, Keras/Tensorflow support in Concrete ML is only partial and experimental.
{% endhint %}

## Quantization Aware Training
Expand All @@ -106,7 +74,7 @@ quantized_numpy_module = compile_onnx_model(

## Supported operators

The following operators are supported for evaluation and conversion to an equivalent FHE circuit. Other operators were not implemented, either due to FHE constraints or because they are rarely used in PyTorch activations or scikit-learn models.
The following ONNX operators are supported for evaluation and conversion to an equivalent FHE circuit. Other operators were not implemented, either due to FHE constraints or because they are rarely used in PyTorch activations or scikit-learn models.

<!--- gen_supported_ops.py: inject supported operations for evaluation [BEGIN] -->

Expand Down
1 change: 0 additions & 1 deletion docs/deep-learning/torch_support.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ Concrete ML also supports some of their QAT equivalents from Brevitas.
- [`torch.nn.CELU`](https://pytorch.org/docs/stable/generated/torch.nn.CELU.html)
- [`torch.nn.ELU`](https://pytorch.org/docs/stable/generated/torch.nn.ELU.html)
- [`torch.nn.GELU`](https://pytorch.org/docs/stable/generated/torch.nn.GELU.html)
- [`torch.nn.Hardshrink`](https://pytorch.org/docs/stable/generated/torch.nn.Hardshrink.html)
- [`torch.nn.HardSigmoid`](https://pytorch.org/docs/stable/generated/torch.nn.Hardsigmoid.html)
- [`torch.nn.Hardswish`](https://pytorch.org/docs/stable/generated/torch.nn.Hardswish)
- [`torch.nn.HardTanh`](https://pytorch.org/docs/stable/generated/torch.nn.Hardtanh.html)
Expand Down
Loading

0 comments on commit c3d7c81

Please sign in to comment.