Skip to content

Commit

Permalink
Merge branch 'develop' into pr/578
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelDkhn committed Mar 4, 2024
2 parents f10ad77 + 8db8684 commit de42865
Show file tree
Hide file tree
Showing 255 changed files with 4,304 additions and 6,204 deletions.
30 changes: 29 additions & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,43 @@
"profile": "https://github.com/tekkac",
"contributions": [
"doc"
],
]
},
{
"login": "canacechan",
"name": "canacechan",
"avatar_url": "https://avatars.githubusercontent.com/u/127183619?v=4",
"profile": "https://github.com/canacechan",
"contributions": [
"code"
]
},
{
"login": "TAdev0",
"name": "Tristan",
"avatar_url": "https://avatars.githubusercontent.com/u/122918260?v=4",
"profile": "https://nodeguardians.io/character/98995858fd55 ",
"contributions": [
"code"
]
},
{
"login": "Gakunt",
"name": "Kugo",
"avatar_url": "https://avatars.githubusercontent.com/u/153402253?v=4",
"profile": "https://github.com/Gakunt",
"contributions": [
"doc"
]
},
{
"login": "FriendlyLifeguard",
"name": "Beeyoung",
"avatar_url": "https://avatars.githubusercontent.com/u/55970530?v=4",
"profile": "http://alankang.xyz",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 7,
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

# Orion: An Open-source Framework for Validity and ZK ML ✨
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-30-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-32-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

Orion is an open-source, community-driven framework dedicated to Provable Machine Learning. It provides essential components and a new ONNX runtime for building verifiable Machine Learning models using [STARKs](https://starkware.co/stark/).
Expand Down Expand Up @@ -57,7 +57,7 @@ For a full list of all authors and contributors, see [the contributors page](htt

This project is licensed under the **MIT license**.

See [LICENSE](https://github.com/franalgaba/onnx-cairo/blob/main/LICENSE/README.md) for more information.
See [LICENSE](https://github.com/franalgaba/onnx-cairo/blob/main/LICENSE) for more information.

## Contributors ✨

Expand Down Expand Up @@ -108,6 +108,9 @@ Thanks goes to these wonderful people:
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Vid201"><img src="https://avatars.githubusercontent.com/u/38610409?v=4?s=100" width="100px;" alt="Vid Kersic"/><br /><sub><b>Vid Kersic</b></sub></a><br /><a href="https://github.com/gizatechxyz/orion/commits?author=Vid201" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/tekkac"><img src="https://avatars.githubusercontent.com/u/98529704?v=4?s=100" width="100px;" alt="Trunks @ Carbonable"/><br /><sub><b>Trunks @ Carbonable</b></sub></a><br /><a href="https://github.com/gizatechxyz/orion/commits?author=tekkac" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/canacechan"><img src="https://avatars.githubusercontent.com/u/127183619?v=4?s=100" width="100px;" alt="canacechan"/><br /><sub><b>canacechan</b></sub></a><br /><a href="https://github.com/gizatechxyz/orion/commits?author=canacechan" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://nodeguardians.io/character/98995858fd55 "><img src="https://avatars.githubusercontent.com/u/122918260?v=4?s=100" width="100px;" alt="Tristan"/><br /><sub><b>Tristan</b></sub></a><br /><a href="https://github.com/gizatechxyz/orion/commits?author=TAdev0" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Gakunt"><img src="https://avatars.githubusercontent.com/u/153402253?v=4?s=100" width="100px;" alt="Kugo"/><br /><sub><b>Kugo</b></sub></a><br /><a href="https://github.com/gizatechxyz/orion/commits?author=Gakunt" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="http://alankang.xyz"><img src="https://avatars.githubusercontent.com/u/55970530?v=4?s=100" width="100px;" alt="Beeyoung"/><br /><sub><b>Beeyoung</b></sub></a><br /><a href="https://github.com/gizatechxyz/orion/commits?author=FriendlyLifeguard" title="Code">💻</a></td>
</tr>
</tbody>
</table>
Expand Down
1 change: 1 addition & 0 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
* [tensor.not](framework/operators/tensor/tensor.not.md)
* [tensor.erf](framework/operators/tensor/tensor.erf.md)
* [tensor.reduce\_log\_sum](framework/operators/tensor/tensor.reduce\_log\_sum.md)
* [tensor.reduce\_log\_sum\_exp](framework/operators/tensor/tensor.reduce\_log\_sum\_exp.md)
* [tensor.unique](framework/operators/tensor/tensor.unique.md)
* [tensor.compress](framework/operators/tensor/tensor.compress.md)
* [tensor.layer_normalization](framework/operators/tensor/tensor.layer_normalization.md)
Expand Down
1 change: 1 addition & 0 deletions docs/framework/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ You can see below the list of current supported ONNX Operators:
| [ReduceLogSum](operators/tensor/tensor.reduce\_log\_sum.md) | :white\_check\_mark: |
| [Erf](operators/tensor/tensor.erf.md) | :white\_check\_mark: |
| [Compress](operators/tensor/tensor.compress.md) | :white\_check\_mark: |
| [ReduceLogSumExp](operators/tensor/tensor.reduce\_log\_sum\_exp.md) | :white\_check\_mark: |
| [Layer_normalization](operators/tensor/tensor.layer_normalization.md) | :white\_check\_mark: |
| [ScatterND](operators/tensor/tensor.scatter/_nd.md) | :white\_check\_mark: |
| [DequantizeLinear](operators/tensor/tensor.dequantize_linear.md) | :white\_check\_mark: |
Expand Down
1 change: 1 addition & 0 deletions docs/framework/numbers/fixed-point/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ use orion::numbers::fixed_point::core::FixedTrait;
| [`fp.sinh`](fp.sinh.md) | Returns the value of the hyperbolic sine of the fixed point number. |
| [`fp.tanh`](fp.tanh.md) | Returns the value of the hyperbolic tangent of the fixed point number. |
| [`fp.sign`](fp.sign.md) | Returns the element-wise indication of the sign of the input fixed point number. |
| [`fp.erf`](fp.erf.md) | Returns the error function of the input fixed point number computed element-wise. |

### Arithmetic & Comparison operators

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# LinearClassifierTrait::predict

```rust
fn predict(ref self: LinearClassifier<T>, X: Tensor<T>) -> Tensor<T>;
fn predict(classifier: LinearClassifier<T>, X: Tensor<T>) -> Tensor<T>;
```

Linear Classifier. Performs the linear classification.
Expand Down Expand Up @@ -85,7 +85,7 @@ fn linear_classifier_helper(
fn linear_classifier_multi_softmax() -> (Span<usize>, Tensor<FP16x16>) {
let (mut classifier, X) = linear_classifier_helper(POST_TRANSFORM::SOFTMAX);

let (labels, mut scores) = LinearClassifierTrait::predict(ref classifier, X);
let (labels, mut scores) = LinearClassifierTrait::predict(classifier, X);

(labels, scores)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# LinearRegressorTrait::predict

```rust
fn predict(ref self: LinearRegressor<T>, X: Tensor<T>) -> Tensor<T>;
fn predict(regressor: LinearRegressor<T>, X: Tensor<T>) -> Tensor<T>;
```

Linear Regressor. Performs the generalized linear regression evaluation.

## Args

* `self`: LinearRegressor<T> - A LinearRegressor object.
* `regressor`: LinearRegressor<T> - A LinearRegressor object.
* `X`: Input 2D tensor.

## Returns
Expand Down Expand Up @@ -68,7 +68,7 @@ fn example_linear_regressor() -> Tensor<FP16x16> {
post_transform
};

let scores = LinearRegressorTrait::predict(ref regressor, X);
let scores = LinearRegressorTrait::predict(regressor, X);

scores
}
Expand Down Expand Up @@ -120,7 +120,7 @@ fn example_linear_regressor_2() -> Tensor<FP16x16> {
post_transform
};

let scores = LinearRegressorTrait::predict(ref regressor, X);
let scores = LinearRegressorTrait::predict(regressor, X);

scores
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# TreeEnsembleClassifier::predict

```rust
fn predict(ref self: TreeEnsembleClassifier<T>, X: Tensor<T>) -> (Span<usize>, MutMatrix::<T>);
fn predict(classifier: TreeEnsembleClassifier<T>, X: Tensor<T>) -> (Span<usize>, MutMatrix::<T>);
```

Tree Ensemble classifier. Returns the top class for each of N inputs.
Expand Down Expand Up @@ -185,7 +185,7 @@ fn tree_ensemble_classifier_helper(
fn test_tree_ensemble_classifier_multi_pt_softmax() -> (Span<usize>, MutMatrix::<FP16x16>) {
let (mut classifier, X) = tree_ensemble_classifier_helper(POST_TRANSFORM::SOFTMAX);

let (labels, scores) = TreeEnsembleClassifierTrait::predict(ref classifier, X);
let (labels, scores) = TreeEnsembleClassifierTrait::predict(classifier, X);
(labels, scores)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# TreeEnsembleRegressor::predict

```rust
fn predict(ref self: TreeEnsembleRegressor<T>, X: Tensor<T>) -> (Span<usize>, MutMatrix::<T>);
fn predict(regressor: TreeEnsembleRegressor<T>, X: Tensor<T>) -> (Span<usize>, MutMatrix::<T>);
```

Tree Ensemble regressor. Returns the regressed values for each input in N.
Expand Down Expand Up @@ -160,7 +160,7 @@ fn tree_ensemble_regressor_helper(

fn test_tree_ensemble_regressor_SUM() -> MutMatrix::<FP16x16> {
let (mut regressor, X) = tree_ensemble_regressor_helper(AGGREGATE_FUNCTION::SUM);
let mut res = TreeEnsembleRegressorTrait::predict(ref regressor, X);
let mut res = TreeEnsembleRegressorTrait::predict(regressor, X);
res
}
>>>
Expand Down
4 changes: 2 additions & 2 deletions docs/framework/operators/neural-network/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ Orion supports currently these `NN` types.
| [`nn.gemm`](nn.gemm.md) | Performs General Matrix multiplication. |
| [`nn.grid_sample`](nn.grid\_sample.md) | Computes the grid sample of the input tensor and input grid. |
| [`nn.col2im`](nn.col2im.md) | Rearranges column blocks back into a multidimensional image |
| [`nn.conv_transpose`](nn.conv\_transpose.md) | Performs the convolution transpose of the input data tensor and weigth tensor. |
| [`nn.conv`](nn.conv.md) | Performs the convolution of the input data tensor and weigth tensor. |
| [`nn.conv_transpose`](nn.conv\_transpose.md) | Performs the convolution transpose of the input data tensor and weight tensor. |
| [`nn.conv`](nn.conv.md) | Performs the convolution of the input data tensor and weight tensor. |

2 changes: 1 addition & 1 deletion docs/framework/operators/neural-network/nn.conv.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
) -> Tensor<T>
```

The convolution operator consumes an input tensor and a filter (input weigth tensor), and computes the output.
The convolution operator consumes an input tensor and a filter (input weight tensor), and computes the output.

## Args

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
) -> Tensor<T>
```

The convolution transpose operator consumes an input tensor and a input weigth tensor, and computes the output.
The convolution transpose operator consumes an input tensor and a input weight tensor, and computes the output.

## Args

Expand Down
1 change: 1 addition & 0 deletions docs/framework/operators/tensor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ use orion::operators::tensor::TensorTrait;
| [`tensor.gather_nd`](tensor.gather\_nd.md) | Given data tensor of rank r >= 1, indices tensor of rank q >= 1, and batch_dims integer b, this operator gathers slices of data into an output tensor of rank q + r - indices_shape[-1] - 1 - b. |
| [`tensor.reduce_log_sum`](tensor.reduce\_log\_sum.md) | Computes the log sum of the input tensor's elements along the provided axes. |
| [`tensor.erf`](tensor.erf.md) | Computes the error function of the given input tensor element-wise. |
| [`tensor.reduce_log_sum_exp`](tensor.reduce\_log\_sum\_exp.md) | Computes the log sum of the exponentials of the input tensor's elements along the provided axes. |
| [`tensor.layer_normalization`](tensor.layer\_normalization.md) | computes the layer normalization of the input tensor. |
| [`tensor.split`](tensor.split.md) | Split a tensor into a list of tensors, along the specified ‘axis’. |
| [`tensor.random_uniform_like`](tensor.random\_uniform\_like.md) | RandomUniformLike generates a tensor with random values using a uniform distribution, matching the shape of the input tensor. |
Expand Down
2 changes: 1 addition & 1 deletion docs/framework/operators/tensor/tensor.min.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
fn min(tensors: Span<Tensor<T>>) -> Tensor<T>;
```

Returns the element-wise minumum values from a list of input tensors
Returns the element-wise minimum values from a list of input tensors
The input tensors must have either:
* Exactly the same shape
* The same number of dimensions and the length of each dimension is either a common length or 1.
Expand Down
2 changes: 1 addition & 1 deletion docs/framework/operators/tensor/tensor.qlinear_add.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Performs the sum of quantized Tensors

It consumes two quantized input tensors, their scales and zero points, scale and zero point of output, and computes the quantized output.
The quantization formula is y = saturate((x / y_scale) + y_zero_point).
It perfoms the addition of the two vectors once dequantized, then return the quantization of the result of the addition.
It performs the addition of the two vectors once dequantized, then return the quantization of the result of the addition.
The broadcasting is supported
Scale and zero point must have same shape and the same type. They must be either scalar (per tensor) or N-D tensor (per row for 'a' and per column for 'b').
Scalar refers to per tensor quantization whereas N-D refers to per row or per column quantization.
Expand Down
2 changes: 1 addition & 1 deletion docs/framework/operators/tensor/tensor.qlinear_matmul.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Multiplies quantized Tensors

It consumes two quantized input tensors, their scales and zero points, scale and zero point of output, and computes the quantized output.
The quantization formula is y = saturate((x / y_scale) + y_zero_point).
It perfoms the multiplication of the two vectors once dequantized. If either argument is N-D, N > 2, it is treated as a stack of matrices residing in the last two indexes.
It performs the multiplication of the two vectors once dequantized. If either argument is N-D, N > 2, it is treated as a stack of matrices residing in the last two indexes.
Then return the quantization of the result of the multiplication.
Scale and zero point must have same shape and the same type. They must be either scalar (per tensor) or N-D tensor (per row for 'a' and per column for 'b').
Scalar refers to per tensor quantization whereas N-D refers to per row or per column quantization.
Expand Down
2 changes: 1 addition & 1 deletion docs/framework/operators/tensor/tensor.qlinear_mul.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Performs the element-wise multiplication of quantized Tensors

It consumes two quantized input tensors, their scales and zero points, scale and zero point of output, and computes the quantized output.
The quantization formula is y = saturate((x / y_scale) + y_zero_point).
It perfoms the element-wise multiplication of the two vectors once dequantized, then return the quantization of the result of the multiplication.
It performs the element-wise multiplication of the two vectors once dequantized, then return the quantization of the result of the multiplication.
The broadcasting is supported
Scale and zero point must have same shape and the same type. They must be either scalar (per tensor) or N-D tensor (per row for 'a' and per column for 'b').
Scalar refers to per tensor quantization whereas N-D refers to per row or per column quantization.
Expand Down
60 changes: 60 additions & 0 deletions docs/framework/operators/tensor/tensor.reduce_log_sum_exp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
## tensor.reduce_log_sum_exp

```rust
fn reduce_log_sum_exp(self: @Tensor<T>, axis: usize, keepdims: bool) -> Tensor<T>;
```

Computes the log sum of the exponentials of the input tensor's elements along the provided axes.

## Args
* 'self'(`@Tensor<T>`) - The input tensor.
* 'axis'(`usize`) - The dimension to reduce.
* 'keepdims'(`bool`) - If true, retains reduced dimensions with length 1.

## Panics

* Panics if axis is not in the range of the input tensor's dimensions.

## Returns

Returns a new `Tensor<T>` instance with the specified axis reduced by summing its elements.


## Example

```rust
use core::array::{ArrayTrait, SpanTrait};
use orion::operators::tensor::{TensorTrait, Tensor};
use orion::operators::tensor::FP32x32Tensor;
use orion::numbers::{FixedTrait, FP32x32};

fn reduce_log_sum_exp() -> Tensor<FP32x32> {
let mut shape = ArrayTrait::<usize>::new();
shape.append(3);
shape.append(2);
shape.append(2);

let mut data = ArrayTrait::new();
data.append(FP32x32 { mag: 4294967296, sign: false });
data.append(FP32x32 { mag: 8589934592, sign: false });
data.append(FP32x32 { mag: 12884901888, sign: false });
data.append(FP32x32 { mag: 17179869184, sign: false });
data.append(FP32x32 { mag: 21474836480, sign: false });
data.append(FP32x32 { mag: 25769803776, sign: false });
data.append(FP32x32 { mag: 30064771072, sign: false });
data.append(FP32x32 { mag: 34359738368, sign: false });
data.append(FP32x32 { mag: 38654705664, sign: false });
data.append(FP32x32 { mag: 42949672960, sign: false });
data.append(FP32x32 { mag: 47244640256, sign: false });
data.append(FP32x32 { mag: 51539607552, sign: false });
TensorTrait::new(shape.span(), data.span())

let tensor = TensorTrait::<FP32x32>::new(shape.span(), data.span());

return tensor.reduce_log_sum_exp(axis: 2, keepdims: false);

}


>>> [[9215828, 16323477, 20115004], [22716772, 24699744, 26302432]]
```
16 changes: 10 additions & 6 deletions nodegen/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class FixedImpl(Enum):
FP8x23 = 'FP8x23'
FP16x16 = 'FP16x16'
FP64x64 = 'FP64x64'
FP32x32 = 'FP32x32'



Expand All @@ -20,14 +20,15 @@ def to_fp(x: np.ndarray, fp_impl: FixedImpl):
return (x * 2**23).astype(np.int64)
case FixedImpl.FP16x16:
return (x * 2**16).astype(np.int64)
case FixedImpl.FP64x64:
return (x * 2**64)
case FixedImpl.FP32x32:
return (x * 2**32).astype(np.int64)



class Dtype(Enum):
FP8x23 = 'FP8x23'
FP16x16 = 'FP16x16'
FP64x64 = 'FP64x64'
FP32x32 = 'FP32x32'
I8 = 'i8'
I32 = 'i32'
U32 = 'u32'
Expand Down Expand Up @@ -173,8 +174,8 @@ def get_data_statement(data: np.ndarray, dtype: Dtype) -> list[str]:
return ["FP8x23 { "+f"mag: {abs(int(x))}, sign: {str(x < 0).lower()} "+"}" for x in data.flatten()]
case Dtype.FP16x16:
return ["FP16x16 { "+f"mag: {abs(int(x))}, sign: {str(x < 0).lower()} "+"}" for x in data.flatten()]
case Dtype.FP64x64:
return ["FP64x64 { "+f"mag: {abs(int(x))}, sign: {str(x < 0).lower()} "+"}" for x in data.flatten()]
case Dtype.FP32x32:
return ["FP32x32 { "+f"mag: {abs(int(x))}, sign: {str(x < 0).lower()} "+"}" for x in data.flatten()]
case Dtype.BOOL:
return [str(x).lower() for x in data.flatten()]
case Dtype.COMPLEX64:
Expand Down Expand Up @@ -253,6 +254,7 @@ def find_all_types(tensors: list[Tensor | Sequence]) -> list[Dtype]:
Dtype.FP16x16: ["orion::operators::tensor::{FP16x16Tensor, FP16x16TensorAdd}",],
Dtype.BOOL: ["orion::operators::tensor::BoolTensor",],
Dtype.COMPLEX64: ["orion::operators::tensor::Complex64Tensor",],
Dtype.FP32x32: ["orion::operators::tensor::FP32x32Tensor",],
}


Expand Down Expand Up @@ -280,6 +282,7 @@ def find_all_types(tensors: list[Tensor | Sequence]) -> list[Dtype]:
Dtype.I8: ["orion::operators::tensor::I8TensorPartialEq",],
Dtype.FP8x23: ["orion::operators::tensor::FP8x23TensorPartialEq",],
Dtype.FP16x16: ["orion::operators::tensor::FP16x16TensorPartialEq",],
Dtype.FP32x32: ["orion::operators::tensor::FP32x32TensorPartialEq",],
Dtype.BOOL: ["orion::operators::tensor::BoolTensorPartialEq",],
Dtype.COMPLEX64: ["orion::operators::tensor::Complex64TensorPartialEq",],
}
Expand All @@ -291,6 +294,7 @@ def find_all_types(tensors: list[Tensor | Sequence]) -> list[Dtype]:
Dtype.I8: ["orion::numbers::NumberTrait"],
Dtype.FP8x23: ["orion::numbers::{FixedTrait, FP8x23}",],
Dtype.FP16x16: ["orion::numbers::{FixedTrait, FP16x16}",],
Dtype.FP32x32: ["orion::numbers::{FixedTrait, FP32x32}",],
Dtype.BOOL: [],
Dtype.COMPLEX64: ["orion::numbers::{NumberTrait, complex64}",],
}
2 changes: 1 addition & 1 deletion nodegen/node/reduce_log_sum.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
from nodegen.node import RunAll
from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl
import numpy as np



class Reduce_log_sum(RunAll):
Expand Down
Loading

0 comments on commit de42865

Please sign in to comment.