Skip to content

Commit

Permalink
Merge pull request #590 from gizatechxyz/develop
Browse files Browse the repository at this point in the history
Merge Develop into Mains
  • Loading branch information
raphaelDkhn authored Mar 4, 2024
2 parents c4efe39 + fb6f4a0 commit 74e63f3
Show file tree
Hide file tree
Showing 367 changed files with 6,852 additions and 6,648 deletions.
29 changes: 28 additions & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,33 @@
"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 All @@ -296,4 +323,4 @@
"projectName": "orion",
"projectOwner": "gizatechxyz",
"commitType": "docs"
}
}
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
2 changes: 1 addition & 1 deletion Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "orion"
version = "0.2.3"
version = "0.2.4"
cairo-version = "2.5.3"
edition = "2023_10"
description = "ONNX Runtime in Cairo for verifiable ML inference using STARK"
Expand Down
8 changes: 8 additions & 0 deletions docgen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ fn main() {
let trait_name: &str = "SVMClassifierTrait";
doc_trait(trait_path, doc_path, label);
doc_functions(trait_path, doc_path, trait_name, label);

// NORMALIZER DOC
let trait_path = "src/operators/ml/normalizer/normalizer.cairo";
let doc_path = "docs/framework/operators/machine-learning/normalizer";
let label = "normalizer";
let trait_name: &str = "NormalizerTrait";
doc_trait(trait_path, doc_path, label);
doc_functions(trait_path, doc_path, trait_name, label);
}

fn doc_trait(trait_path: &str, doc_path: &str, label: &str) {
Expand Down
5 changes: 5 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased] - 2024-02-21

## Added
- Label Encoder.
-
## [Unreleased] - 2024-01-17

## Added
Expand Down
4 changes: 4 additions & 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 All @@ -157,6 +158,7 @@
* [tensor.hamming_window](framework/operators/tensor/tensor.hamming_window.md)
* [tensor.blackman_window](framework/operators/tensor/tensor.blackman_window.md)
* [tensor.random_uniform_like](framework/operators/tensor/tensor.random_uniform_like.md)
* [tensor.label_encoder](framework/operators/tensor/tensor.label_encoder.md)
* [Neural Network](framework/operators/neural-network/README.md)
* [nn.relu](framework/operators/neural-network/nn.relu.md)
* [nn.leaky\_relu](framework/operators/neural-network/nn.leaky\_relu.md)
Expand Down Expand Up @@ -198,6 +200,8 @@
* [sequence.sequence\_erase](framework/operators/sequence/sequence.sequence\_erase.md)
* [sequence.sequence\_insert](framework/operators/sequence/sequence.sequence\_insert.md)
* [sequence.concat\_from\_sequence](framework/operators/sequence/sequence.concat\_from\_sequence.md)
* [Normalizer](framework/operators/machine-learning/normalizer/README.md)
* [normalize.predict](framework/operators/machine-learning/normalizer/normalizer.predict.md)

## 🏛 Hub

Expand Down
6 changes: 4 additions & 2 deletions docs/framework/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ You can see below the list of current supported ONNX Operators:
| [Max](operators/tensor/tensor.max.md) | :white\_check\_mark: |
| [ReduceSumSquare](operators/tensor/tensor.reduce\_sum\_square.md) | :white\_check\_mark: |
| [Trilu](operators/tensor/tensor.trilu.md) | :white\_check\_mark: |
| [Scatter](operators/tensor/scatter.max.md) | :white\_check\_mark: |
| [Scatter](operators/tensor/tensor.scatter.md) | :white\_check\_mark: |
| [ArrayFeatureExtractor](operators/tensor/tensor.array\_feature\_extractor.md) | :white\_check\_mark: |
| [Binarizer](operators/tensor/tensor.binarizer.md) | :white\_check\_mark: |
| [ConstantOfShape](operators/tensor/tensor.constant_of_shape.md) | :white\_check\_mark: |
Expand All @@ -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 All @@ -124,5 +125,6 @@ You can see below the list of current supported ONNX Operators:
| [HammingWindow](operators/tensor/tensor.tensor.hamming_window.md) | :white\_check\_mark: |
| [BlackmanWindow](operators/tensor/tensor.tensor.blackman_window.md) | :white\_check\_mark: |
| [RandomUniformLike](operators/tensor/tensor.tensor.random_uniform_like.md) | :white\_check\_mark: |
| [LabelEncoder](operators/tensor/tensor.label_encoder.md) | :white\_check\_mark: |

