Skip to content

Commit

Permalink
Merge pull request #443 from gizatechxyz/develop
Browse files Browse the repository at this point in the history
Merge Develop into Main
  • Loading branch information
raphaelDkhn authored Nov 12, 2023
2 parents bc80875 + 3495839 commit 6f0dc22
Show file tree
Hide file tree
Showing 757 changed files with 15,732 additions and 1,640 deletions.
27 changes: 27 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,33 @@
"contributions": [
"code"
]
},
{
"login": "Ephraim-nonso",
"name": "Ephraim Chukwu",
"avatar_url": "https://avatars.githubusercontent.com/u/68496788?v=4",
"profile": "https://audits.quillhash.com/smart-contract-audit",
"contributions": [
"code"
]
},
{
"login": "Bal7hazar",
"name": "Bal7hazar",
"avatar_url": "https://avatars.githubusercontent.com/u/97087040?v=4",
"profile": "https://github.com/Bal7hazar",
"contributions": [
"bug"
]
},
{
"login": "okhaimie-dev",
"name": "Tony Stark",
"avatar_url": "https://avatars.githubusercontent.com/u/57156589?v=4",
"profile": "https://okhaimie.com",
"contributions": [
"doc"
]
}
],
"contributorsPerLine": 7,
Expand Down
7 changes: 6 additions & 1 deletion 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-21-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-22-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 @@ -95,6 +95,11 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center" valign="top" width="14.28%"><a href="https://brilliantblocks.io"><img src="https://avatars.githubusercontent.com/u/25390947?v=4?s=100" width="100px;" alt="Thomas S. Bauer"/><br /><sub><b>Thomas S. Bauer</b></sub></a><br /><a href="https://github.com/gizatechxyz/orion/commits?author=TsBauer" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="http://andresmayorca.github.io"><img src="https://avatars.githubusercontent.com/u/70079260?v=4?s=100" width="100px;" alt="Andres"/><br /><sub><b>Andres</b></sub></a><br /><a href="https://github.com/gizatechxyz/orion/commits?author=andresmayorca" title="Code">💻</a></td>
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://audits.quillhash.com/smart-contract-audit"><img src="https://avatars.githubusercontent.com/u/68496788?v=4?s=100" width="100px;" alt="Ephraim Chukwu"/><br /><sub><b>Ephraim Chukwu</b></sub></a><br /><a href="https://github.com/gizatechxyz/orion/commits?author=Ephraim-nonso" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Bal7hazar"><img src="https://avatars.githubusercontent.com/u/97087040?v=4?s=100" width="100px;" alt="Bal7hazar"/><br /><sub><b>Bal7hazar</b></sub></a><br /><a href="https://github.com/gizatechxyz/orion/issues?q=author%3ABal7hazar" title="Bug reports">🐛</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://okhaimie.com"><img src="https://avatars.githubusercontent.com/u/57156589?v=4?s=100" width="100px;" alt="Tony Stark"/><br /><sub><b>Tony Stark</b></sub></a><br /><a href="https://github.com/gizatechxyz/orion/commits?author=okhaimie-dev" title="Documentation">📖</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
Expand Up @@ -6,7 +6,7 @@ homepage = "https://github.com/gizatechxyz/orion"

[dependencies]
alexandria_data_structures = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "f37d73d" }
cubit = { git = "https://github.com/raphaelDkhn/cubit.git" }
cubit = { git = "https://github.com/influenceth/cubit.git", rev = "b459053" }

[scripts]
sierra = "cairo-compile . -r"
Expand Down
16 changes: 16 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,28 @@ 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] - 2023-11-06

## Added
- Reduce Sum Square Operator.

## [Unreleased] - 2023-11-05

### Added
- ReduceL2 operator.

## [Unreleased] - 2023-11-06

## Added
- Reduce L1 Operator.


## [Unreleased] - 2023-11-03

## Added
- Scatter Elements Operator.


## [Unreleased] - 2023-09-27

