Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NOISSUE - Fix Docker Algorithm #40

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 33 additions & 24 deletions docs/algorithms.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Currently, cocos supports running the following algorithms:

- binary algorithms
- python scripts
- docker images
- wasm modules

## Binary Algorithms
Expand Down Expand Up @@ -353,11 +354,11 @@ For real-world examples to test with cocos, see our [AI repository](https://gith

Python is a high-level, interpreted programming language. Python scripts can be run on the enclave. Python is known for its simplicity and readability, making it a popular choice for beginners and experienced developers alike.

## Running Python Algorithms without Datasets
### Running Python Algorithms without Datasets

This has been covered in the [previous section](./getting-started.md#uploading-artefacts).

## Running Python Algorithms with Datasets
### Running Python Algorithms with Datasets

For Python algorithms, with datatsets:

Expand Down Expand Up @@ -491,27 +492,13 @@ We will use the linear regression example from the cocos repository in this exam
git clone https://github.com/ultravioletrs/cocos.git
```

Then, use your favorite editor to create a file named `Dockerfile` in the current working directory and write the following code.
Change directory to the linear regression example.

```bash
FROM python:3.9-slim

# set the working directory in the container
WORKDIR /cocos
RUN mkdir /cocos/results
RUN mkdir /cocos/datasets

COPY ./cocos/test/manual/algo/requirements.txt /cocos/requirements.txt
COPY ./cocos/test/manual/algo/lin_reg.py /cocos/lin_reg.py

# install dependencies
RUN pip install -r requirements.txt

# command to be run when the docker container is started
CMD ["python3", "/cocos/lin_reg.py"]
cd cocos/test/manual/algo/
```

Next, run the build command and save the docker image as a `tar` file.
Next, run the build command and save the docker image as a `tar` file. This example Dockerfile is based of the python linear regression example using iris dataset.

```bash
docker build -t linreg .
Expand All @@ -529,32 +516,37 @@ cd ./cocos
Start the computation server:

```bash
go run ./test/computations/main.go ./test/manual/algo/lin_reg.py public.pem false ./test/manual/data/iris.csv
go run ./test/computations/main.go ./test/manual/algo/linreg.tar public.pem false ./test/manual/data/iris.csv
```

Start the manager

```bash
cd cmd/manager
```

```bash
sudo \
MANAGER_QEMU_SMP_MAXCPUS=4 \
MANAGER_QEMU_MEMORY_SIZE=25G \
MANAGER_GRPC_URL=localhost:7001 \
MANAGER_LOG_LEVEL=debug \
MANAGER_QEMU_ENABLE_SEV_SNP=false \
MANAGER_QEMU_OVMF_CODE_FILE=/usr/share/edk2/x64/OVMF_CODE.fd \
MANAGER_QEMU_OVMF_VARS_FILE=/usr/share/edk2/x64/OVMF_VARS.fd \
go run ./cmd/manager/main.go
go run main.go
```

Export the agent grpc url from computation server logs

```bash
export AGENT_GRPC_URL=localhost:6015
export AGENT_GRPC_URL=localhost:6100
SammyOina marked this conversation as resolved.
Show resolved Hide resolved
```

Upload the algorithm

```bash
./build/cocos-cli algo ../linreg.tar ./private.pem -a docker
./build/cocos-cli algo ./test/manual/algo/linreg.tar ./private.pem -a docker
```

Upload the dataset
Expand All @@ -569,12 +561,29 @@ After some time when the results are ready, you can run the following command to
./build/cocos-cli results ./private.pem
```

The logs will be similar to this:

```bash
2024/08/19 14:14:31 Retrieving computation result file
2024/08/19 14:14:31 Computation result retrieved and saved successfully!
SammyOina marked this conversation as resolved.
Show resolved Hide resolved
```

Unzip the results

```bash
unzip results.zip -d results
```

To make inference on the results, you can use the following command:

```bash
python3 ./test/manual/algo/lin_reg.py predict result.zip ./test/manual/data
python3 test/manual/algo/lin_reg.py predict results/model.bin test/manual/data/
```

Terminal recording session

[![asciicast](https://asciinema.org/a/vHaUnKoEcXwHJR78EBzTScCuS.svg)](https://asciinema.org/a/vHaUnKoEcXwHJR78EBzTScCuS)

## Wasm Modules

WebAssembly (wasm) is a binary instruction format for a stack-based virtual machine. Wasm is designed as a portable target for compilation of high-level languages like C/C++/Rust, enabling deployment on the web for client and server applications. Wasm modules can be run on the enclave.
Expand Down