Skip to content

Commit

Permalink
Merge pull request #609 from gizatechxyz/develop
Browse files Browse the repository at this point in the history
Merge Develop into Main
  • Loading branch information
raphaelDkhn authored Mar 21, 2024
2 parents 74e63f3 + 6095349 commit efbe4aa
Show file tree
Hide file tree
Showing 104 changed files with 2,206 additions and 455 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ jobs:
- uses: actions/checkout@v3
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: "2.5.3"
scarb-version: "2.6.4"
- run: scarb test --workspace && scarb fmt --workspace
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
scarb 2.5.3
scarb 2.6.4
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.4"
cairo-version = "2.5.3"
version = "0.2.5"
cairo-version = "2.6.3"
edition = "2023_10"
description = "ONNX Runtime in Cairo for verifiable ML inference using STARK"
homepage = "https://github.com/gizatechxyz/orion"
Expand Down
3 changes: 2 additions & 1 deletion docs/framework/operators/tensor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ 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) | Reduces a tensor by summing its elements along a specified axis. |
| [`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_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
13 changes: 7 additions & 6 deletions docs/framework/operators/tensor/tensor.reduce_sum.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
fn reduce_sum(self: @Tensor<T>, axis: usize, keepdims: bool) -> Tensor<T>;
```

Reduces a tensor by summing its elements along a specified axis.
Computes the sum 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.
* `axes`(`Option<Span<usize>>`) - Optional input list of integers, along which to reduce.
* `keepdims`(`Option<bool>`) - If true, retains reduced dimensions with length 1.
* `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

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

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

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

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

Reduces a tensor by summing its elements along a specified axis.

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

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

## Examples

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

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

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

// We can call `reduce_sum_single_axis` function as follows.
return tensor.reduce_sum_single_axis(axis: 0, keepdims: false);
}
>>> [[4,6],[8,10]]
```
35 changes: 23 additions & 12 deletions nodegen/file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,25 +91,36 @@ def base_template(
This method generates a list of strings that form the template of a Cairo test function,
including module imports, function definition, and assertions.
"""
return [
template = [
*[f"mod input_{i};" for i in range(arg_cnt)],
*[f"mod output_{i};" for i in range(out_cnt)],
*[""],
*[""],
"",
"",
*[f"use {ref};" for ref in refs],
*[""],
*["#[test]"],
*["#[available_gas(2000000000)]"],
*[f"fn test_{name}()" + " {"],
"",
"#[test]",
"#[available_gas(2000000000)]",
f"fn test_{name}()" + " {",
*[f" let input_{i} = input_{i}::input_{i}();" for i in range(arg_cnt)],
*[f" let z_{i} = output_{i}::output_{i}();" for i in range(out_cnt)],
*[""],
*[f" let ({', '.join(f'y_{i}' for i in range(out_cnt))}) = {func_sig};"],
*[""],
*[f" assert_eq(y_{i}, z_{i});" for i in range(out_cnt)],
*["}"],
""
]

# Handling conditional function signature based on the number of outputs
if out_cnt > 1:
template.append(f" let ({', '.join(f'y_{i}' for i in range(out_cnt))}) = {func_sig};")
else:
template.append(f" let y_0 = {func_sig};")

# Continue appending to the template
template.extend([
"",
*[f" assert_eq(y_{i}, z_{i});" for i in range(out_cnt)],
"}"
])

return template

@classmethod
def sequence_template(cls, name: str, arg_cnt: int, refs: list[str], func_sig: str) -> list[str]:
"""
Expand Down
Loading

0 comments on commit efbe4aa

Please sign in to comment.