Skip to content

Commit

Permalink
Merge pull request #623 from gizatechxyz/develop
Browse files Browse the repository at this point in the history
Merge Develop into Main
  • Loading branch information
raphaelDkhn authored Mar 27, 2024
2 parents efbe4aa + bde88b6 commit 2ab64e5
Show file tree
Hide file tree
Showing 565 changed files with 3,935 additions and 12,481 deletions.
Binary file added .DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "orion"
version = "0.2.5"
cairo-version = "2.6.3"
version = "0.2.4"
cairo-version = "2.5.3"
edition = "2023_10"
description = "ONNX Runtime in Cairo for verifiable ML inference using STARK"
homepage = "https://github.com/gizatechxyz/orion"
Expand Down
6 changes: 3 additions & 3 deletions docs/framework/operators/neural-network/nn.softmax.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# NNTrait::softmax

```rust
fn softmax(tensor: @Tensor<T>, axis: usize) -> Tensor<T>;
fn softmax(tensor: @Tensor<T>, axis: Option<i32>) -> Tensor<T>;
```

Applies the Softmax function to an n-dimensional input Tensor rescaling them so that the elements of the n-dimensional output Tensor lie in the range \[0,1] and sum to 1.
Expand All @@ -13,7 +13,7 @@ $$
## Args

* `tensor`(`@Tensor<T>`) - The input tensor.
* `axis`(`usize`) - The axis along which to compute the softmax.
* `axis`(`Option<i32>`) - Describes the dimension Softmax will be performed on. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(input).

## Returns

Expand Down Expand Up @@ -44,7 +44,7 @@ fn softmax_example() -> Tensor<FP8x23> {
.span(),
);

return NNTrait::softmax(@tensor, 1);
return NNTrait::softmax(@tensor, Option::Some(1));
}
>>> [[2255697,6132911],[2255697,6132911]]
// The fixed point representation of
Expand Down
3 changes: 1 addition & 2 deletions docs/framework/operators/tensor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ use orion::operators::tensor::TensorTrait;
| [`tensor.min_in_tensor`](tensor.min\_in\_tensor.md) | Returns the minimum value in the tensor. |
| [`tensor.min`](tensor.min.md) | Returns the minimum value in the tensor. |
| [`tensor.max`](tensor.max.md) | Returns the maximum value in the tensor. |
| [`tensor.reduce_sum`](tensor.reduce\_sum.md) | Computes the sum of the input tensor's elements along the provided axes. |
| [`tensor.reduce_sum_single_axis`](tensor.reduce\_sum\_single\_axis.md) | Reduces a tensor by summing its elements along a specified axis. |
| [`tensor.reduce_sum`](tensor.reduce\_sum.md) | Reduces a tensor by summing its elements along a specified axis. |
| [`tensor.reduce_prod`](tensor.reduce\_prod.md) | Reduces a tensor to its products along specified axis. |
| [`tensor.argmax`](tensor.argmax.md) | Returns the index of the maximum value along the specified axis. |
| [`tensor.argmin`](tensor.argmin.md) | Returns the index of the minimum value along the specified axis. |
Expand Down
4 changes: 2 additions & 2 deletions docs/framework/operators/tensor/tensor.argmax.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# tensor.argmax

```rust
fn argmax(self: @Tensor<T>, axis: usize, keepdims: Option<bool>, select_last_index: Option<bool>) -> Tensor<usize>;
fn argmax(self: @Tensor<T>, axis: i32, keepdims: Option<bool>, select_last_index: Option<bool>) -> Tensor<i32>;
```

Returns the index of the maximum value along the specified axis.

## Args

* `self`(`@Tensor<T>`) - The input tensor.
* `axis`(`usize`) - The axis along which to compute the argmax.
* `axis`(`i32`) - The axis along which to compute the argmax.
* `keepdims`(`Option<bool>`) - If true, retains reduced dimensions with length 1. Defaults to true.
* `select_last_index`(`Option<bool>`) - If true, the index of the last occurrence of the maximum value is returned. Defaults to false.

Expand Down
8 changes: 4 additions & 4 deletions docs/framework/operators/tensor/tensor.gather.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# tensor.gather

```rust
fn gather(self: @Tensor<T>, indices: Tensor<T>, axis: Option<usize>) -> Tensor<T>;
fn gather(self: @Tensor<T>, indices: Tensor<i32>, axis: Option<i32>) -> Tensor<T>;
```

