Skip to content

Commit

Permalink
organize nada libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
oceans404 committed Jun 21, 2024
1 parent 228434b commit 28a0b14
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 100 deletions.
21 changes: 10 additions & 11 deletions docs/nada-ai-introduction.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Introducing Nada AI
# Nada AI

Welcome to Nada AI, a cutting-edge Machine Learning framework inspired by SKLearn and PyTorch, designed to seamlessly integrate model-building capabilities into Nada DSL. With Nada AI, effortlessly import AI models into the Nillion ecosystem for inference, leveraging the robust foundation of [Nada Numpy](./nada-numpy-introduction).
[nada-ai](https://github.com/NillionNetwork/nada-ai/) is a cutting-edge Machine Learning framework inspired by SKLearn and PyTorch, designed to seamlessly integrate model-building capabilities into Nada DSL. With Nada AI, effortlessly import AI models into the Nillion ecosystem for inference, leveraging the robust foundation of [Nada Numpy](./nada-numpy-introduction).

Nada AI boasts a strongly-typed interface, utilizing root families (`Integer`, `UnsignedInteger`, `Rational`, and `SecretBoolean`). This ensures strict type enforcement at the library level, guaranteeing compliance with Nada DSL rules.

Expand All @@ -16,17 +16,16 @@ Explore our [GitHub Repository Examples](https://github.com/NillionNetwork/nada-

### Supported Models

* **Multilayer Perceptron**: With the following layers available: `Linear`, `Conv2d`, `AvgPooling2d`, `DotProductSimilarity`, `ReLU`, `Flatten`.
* **Linear Regression Model**: Linear model.
* **Logistic Regression Model**: Linear model implementation with cleartext sigmoid and potential multiclass classification.
* **Prophet**: Time series forecasting model.

- **Multilayer Perceptron**: With the following layers available: `Linear`, `Conv2d`, `AvgPooling2d`, `DotProductSimilarity`, `ReLU`, `Flatten`.
- **Linear Regression Model**: Linear model.
- **Logistic Regression Model**: Linear model implementation with cleartext sigmoid and potential multiclass classification.
- **Prophet**: Time series forecasting model.

### Important Considerations and Limitations

*Nada AI is currently in active development. Please note:*
_Nada AI is currently in active development. Please note:_

- *AI training is **not** supported at this time. Both MPC and AI training are computationally intensive tasks requiring specific setups for efficcient use. The current roadmap includes support for Federated Learning and other training procedures for privacy-preserving AI training.*
- *The described workloads have been tested on the Nillion devnet tool. Due to high demand, running large models on the Nillion Testnet or Mainnet may not always be possible. For specific use cases or if you wish to run models on the Testnet or Mainnet, please contact us [here](https://app.deform.cc/form/51a162ff-4ffb-4d9b-86ec-249f087a332f/?page_number=0).*
- _AI training is **not** supported at this time. Both MPC and AI training are computationally intensive tasks requiring specific setups for efficcient use. The current roadmap includes support for Federated Learning and other training procedures for privacy-preserving AI training._
- _The described workloads have been tested on the Nillion devnet tool. Due to high demand, running large models on the Nillion Testnet or Mainnet may not always be possible. For specific use cases or if you wish to run models on the Testnet or Mainnet, please contact us [here](https://app.deform.cc/form/51a162ff-4ffb-4d9b-86ec-249f087a332f/?page_number=0)._

Embark on your journey with Nada AI and revolutionize your approach to privacy-preserving machine learning!
Embark on your journey with Nada AI and revolutionize your approach to privacy-preserving machine learning!
17 changes: 0 additions & 17 deletions docs/nada-ai-toolkit.md

This file was deleted.

23 changes: 23 additions & 0 deletions docs/nada-libraries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import DocCardList from '@theme/DocCardList';

# Nada Libraries

The Nillion Network leverages [Nada](/nada-lang) for defining programs. We are developing a set of libraries to enhance the developer experience when developing with Artificial Intelligence models and beyond on Nillion. These libraries are built on top of Nada DSL and are meant to be intercompatible with it.

## Nada Numpy

[nada-numpy](/nada-numpy-introduction) is a Python library for algebraic operations on NumPy-like arrays using Nada DSL and the Nillion Network. It offers an easy-to-use interface for various computations like dot products, element-wise operations, and stacking, with broadcasting support similar to NumPy. Key Features include

- Matrix operations: Perform common matrix operations on NadaArrays (a NumPy-like matrix object).
- Element-wise Operations: Perform matrix arithmetic with support for broadcasting.
- Rational Number Support: Use Rational and SecretRational for simplified decimal number operations on Nillion.

## Nada AI

[nada-ai](/nada-ai-introduction) is a Python library for performing ML/AI tasks using Nada DSL and the Nillion Network. It offers an intuitive interface and seamless integration with ML frameworks like PyTorch and Sci-kit learn. Key Features include

- Exporting Model State: Integrates with models from existing ML frameworks, making it easy to export them to the Nillion network for use in Nada programs.
- AI Modules: Provides a PyTorch-like interface to create ML models in Nada by stacking pre-built common components, with the option to create custom components.
- Importing Model State: Easily import an exported model state from the Nillion network for use in a Nada program.

<DocCardList />
34 changes: 21 additions & 13 deletions docs/nada-numpy-introduction.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Nada Numpy Introduction
# Nada Numpy

Nada Numpy is an opinionated clone of Numpy, seamlessly integrated with the Nada DSL. It allows for fast and efficient manipulation of array structures using Nada DSL, while extending functionality to include interfacing with decimal numbers.
[nada-numpy](https://github.com/NillionNetwork/nada-numpy/) is an opinionated clone of Numpy, seamlessly integrated with the Nada DSL. It allows for fast and efficient manipulation of array structures using Nada DSL, while extending functionality to include interfacing with decimal numbers.

One key difference between Numpy and Nada Numpy is that Nada Numpy enforces strong typing. Unlike Numpy, which dynamically changes types, Nada Numpy requires a strongly-typed interface, working with root families (`Integer`, `UnsignedInteger`, `Rational`, and `SecretBoolean`).

Expand All @@ -9,6 +9,7 @@ In this tutorial, we’ll explore the capabilities of Nada Numpy together. Befor
## Installation

First things first, let’s get Nada Numpy installed on your system. It’s as easy as running:

```bash
pip install nada-numpy
```
Expand All @@ -17,18 +18,20 @@ pip install nada-numpy

Nada Numpy aligns with the structure of the Nada DSL. A typical Nada Numpy program comprises the following sections:

1. Import Section
2. Party Declaration Section
3. Input Declaration Section
4. Computation Section
5. Output Section
1. Import Section
2. Party Declaration Section
3. Input Declaration Section
4. Computation Section
5. Output Section

To get started, we can initialize our project structure with the following command:

```bash
nada init hello-nada-numpy
```

This sets up everything we need. Now, let’s dive into the code! We’ll create a program that adds two arrays, similar to the Nada DSL starter which adds two variables. Here’s the complete code to put in `src/main.py`:

```python
from nada_dsl import *
import nada_numpy as na
Expand All @@ -46,7 +49,6 @@ def nada_main():

Let’s break this down step-by-step.


### 1. Party Declaration Section

Start by importing the necessary modules. We need Nada DSL and Nada Numpy, so we import them like this:
Expand All @@ -55,6 +57,7 @@ Start by importing the necessary modules. We need Nada DSL and Nada Numpy, so we
from nada_dsl import *
import nada_numpy as na
```

Next, define the main function for our program:

```python
Expand All @@ -80,9 +83,11 @@ Now, let’s define our inputs. We’ll create two `NadaArrays`, each with three
This line creates an array a with 3 elements, owned by `Party0`, named `“A”`, and of type `SecretInteger`.

Similarly, we define the second array b:

```python
b = na.array([3], parties[1], "B", SecretInteger)
```

This array is also 3 elements long, owned by `Party1`, named `“B”`, and of type `SecretInteger`.

:::tip
Expand All @@ -92,8 +97,9 @@ Under the hood, NadaArray creates variables for each element of the array. For e
:::

### 3. Computation Phase
With our inputs ready, we can perform computations. Adding the two arrays is straightforward. In the Numpy fashion, we'll be operating all the variables consecutively with the `+` operator.


With our inputs ready, we can perform computations. Adding the two arrays is straightforward. In the Numpy fashion, we'll be operating all the variables consecutively with the `+` operator.

```python
res = a + b
```
Expand All @@ -102,11 +108,10 @@ This line operates each entry of the array linearly. If our input arrays were: `

:::tip

You can experiment with different operations (+, -, *, /) and array dimensions to see what Nada Numpy can do!
You can experiment with different operations (+, -, \*, /) and array dimensions to see what Nada Numpy can do!

:::


### 4. Output Section

Finally, we need to produce the output. Since `NadaArray` is not a base Nada type, we use the `.output` method to generate the output. This method takes the output party and the output variable name as arguments:
Expand All @@ -118,6 +123,7 @@ Finally, we need to produce the output. Since `NadaArray` is not a base Nada typ
In this case, we'll be invoking `res.output(parties[2], "my_output")` establishing that the output party will be `Party2`and the name of the output variable will be `"my_output"`.

With everything in place, we can build and test our program:

```bash
nada build
```
Expand All @@ -127,6 +133,7 @@ nada build
After completing the program writing, we can upload it and interact with it in the network with the ease provided by Nada Numpy. For that, we use the Python Nillion Client. We can use the same complete code as for other examples. The only difference is how Nada Numpy allows to easily include arrays in our uploads to the Nillion Networ with the Nada Numpy client. We add the link to the [complete code](https://github.com/NillionNetwork/nada-algebra/blob/main/examples/broadcasting/main.py).

First, import the necessary modules:

```python
import numpy as np
import nada_numpy.client as na_client
Expand All @@ -138,6 +145,7 @@ Then, we can use it to introduce arrays with a similar syntax that will take car
A = np.ones((3,)) # Sample numpy array with ones [1, 1, 1]
stored_secret = nillion.Secrets(na_client.array(A, "A"))
```

And that’s it! You’ve successfully created, built, and integrated a Nada Numpy program with the Nillion Network.

For more examples, please visit our [Github Repository Examples](https://github.com/NillionNetwork/nada-algebra/tree/main/examples).
For more examples, please visit our [Github Repository Examples](https://github.com/NillionNetwork/nada-algebra/tree/main/examples).
138 changes: 79 additions & 59 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,75 +217,95 @@ const sidebars = {
},
],
},
],
},
{
type: 'category',
label: 'Nada AI Toolkit',
link: {
type: 'doc',
id: 'nada-ai-toolkit',
},
items: [
{
type: 'category',
label: 'Nada Numpy',
link: {
type: 'doc',
id: 'nada-numpy-introduction',
},
items: [
{
type: 'doc',
label: 'Nada Rationals',
id: 'nada-numpy-rationals',
},
{
type: 'doc',
label: 'Dot Product',
id: 'nada-numpy-dot-product',
},
{
type: 'doc',
label: 'Matrix Multiplication',
id: 'nada-numpy-matrix-multiplication',
},
{
type: 'doc',
label: 'Nada Numpy Array Operators',
id: 'nada-numpy-operators',
},
{
type: 'doc',
label: 'Nada Numpy Array Functions',
id: 'nada-numpy-array-functions',
},
]
},
{
type: 'category',
label: 'Nada AI',
label: 'Nada Libraries',
link: {
type: 'doc',
id: 'nada-ai-introduction',
id: 'nada-libraries',
},
items: [
{
type: 'doc',
label: 'Nada AI Linear Model Tutorial',
id: 'nada-ai-linear-model',
},
{
type: 'doc',
label: 'Nada AI Deep Learning Tutorial',
id: 'nada-ai-neural-network',
type: 'category',
label: 'nada-numpy',
link: {
type: 'doc',
id: 'nada-numpy-introduction',
},
items: [
{
type: 'doc',
label: 'Nada Rationals',
id: 'nada-numpy-rationals',
},
{
type: 'doc',
label: 'Dot Product',
id: 'nada-numpy-dot-product',
},
{
type: 'doc',
label: 'Matrix Multiplication',
id: 'nada-numpy-matrix-multiplication',
},
{
type: 'doc',
label: 'Nada Numpy Array Operators',
id: 'nada-numpy-operators',
},
{
type: 'doc',
label: 'Nada Numpy Array Functions',
id: 'nada-numpy-array-functions',
},
{
type: 'link',
label: 'nada-numpy library',
href: 'https://github.com/NillionNetwork/nada-numpy/',
},
{
type: 'link',
label: 'nada-numpy examples',
href: 'https://github.com/NillionNetwork/nada-numpy/tree/main/examples',
},
],
},
{
type: 'doc',
label: 'Nada AI Reference',
id: 'nada-ai-reference',
type: 'category',
label: 'nada-ai',
link: {
type: 'doc',
id: 'nada-ai-introduction',
},
items: [
{
type: 'doc',
label: 'Nada AI Linear Model Tutorial',
id: 'nada-ai-linear-model',
},
{
type: 'doc',
label: 'Nada AI Deep Learning Tutorial',
id: 'nada-ai-neural-network',
},
{
type: 'doc',
label: 'Nada AI Reference',
id: 'nada-ai-reference',
},
{
type: 'link',
label: 'nada-ai library',
href: 'https://github.com/NillionNetwork/nada-ai/',
},
{
type: 'link',
label: 'nada-ai examples',
href: 'https://github.com/NillionNetwork/nada-ai/tree/main/examples',
},
],
},
]
],
},
],
},
Expand Down

0 comments on commit 28a0b14

Please sign in to comment.