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

worker: Move ai-worker package to go-livepeer #396

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
File renamed without changes.
5 changes: 0 additions & 5 deletions .flake8

This file was deleted.

35 changes: 0 additions & 35 deletions .github/workflows/ai-worker-test.yaml

This file was deleted.

10 changes: 0 additions & 10 deletions .github/workflows/validate-openapi-on-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,3 @@ jobs:
echo "::error:: OpenAPI spec has changed. Please run 'python gen_openapi.py' in the 'runner' directory and commit the changes."
exit 1
fi

- name: Generate Go bindings
run: make

- name: Check for Go bindings changes
run: |
if ! git diff --exit-code; then
echo "::error::Go bindings have changed. Please run 'make' at the root of the repository and commit the changes."
exit 1
fi
9 changes: 0 additions & 9 deletions Makefile

This file was deleted.

67 changes: 49 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,69 @@
# ai-worker
# ai-runner

> [!WARNING]
> The AI network is in it's **Beta** phase and although it is ready for production it is still under development. Please report any issues you encounter to the [Livepeer Discord](https://discord.gg/7nbPbTK).

This repository hosts the AI worker and runner for processing inference requests on the Livepeer AI subnet.
This repository hosts the AI runner for processing AI inference jobs on the Livepeer network.

## Overview

The AI worker repository includes:
The AI runner is a containerized Python application which processes inference requests on Livepeer AI's Pipelines and models. It loads models into GPU memory and exposes a REST API other programs like [the Livepeer node AI worker](../README.md) can use to request AI inference requests. The AI runner code sits in the [runner](https://github.com/livepeer/ai-runner/tree/main/runner) directory.

- **Runner**: The [AI runner](https://github.com/livepeer/ai-worker/tree/main/runner), a containerized Python application, processes inference requests on Livepeer AI's Pipelines and models, providing a REST API for model interaction.
## Build

- **Worker**: The [AI worker](https://github.com/livepeer/ai-worker) allows the [ai-video](https://github.com/livepeer/go-livepeer/tree/ai-video) branch of [go-livepeer](https://github.com/livepeer/go-livepeer/tree/ai-video) to interact with the AI runner. It includes golang API bindings, a worker for routing inference requests, and a Docker manager for AI runner containers.
To build the AI runner locally and run examples, follow these steps:

### Runner
1. Follow the instructions in this document to download model checkpoints and build the runner image.
2. Generate Go bindings for the runner OpenAPI spec with `make codegen`.
3. Run any examples in the `cmd/examples` directory, e.g., `go run cmd/examples/text-to-image/main.go <RUNS> <PROMPT>`.

The AI runner's code is in the [runner](https://github.com/livepeer/ai-worker/tree/main/runner) directory. For more details, see the [AI runner README](./runner/README.md).
## Architecture

### Worker
A high level sketch of how the runner is used:

The AI worker's code is in the [worker](https://github.com/livepeer/ai-worker/tree/main/worker) directory. It includes:
![Architecture](./docs/images/architecture.png)

- **Golang API Bindings**: Generated from the AI runner's OpenAPI spec using `make codegen`.
- **Worker**: Listens for inference requests from the Livepeer AI subnet and routes them to the AI runner.
- **Docker Manager**: Manages AI runner containers.
The AI runner, found in the [app](./runner/app) directory, consists of:

## Build
- **Routes**: FastAPI routes in [app/routes](./runner/app/routes) that handle requests and delegate them to the appropriate pipeline.
- **Pipelines**: Modules in [app/pipelines](./runner/app/pipelines) that manage model loading, request processing, and response generation for specific AI tasks.

The AI worker and runner are designed to work with the [ai-video](https://github.com/livepeer/go-livepeer/tree/ai-video) branch of [go-livepeer](https://github.com/livepeer/go-livepeer/tree/ai-video). You can run both independently for testing. To build the AI worker locally and run examples, follow these steps:
It also includes utility scripts:

1. Follow the [README](./runner/README.md) instructions in the [runner](./runner/README.md) directory to download model checkpoints and build the runner image.
2. Generate Go bindings for the runner OpenAPI spec with `make codegen`.
3. Run any examples in the `cmd/examples` directory, e.g., `go run cmd/examples/text-to-image/main.go <RUNS> <PROMPT>`.
- **[bench.py](./runner/bench.py)**: Benchmarks the runner's performance.
- **[gen_openapi.py](./runner/gen_openapi.py)**: Generates the OpenAPI specification for the runner's API endpoints.
- **[dl_checkpoints.sh](./runner/dl_checkpoints.sh)**: Downloads model checkpoints from Hugging Face.
- **[modal_app.py](./runner/modal_app.py)**: Deploys the runner on [Modal](https://modal.com/), a serverless GPU platform.

## OpenAPI Specification

Regenerate the OpenAPI specification for the AI runner's API endpoints with:

```bash
python gen_openapi.py
```

To correspondingly generate the Go client bindings in the go-livepeer repository,
you should install `livepeer/go-livepeer` and run:
```bash
# in the go-livepeer repo
make ai_worker_codegen
```

Alternatively, if you want to test the client from a development version of
`ai-runner`, you can specify a commit hash or branch to generate from:
```bash
# for commit `aa7ab76`
make ai_worker_codegen REF=aa7ab76
# for branch `test`
make ai_worker_codegen REF=refs/heads/vg/chore/test
```

## Development documentation

For more on developing and debugging the AI runner, see the [development documentation](./dev/README.md).
For more on developing and debugging the AI runner, see the [development documentation](./docs/development-guide.md).

## Credits

Based off of [this repo](https://github.com/huggingface/api-inference-community/tree/main/docker_images/diffusers).

Loading