Gather entries of the axis dimension of data.

## Args

* `self`(`@Tensor<T>`) - The input tensor.
* `indices`(`Tensor<T>`) - Tensor of indices.
* `axis`(`Option<usize>`) - Axis to gather on. Default: axis=0.
* `indices`(`Tensor<i32>`) - Tensor of indices.
* `axis`(`Option<i32>`) - Axis to gather on. Default: axis=0.

## Panics

Expand All @@ -32,7 +32,7 @@ fn gather_example() -> Tensor<u32> {
shape: array![2, 3].span(),
data: array![[ 1, 2, 3],[4, 5, 6]].span(),
);
let indices = TensorTrait::<u32>::new(
let indices = TensorTrait::<i32>::new(
shape: array![1, 1].span(),
data: array![1, 0].span(),
);
Expand Down
8 changes: 4 additions & 4 deletions docs/framework/operators/tensor/tensor.gather_elements.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# tensor.gather_elements

```rust
fn gather_elements(self: @Tensor<T>, indices: Tensor<T>, axis: Option<usize>) -> Tensor<T>;
fn gather_elements(self: @Tensor<T>, indices: Tensor<i32>, axis: Option<i32>) -> Tensor<T>;
```

GatherElements is an indexing operation that produces its output by indexing into the input data tensor at index positions determined by elements of the indices tensor.

## Args

* `self`(`@Tensor<T>`) - The input tensor.
* `indices`(`Tensor<T>`) - Tensor of indices.
* `axis`(`Option<usize>`) - Axis to gather_elements on. Default: axis=0.
* `indices`(`Tensor<i32>`) - Tensor of indices.
* `axis`(`Option<i32>`) - Axis to gather_elements on. Default: axis=0.

## Panics

Expand All @@ -32,7 +32,7 @@ fn gather_elements_example() -> Tensor<u32> {
shape: array![3, 3].span(),
data: array![[ 1, 2, 3],[4, 5, 6], [7, 8, 9]].span(),
);
let indices = TensorTrait::<u32>::new(
let indices = TensorTrait::<i32>::new(
shape: array![1, 2, 0].span(),
data: array![2, 0, 0].span(),
);
Expand Down
8 changes: 4 additions & 4 deletions docs/framework/operators/tensor/tensor.less.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#tensor.less

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

Check if each element of the first tensor is less than the corresponding element of the second tensor.
Expand All @@ -20,7 +20,7 @@ The input tensors must have either:

## Returns

A new `Tensor<usize>` of booleans (0 or 1) with the same shape as the broadcasted inputs.
A new `Tensor<bool>` of booleans with the same shape as the broadcasted inputs.

## Examples

Expand All @@ -31,7 +31,7 @@ use core::array::{ArrayTrait, SpanTrait};

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

fn less_example() -> Tensor<usize> {
fn less_example() -> Tensor<i32> {
let tensor_1 = TensorTrait::<u32>::new(
shape: array![3, 3, 3].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7, 8].span(),
);
Expand All @@ -53,7 +53,7 @@ use core::array::{ArrayTrait, SpanTrait};

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

fn less_example() -> Tensor<usize> {
fn less_example() -> Tensor<i32> {
let tensor_1 = TensorTrait::<u32>::new(
shape: array![3, 3, 3].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7, 8].span(),
);
Expand Down
8 changes: 4 additions & 4 deletions docs/framework/operators/tensor/tensor.less_equal.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#tensor.less_equal

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

Check if each element of the first tensor is less than or equal to the corresponding element of the second tensor.
Expand All @@ -20,7 +20,7 @@ The input tensors must have either:

## Returns

A new `Tensor<usize>` of booleans (0 or 1) with the same shape as the broadcasted inputs.
A new `Tensor<i32>` of booleans (0 or 1) with the same shape as the broadcasted inputs.

## Examples

Expand All @@ -31,7 +31,7 @@ use core::array::{ArrayTrait, SpanTrait};

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

fn less_equal_example() -> Tensor<usize> {
fn less_equal_example() -> Tensor<i32> {
let tensor_1 = TensorTrait::<u32>::new(
shape: array![3, 3, 3].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7, 8].span(),
);
Expand All @@ -53,7 +53,7 @@ use core::array::{ArrayTrait, SpanTrait};

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

fn less_equal_example() -> Tensor<usize> {
fn less_equal_example() -> Tensor<i32> {
let tensor_1 = TensorTrait::<u32>::new(
shape: array![3, 3, 3].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7, 8].span(),
);
Expand Down
20 changes: 8 additions & 12 deletions docs/framework/operators/tensor/tensor.reduce_sum.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
## tensor.reduce_sum

```rust
fn reduce_sum(self: @Tensor<T>, axis: usize, keepdims: bool) -> Tensor<T>;
fn reduce_sum(self: @Tensor<T>, axes: Option<Span<i32>>, keepdims: Option<bool>, noop_with_empty_axes: Option<bool>) -> Tensor<T>;
```

Computes the sum of the input tensor's elements along the provided axes
Reduces a tensor by summing its elements along a specified axis.

## Args

* `self`(`@Tensor<T>`) - The input tensor.
* `axes`(`Option<Span<usize>>`) - Optional input list of integers, along which to reduce.
* `keepdims`(`Option<bool>`) - If true, retains reduced dimensions with length 1.
* `axes`(`Option<Span<i32>>`) - Optional input list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor if 'noop_with_empty_axes' is false, else act as an Identity op when 'noop_with_empty_axes' is true.
* `keepdims`(`Option<bool>`) - Keep the reduced dimension or not, default 1 means keep reduced dimension.
* `noop_with_empty_axes`(`Option<bool>`) - Defines behavior if 'axes' is empty. Default behavior with 'false' is to reduce all axes. When axes is empty and this attribute is set to true, input tensor will not be reduced,and the output tensor would be equivalent to input tensor.

## Panics

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

## Returns

A new `Tensor<T>` instance with the specified axis reduced by summing its elements.
Reduced output tensor.

## Examples

Expand All @@ -30,11 +26,11 @@ use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor};

fn reduce_sum_example() -> Tensor<u32> {
let tensor = TensorTrait::<u32>::new(
shape: array![3, 2, 2].span(), data: array![1, 2, 3, 4, 5, 6, 7, 8 ,9, 10, 11, 12].span(),
shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(),
);

// We can call `reduce_sum` function as follows.
return tensor.reduce_sum(Option::Some(array![1].span()), Option::Some(false), Option::None);
return tensor.reduce_sum(axes: Option::None, keepdims: false);
}
>>> [[4, 6] [12, 14] [20, 22]]
>>> [[4,6],[8,10]]
```
39 changes: 0 additions & 39 deletions docs/framework/operators/tensor/tensor.reduce_sum_single_axis.md

This file was deleted.

14 changes: 10 additions & 4 deletions docs/framework/operators/tensor/tensor.reshape.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
# tensor.reshape

```rust
fn reshape(self: @Tensor<T>, target_shape: Span<usize>) -> Tensor<T>;
fn reshape(self: @Tensor<T>, target_shape: Span<i32>, allowzero: bool) -> Tensor<T>;
```

Returns a new tensor with the specified target shape and the same data as the input tensor.
Reshape the input tensor similar to numpy.reshape. First input is the data tensor, second
input is a shape tensor which specifies the output shape. It outputs the reshaped tensor.
At most one dimension of the new shape can be -1. In this case, the value is inferred from
the size of the tensor and the remaining dimensions. A dimension could also be 0, in which case
the actual dimension value is unchanged (i.e. taken from the input tensor). If 'allowzero' is set,
and the new shape includes 0, the dimension will be set explicitly to zero (i.e. not taken from input tensor)

## Args

* `self`(`@Tensor<T>`) - The input tensor.
* `target_shape`(Span<usize>) - A span containing the target shape of the tensor.
* `target_shape`(Span<i32>) - A span containing the target shape of the tensor.
* `allowzero`(`bool`) - Indicates that if any value in the 'shape' input is set to zero, the zero value is honored, similar to NumPy.

## Panics

Expand All @@ -32,7 +38,7 @@ fn reshape_tensor_example() -> Tensor<u32> {
);

// We can call `reshape` function as follows.
return tensor.reshape(target_shape: array![2, 4].span());
return tensor.reshape(target_shape: array![2, 4].span(), false);
}
>>> [[0,1,2,3], [4,5,6,7]]
```
Loading

0 comments on commit 2ab64e5

Please sign in to comment.