Current Operators support: **117/156 (75%)**
Current Operators support: **118/156 (75%)**
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
23 changes: 23 additions & 0 deletions docs/framework/operators/machine-learning/normalizer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Normalizer

`NormalizerTrait` computes the normalization of the input, each row of the input is normalized independently.

```rust
use orion::operators::ml::NormalizerTrait;
```

### Data types

Orion supports currently only fixed point data types for `NormalizerTrait`.

| Data type | dtype |
| -------------------- | ------------------------------------------------------------- |
| Fixed point (signed) | `NormalizerTrait<FP8x23 \| FP16x16 \| FP64x64 \| FP32x32>` |


***

| function | description |
| --- | --- |
| [`normalizer.predict`](normalizer.predict.md) | Returns the normalization of the input, each row of the input is normalized independently. |

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Normalizer::predict

```rust
fn predict(X: Tensor<T>, norm: NORM) -> Tensor<T>;
```

Returns the normalized input.
Tree different types of normalization can be performed and are defined as follow :
MAX: $Y = \frac{X}{max(X)}$
L1: $Y = \frac{X}{sum(X)}$
L2: $Y = \frac{X}\sqrt{{sum(X²)}}$
For batches, that is, [N,C] tensors, normalization is done along the C axis. In other words, each row of the batch is normalized independently.

## Args

* `X`(`@Tensor<T>`) - Input 2D tensor.
* `norm`(`NORM`) - NORM::MAX, NORM::L1 or NORM::L2


## Returns

* Tensor<T> - output tensor

## Examples

```rust
use orion::numbers::FP16x16;
use orion::operators::tensor::{Tensor, TensorTrait, FP16x16Tensor, FP16x16TensorDiv, FP16x16TensorPartialEq};

use orion::operators::ml::normalizer::normalizer::{
NormalizerTrait, NORM
};



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

let mut data = ArrayTrait::new();
data.append(FP16x16 { mag: 65536, sign: true });
data.append(FP16x16 { mag: 52428, sign: true });
data.append(FP16x16 { mag: 39321, sign: true });
data.append(FP16x16 { mag: 26214, sign: true });
data.append(FP16x16 { mag: 13107, sign: true });
data.append(FP16x16 { mag: 0, sign: false });
data.append(FP16x16 { mag: 13107, sign: false });
data.append(FP16x16 { mag: 26214, sign: false });
data.append(FP16x16 { mag: 39321, sign: false });

let X = TensorTrait::new(shape.span(), data.span());

return NormalizerTrait::predict(X, NORM::MAX);
}
>>> [[-1. -0.8 -0.6 ]
[-1. -0.5 0. ]
[ 0.3333333 0.6666666 1. ]]

```

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. |

1 change: 0 additions & 1 deletion docs/framework/operators/neural-network/nn.col2im.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# NNTrait::col2im

```rust
Expand Down
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
2 changes: 2 additions & 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 All @@ -130,6 +131,7 @@ use orion::operators::tensor::TensorTrait;
| [`tensor.optional`](tensor.optional.md) | Constructs an optional-type value containing either an empty optional of a certain type specified by the attribute, or a non-empty value containing the input element. |
| [`tensor.dynamic_quantize_linear`](tensor.dynamic\_quantize\_linear.md) | Computes the Scale, Zero Point and FP32->8Bit conversion of FP32 Input data. |
| [`tensor.scatter_nd`](tensor.scatter\_nd.md) | The output of the operation is produced by creating a copy of the input data, and then updating its value to values specified by updates at specific index positions specified by indices. Its output shape is the same as the shape of data |
| [`tensor.label_encoder`](tensor.label\_encoder.md) | Maps each element in the input tensor to another value. |

## Arithmetic Operations

Expand Down
Empty file.
Loading

0 comments on commit 74e63f3

Please sign in to comment.