mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-08 19:44:57 -05:00
refactor: add concrete.onnx mod with previous conv2d
the module is meant to contain machine learning operations as defined by ONNX
This commit is contained in:
@@ -10,6 +10,6 @@ from .compilation import (
|
||||
EncryptionStatus,
|
||||
compiler,
|
||||
)
|
||||
from .extensions import LookupTable, conv2d
|
||||
from .extensions import LookupTable
|
||||
from .mlir.utils import MAXIMUM_BIT_WIDTH
|
||||
from .representation import Graph
|
||||
|
||||
@@ -2,5 +2,4 @@
|
||||
Provide additional features that are not present in numpy.
|
||||
"""
|
||||
|
||||
from .convolution import conv2d
|
||||
from .table import LookupTable
|
||||
|
||||
5
concrete/onnx/__init__.py
Normal file
5
concrete/onnx/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
"""
|
||||
Implement machine learning operations as specified by ONNX.
|
||||
"""
|
||||
|
||||
from .convolution import conv2d
|
||||
@@ -8,9 +8,9 @@ from typing import List, Optional, Tuple, Union
|
||||
import numpy as np
|
||||
import torch
|
||||
|
||||
from ..representation import Node
|
||||
from ..tracing import Tracer
|
||||
from ..values import EncryptedTensor
|
||||
from ..numpy.representation import Node
|
||||
from ..numpy.tracing import Tracer
|
||||
from ..numpy.values import EncryptedTensor
|
||||
|
||||
SUPPORTED_AUTO_PAD = {
|
||||
"NOTSET",
|
||||
@@ -6,6 +6,7 @@ import numpy as np
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
import concrete.onnx as connx
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -56,7 +57,7 @@ def test_conv2d(input_shape, weight_shape, strides, dilations, has_bias, helpers
|
||||
|
||||
@cnp.compiler({"x": "encrypted"}, configuration=configuration)
|
||||
def function(x):
|
||||
return cnp.conv2d(x, weight, bias, strides=strides, dilations=dilations)
|
||||
return connx.conv2d(x, weight, bias, strides=strides, dilations=dilations)
|
||||
|
||||
inputset = [np.random.randint(0, 4, size=input_shape) for i in range(100)]
|
||||
circuit = function.compile(inputset)
|
||||
@@ -177,7 +178,7 @@ def test_bad_conv2d_tracing(
|
||||
|
||||
@cnp.compiler({"x": "encrypted"}, configuration=configuration)
|
||||
def function(x):
|
||||
return cnp.conv2d(x, weight, bias, pads, strides, dilations, auto_pad)
|
||||
return connx.conv2d(x, weight, bias, pads, strides, dilations, auto_pad)
|
||||
|
||||
inputset = [np.random.randint(0, 4, size=input_shape) for i in range(100)]
|
||||
with pytest.raises(expected_error) as excinfo:
|
||||
@@ -194,13 +195,13 @@ def test_bad_conv2d_evaluation():
|
||||
x = np.random.randint(0, 4, size=(1, 1, 4, 4))
|
||||
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
cnp.conv2d(x, "abc")
|
||||
connx.conv2d(x, "abc")
|
||||
|
||||
assert str(excinfo.value) == "Weight should be of type np.ndarray for evaluation"
|
||||
|
||||
weight = np.random.randint(0, 4, size=(1, 1, 2, 2))
|
||||
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
cnp.conv2d(x, weight, "abc")
|
||||
connx.conv2d(x, weight, "abc")
|
||||
|
||||
assert str(excinfo.value) == "Bias should be of type np.ndarray for evaluation"
|
||||
|
||||
@@ -6,6 +6,7 @@ import numpy as np
|
||||
import pytest
|
||||
|
||||
import concrete.numpy as cnp
|
||||
import concrete.onnx as connx
|
||||
|
||||
# pylint: disable=line-too-long
|
||||
|
||||
@@ -91,7 +92,7 @@ return %2
|
||||
""", # noqa: E501
|
||||
),
|
||||
pytest.param(
|
||||
lambda x, w: cnp.conv2d(x, w),
|
||||
lambda x, w: connx.conv2d(x, w),
|
||||
{"x": "encrypted", "w": "encrypted"},
|
||||
[
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user