## Added
Expand Down
5 changes: 5 additions & 0 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
* [tensor.gather](framework/operators/tensor/tensor.gather.md)
* [tensor.quantize\_linear](framework/operators/tensor/tensor.quantize\_linear.md)
* [tensor.dequantize\_linear](framework/operators/tensor/tensor.dequantize\_linear.md)
* [tensor.qlinear\_add](framework/operators/tensor/tensor.qlinear\_add.md)
* [tensor.qlinear\_matmul](framework/operators/tensor/tensor.qlinear\_matmul.md)
* [tensor.nonzero](framework/operators/tensor/tensor.nonzero.md)
* [tensor.squeeze](framework/operators/tensor/tensor.squeeze.md)
Expand All @@ -93,8 +94,12 @@
* [tensor.identity](framework/operators/tensor/tensor.identity.md)
* [tensor.and](framework/operators/tensor/tensor.and.md)
* [tensor.where](framework/operators/tensor/tensor.where.md)
* [tensor.bitwise_and](framework/operators/tensor/tensor.bitwise_and.md)
* [tensor.round](framework/operators/tensor/tensor.round.md)
* [tensor.scatter](framework/operators/tensor/tensor.scatter.md)
* [tensor.reduce\_sum\_square](framework/operators/tensor/tensor.reduce\_sum\_square.md)
* [tensor.reduce\_l2](framework/operators/tensor/tensor.reduce\_l2.md)
* [tensor.reduce\_l1](framework/operators/tensor/tensor.reduce\_l1.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
5 changes: 1 addition & 4 deletions docs/academy/tutorials/implement-new-operators-in-orion.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ Finally, we create a Softmax class, containing tests for each dtypes.
```python
import numpy as np
from nodegen.node import RunAll
from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl, Trait
from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl, Trait

def softmax(x: np.ndarray, axis: int = -1) -> np.ndarray:
x_max = np.max(x, axis=axis, keepdims=True)
Expand All @@ -293,8 +293,6 @@ class Softmax(RunAll):

# Define the name of the generated folder.
name = "softmax_fp8x23"
# Invoke `make_node` method to generate Cairo representation of `x` and `y`:
make_node([x], [y], name)
# Invoke `make_test` method to generate corresponding Cairo tests:
make_test(
[x], # List of input tensors.
Expand All @@ -316,7 +314,6 @@ class Softmax(RunAll):
y.flatten(), FixedImpl.FP16x16))

name = "softmax_fp16x16"
make_node([x], [y], name)
make_test([x], y, "NNTrait::softmax(@input_0, 1)",
name, Trait.NN)
```
Expand Down
9 changes: 8 additions & 1 deletion docs/framework/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ You can see below the list of current supported ONNX Operators:
| [Gather](operators/tensor/tensor.gather.md) | :white\_check\_mark: |
| [QuantizeLinear](operators/tensor/tensor.quantize\_linear.md) | :white\_check\_mark: |
| [DequantizeLinear](operators/tensor/tensor.quantize\_linear.md) | :white\_check\_mark: |
| [QLinearMatmul](operators/tensor/tensor.qlinear\_matmul.md) | :white\_check\_mark: |
| [QlinearAdd](operators/tensor/tensor.qlinear\_add.md) | :white\_check\_mark: |
| [QLinearMatmul](operators/tensor/tensor.qlinear\_matmul.md) | :white\_check\_mark: |
| [Nonzero](operators/tensor/tensor.nonzero.md) | :white\_check\_mark: |
| [Squeeze](operators/tensor/tensor.squeeze.md) | :white\_check\_mark: |
| [Unsqueeze](operators/tensor/tensor.unsqueeze.md) | :white\_check\_mark: |
Expand All @@ -70,9 +71,15 @@ You can see below the list of current supported ONNX Operators:
| [MinInTensor](operators/tensor/tensor.min\_in\_tensor.md) | :white\_check\_mark: |
| [Min](operators/tensor/tensor.min.md) | :white\_check\_mark: |
| [Where](operators/tensor/tensor.where.md) | :white\_check\_mark: |
| [BitwiseAnd](operators/tensor/tensor.bitwise_and.md) | :white\_check\_mark: |
| [Round](operators/tensor/tensor.round.md) | :white\_check\_mark: |
| [MaxInTensor](operators/tensor/tensor.max\_in\_tensor.md) | :white\_check\_mark: |
| [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: |
| [ConstantOfShape](operators/tensor/tensor.constant_of_shape.md) | :white\_check\_mark: |
| [ReduceL1](operators/tensor/tensor.reduce\_l1.md) | :white\_check\_mark: |
| [ReduceL2](operators/tensor/tensor.reduce\_l2.md) | :white\_check\_mark: |

Current Operators support: **68/156 (43%)**
10 changes: 5 additions & 5 deletions docs/framework/operators/neural-network/nn.softmax.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ Constrain input and output types to fixed point tensors.
```rust
use array::{ArrayTrait, SpanTrait};

use orion::operators::tensor::{TensorTrait, Tensor, FP8x23};
use orion::operators::tensor::{TensorTrait, Tensor, FP8x23Tensor};
use orion::operators::nn::{NNTrait, FP8x23NN};
use orion::numbers::{FP8x23, FixedTrait};

fn softmax_example() -> Tensor<FP8x23> {
let tensor = TensorTrait::<FP8x23>::new(
shape: array![2, 2].span(),
data: array![
NNTrait::new(0, false),
NNTrait::new(1, false),
NNTrait::new(2, false),
NNTrait::new(3, false),
FixedTrait::new(0, false),
FixedTrait::new(1, false),
FixedTrait::new(2, false),
FixedTrait::new(3, false),
]
.span(),
);
Expand Down
7 changes: 7 additions & 0 deletions docs/framework/operators/tensor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use orion::operators::tensor::TensorTrait;
| [`tensor.new`](tensor.new.md) | Returns a new tensor with the given shape and data. |
| [`tensor.reshape`](tensor.reshape.md) | Returns a new tensor with the specified target shape and the same data as the input tensor. |
| [`tensor.flatten`](tensor.flatten.md) | Flattens the input tensor into a 2D tensor. |
| [`tensor.constant_of_shape`](tensor.constant\_of\_shape.md) | Generate a tensor with given value and shape. |
| [`tensor.transpose`](tensor.transpose.md) | Returns a new tensor with the axes rearranged according to the given permutation. |
| [`tensor.at`](tensor.at.md) | Retrieves the value at the specified indices of a Tensor. |
| [`tensor.ravel_index`](tensor.ravel\_index.md) | Converts a multi-dimensional index to a one-dimensional index. |
Expand Down Expand Up @@ -79,6 +80,7 @@ use orion::operators::tensor::TensorTrait;
| [`tensor.concat`](tensor.concat.md) | Concatenate a list of tensors into a single tensor. |
| [`tensor.quantize_linear`](tensor.quantize\_linear.md) | Quantizes a Tensor to i8 using linear quantization. |
| [`tensor.dequantize_linear`](tensor.dequantize\_linear.md) | Dequantizes an i8 Tensor using linear dequantization. |
| [`tensor.qlinear_add`](tensor.qlinear\_add.md) | Performs the sum of two quantized i8 Tensors. |
| [`tensor.qlinear_matmul`](tensor.qlinear\_matmul.md) | Performs the product of two quantized i8 Tensors. |
| [`tensor.gather`](tensor.gather.md) | Gather entries of the axis dimension of data. |
| [`tensor.nonzero`](tensor.nonzero.md) | Produces indices of the elements that are non-zero (in row-major order - by dimension). |
Expand All @@ -89,8 +91,13 @@ use orion::operators::tensor::TensorTrait;
| [`tensor.and`](tensor.and.md) | Computes the logical AND of two tensors element-wise. |
| [`tensor.identity`](tensor.identity.md) | Return a Tensor with the same shape and contents as input. |
| [`tensor.where`](tensor.where.md) | Return elements chosen from x or y depending on condition. |
| [`tensor.bitwise_and`](tensor.bitwise\_and.md) | Computes the bitwise AND of two tensors element-wise. |
| [`tensor.round`](tensor.round.md) | Computes the round value of all elements in the input tensor. |
| [`tensor.reduce_l1`](tensor.reduce\_l1.md) | Computes the L1 norm of the input tensor's elements along the provided axes. |
| [`tensor.trilu`](tensor.trilu.md) | Returns the upper or lower triangular part of a tensor or a batch of 2D matrices. |
| [`tensor.scatter`](tensor.scatter.md) | Produces a copy of input data, and updates value to values specified by updates at specific index positions specified by indices. |
| [`tensor.reduce_sum_square`](tensor.reduce\_sum\_square.md) | Computes the sum square of the input tensor's elements along the provided axes. |
| [`tensor.reduce_l2`](tensor.reduce\_l2.md) | Computes the L2 norm of the input tensor's elements along the provided axes. |

## Arithmetic Operations

Expand Down
Empty file.
44 changes: 44 additions & 0 deletions docs/framework/operators/tensor/tensor.bitwise_and.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#tensor.bitwise_and

```rust
fn bitwise_and(self: @Tensor<T>, other: @Tensor<T>) -> Tensor<usize>;
```

Computes the bitwise AND of two tensors element-wise.
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.

## Args

* `self`(`@Tensor<T>`) - The first tensor to be compared
* `other`(`@Tensor<T>`) - The second tensor to be compared

## Panics

* Panics if the shapes are not equal or broadcastable

## Returns

A new `Tensor<T>` with the same shape as the broadcasted inputs.

## Example

```rust
use array::{ArrayTrait, SpanTrait};

use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor};

fn and_example() -> Tensor<usize> {
let tensor_1 = TensorTrait::<u32>::new(
shape: array![3, 3].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7, 8].span(),
);

let tensor_2 = TensorTrait::<u32>::new(
shape: array![3, 3].span(), data: array![0, 1, 2, 0, 4, 5, 0, 6, 2].span(),
);

return tensor_1.bitwise_and(@tensor_2);
}
>>> [0,1,2,0,4,5,0,6,2]
```
38 changes: 38 additions & 0 deletions docs/framework/operators/tensor/tensor.constant_of_shape.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# tensor.constant_of_shape

```rust
fn constant_of_shape(shape: Span<usize>, value: T) -> Tensor<T>;
```

Returns a new tensor with the given shape and constant value.

## Args

* `shape`(`Span<usize>`) - A span representing the shape of the tensor.
* `value` (`T`) - the constant value.

## Returns

A new `Tensor<T>` instance.

## Examples

Let's create new u32 Tensor with constant 42.

```rust
use array::{ArrayTrait, SpanTrait};

use orion::operators::tensor::{
TensorTrait, // we import the trait
Tensor, // we import the type
U32Tensor // we import the implementation.
};

fn constant_of_shape_example() -> Tensor<u32> {
let tensor = TensorTrait::constant_of_shape(shape: array![3].span(), value: 42);

return tensor;
}

>>> [42, 42, 42]
```
Loading

0 comments on commit 6f0dc22

Please sign in to comment.