Skip to content

Commit

Permalink
Merge pull request #2959 from livepeer/ai-video
Browse files Browse the repository at this point in the history
Livepeer AI Subnet
  • Loading branch information
leszko authored Nov 7, 2024
2 parents f20d1ff + 0a56bd1 commit 58a64dc
Show file tree
Hide file tree
Showing 87 changed files with 12,496 additions and 1,147 deletions.
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Default reviewers for the `ai-video` branch.
# TODO: Change if merged into `master` branch.
* @rickstaa
67 changes: 50 additions & 17 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
pull_request:
push:
branches:
- master
- ai-video
tags:
- "v*"

Expand All @@ -29,25 +29,25 @@ jobs:
container: ubuntu:20.04
type: cpu

- GOOS: linux
GOARCH: arm64
container: ubuntu:20.04
type: cpu
# - GOOS: linux
# GOARCH: arm64
# container: ubuntu-20.04
# type: cpu

- GOOS: linux
GOARCH: amd64
container: livepeerci/cuda:12.0.0-cudnn8-devel-ubuntu20.04
type: gpu

- GOOS: linux
GOARCH: arm64
container: livepeerci/cuda:12.0.0-cudnn8-devel-ubuntu20.04
type: gpu
# - GOOS: linux
# GOARCH: arm64
# container: livepeerci/cuda:12.0.0-cudnn8-devel-ubuntu20.04
# type: gpu

- GOOS: windows
GOARCH: amd64
container: ubuntu:22.04
type: cpu
# - GOOS: windows
# GOARCH: amd64
# container: ubuntu:22.04
# type: cpu

steps:
- name: Setup ubuntu container
Expand All @@ -69,7 +69,7 @@ jobs:
id: go
uses: actions/setup-go@v5
with:
go-version: 1.20.4
go-version: 1.23.2
cache: true
cache-dependency-path: go.sum

Expand Down Expand Up @@ -100,7 +100,8 @@ jobs:
&& apt update \
&& apt -yqq install \
nasm clang-14 clang-tools-14 lld-14 build-essential pkg-config autoconf git python3 \
gcc-mingw-w64 libgcc-9-dev-arm64-cross mingw-w64-tools gcc-mingw-w64-x86-64 mingw-w64-x86-64-dev
gcc-mingw-w64 libgcc-9-dev-arm64-cross mingw-w64-tools gcc-mingw-w64-x86-64 mingw-w64-x86-64-dev \
golang-goprotobuf-dev protobuf-compiler-grpc
update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-14 30 \
&& update-alternatives --install /usr/bin/clang clang /usr/bin/clang-14 30 \
Expand Down Expand Up @@ -170,7 +171,7 @@ jobs:
id: go
uses: actions/setup-go@v5
with:
go-version: 1.20.4
go-version: 1.23.2
cache: true
cache-dependency-path: go.sum

Expand Down Expand Up @@ -212,7 +213,7 @@ jobs:
id: match-tag
with:
text: ${{ github.ref_name }}
regex: '^(master|main|v[0-9]+\.\d+\.\d+)$'
regex: '^(master|main|ai-video|v[0-9]+\.\d+\.\d+)$'

- name: Codesign and notarize binaries
if: steps.match-tag.outputs.match != '' && matrix.target.GOOS == 'darwin'
Expand Down Expand Up @@ -316,6 +317,38 @@ jobs:
parent: false
process_gcloudignore: false

# Get the latest release tag
- name: Get latest tag
id: get-latest-tag
run: |
git fetch --tags
latest_tag=$(git tag -l "v*" | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-ai.[0-9]+$' | sort -V | tail -n 1)
echo "latest_tag=$latest_tag" >> $GITHUB_OUTPUT
echo "Latest tag: $latest_tag"
echo "GitHub Ref: ${{ github.ref }}"
# Update the latest release
- name: Upload release archives to Google Cloud stable folder
id: upload-archives-latest
if: ${{ github.ref == format('refs/tags/{0}', steps.get-latest-tag.outputs.latest_tag) }}
uses: google-github-actions/upload-cloud-storage@v2
with:
path: "releases"
destination: "build.livepeer.live/${{ github.event.repository.name }}/ai-video/stable"
parent: false
process_gcloudignore: false

# Update the latest branch manifest
- name: Upload branch manifest file to Google Cloud stable folder
id: upload-manifest-latest
if: ${{ github.ref == format('refs/tags/{0}', steps.get-latest-tag.outputs.latest_tag) }}
uses: google-github-actions/upload-cloud-storage@v2
with:
path: ${{ steps.branch-manifest.outputs.manifest-file }}
destination: "build.livepeer.live/${{ github.event.repository.name }}/ai-video/stable"
parent: false
process_gcloudignore: false

- name: Trigger discord webhook
shell: bash
env:
Expand Down
11 changes: 7 additions & 4 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ on:
pull_request:
push:
branches:
- master
# - master
- ai-video
tags:
- "v*"

Expand Down Expand Up @@ -89,7 +90,8 @@ jobs:
build-args: |
BUILD_TAGS=${{ steps.build-tag.outputs.build-tags }}
context: .
platforms: linux/amd64, linux/arm64
# platforms: linux/amd64, linux/arm64 # NOTE: Arm64 not yet supported.
platforms: linux/amd64
push: true
tags: ${{ steps.meta.outputs.tags }}
file: "docker/Dockerfile"
Expand Down Expand Up @@ -126,7 +128,7 @@ jobs:
id: match-tag
with:
text: ${{ github.ref_name }}
regex: '^(main|master|v[0-9]+\.\d+\.\d+)$'
regex: '^(main|master|ai-video|v[0-9]+\.\d+\.\d+|v[0-9]+\.\d+\.\d+-ai-video-\d+)'

- name: Get build tags
id: build-tag
Expand Down Expand Up @@ -177,7 +179,8 @@ jobs:
build-args: |
BUILD_TAGS=${{ steps.build-tag.outputs.build-tags }}
context: .
platforms: linux/amd64, linux/arm64
# platforms: linux/amd64, linux/arm64 # NOTE: Arm64 not yet supported.
platforms: linux/amd64
push: true
tags: ${{ steps.meta-builder.outputs.tags }}
file: "docker/Dockerfile"
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
branches:
- master
- ai-video
push:
branches:
- master
Expand Down Expand Up @@ -43,7 +44,7 @@ jobs:
id: go
uses: actions/setup-go@v5
with:
go-version: 1.20.4
go-version: 1.23.2
cache: true
cache-dependency-path: go.sum

Expand Down Expand Up @@ -94,9 +95,9 @@ jobs:
- name: Lint
uses: golangci/golangci-lint-action@v4
with:
version: v1.52.2
version: v1.61.0
skip-pkg-cache: true
args: '--disable-all --enable=gofmt --enable=vet --enable=golint --deadline=4m pm verification'
args: '--out-format=colored-line-number --disable-all --enable=gofmt --enable=govet --enable=revive --timeout=4m pm verification'

- name: Run Revive Action by building from repository
uses: docker://morphy/revive-action:v2
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
*.dll
*.so
*.dylib

# IDE files
*.vscode
*.code-workspace

# Test binary, build with `go test -c`
*.test
Expand Down
102 changes: 102 additions & 0 deletions ai/file_worker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package ai

import (
"context"
"encoding/json"
"errors"
"os"

"github.com/livepeer/ai-worker/worker"
)

type FileWorker struct {
files map[string]string
}

func NewFileWorker(files map[string]string) *FileWorker {
return &FileWorker{files: files}
}

func (w *FileWorker) TextToImage(ctx context.Context, req worker.GenTextToImageJSONRequestBody) (*worker.ImageResponse, error) {

Check warning on line 20 in ai/file_worker.go

View workflow job for this annotation

GitHub Actions / Run tests defined for the project

parameter 'req' seems to be unused, consider removing or renaming it as _

Check warning on line 20 in ai/file_worker.go

View workflow job for this annotation

GitHub Actions / Run tests defined for the project

parameter 'ctx' seems to be unused, consider removing or renaming it as _
fname, ok := w.files["text-to-image"]
if !ok {
return nil, errors.New("text-to-image response file not found")
}

data, err := os.ReadFile(fname)
if err != nil {
return nil, err
}

var resp worker.ImageResponse
if err := json.Unmarshal(data, &resp); err != nil {
return nil, err
}

return &resp, nil
}

func (w *FileWorker) ImageToImage(ctx context.Context, req worker.GenImageToImageMultipartRequestBody) (*worker.ImageResponse, error) {

Check warning on line 39 in ai/file_worker.go

View workflow job for this annotation

GitHub Actions / Run tests defined for the project

parameter 'req' seems to be unused, consider removing or renaming it as _

Check warning on line 39 in ai/file_worker.go

View workflow job for this annotation

GitHub Actions / Run tests defined for the project

parameter 'ctx' seems to be unused, consider removing or renaming it as _
fname, ok := w.files["image-to-image"]
if !ok {
return nil, errors.New("image-to-image response file not found")
}

data, err := os.ReadFile(fname)
if err != nil {
return nil, err
}

var resp worker.ImageResponse
if err := json.Unmarshal(data, &resp); err != nil {
return nil, err
}

return &resp, nil
}

func (w *FileWorker) ImageToVideo(ctx context.Context, req worker.GenImageToVideoMultipartRequestBody) (*worker.VideoResponse, error) {

Check warning on line 58 in ai/file_worker.go

View workflow job for this annotation

GitHub Actions / Run tests defined for the project

parameter 'req' seems to be unused, consider removing or renaming it as _

Check warning on line 58 in ai/file_worker.go

View workflow job for this annotation

GitHub Actions / Run tests defined for the project

parameter 'ctx' seems to be unused, consider removing or renaming it as _
fname, ok := w.files["image-to-video"]
if !ok {
return nil, errors.New("image-to-video response file not found")
}

data, err := os.ReadFile(fname)
if err != nil {
return nil, err
}

var resp worker.VideoResponse
if err := json.Unmarshal(data, &resp); err != nil {
return nil, err
}

return &resp, nil
}

func (w *FileWorker) Upscale(ctx context.Context, req worker.GenUpscaleMultipartRequestBody) (*worker.ImageResponse, error) {

Check warning on line 77 in ai/file_worker.go

View workflow job for this annotation

GitHub Actions / Run tests defined for the project

parameter 'req' seems to be unused, consider removing or renaming it as _

Check warning on line 77 in ai/file_worker.go

View workflow job for this annotation

GitHub Actions / Run tests defined for the project

parameter 'ctx' seems to be unused, consider removing or renaming it as _
fname, ok := w.files["upscale"]
if !ok {
return nil, errors.New("upscale response file not found")
}

data, err := os.ReadFile(fname)
if err != nil {
return nil, err
}

var resp worker.ImageResponse
if err := json.Unmarshal(data, &resp); err != nil {
return nil, err
}

return &resp, nil
}

func (w *FileWorker) Warm(ctx context.Context, containerName, modelID string) error {

Check warning on line 96 in ai/file_worker.go

View workflow job for this annotation

GitHub Actions / Run tests defined for the project

parameter 'containerName' seems to be unused, consider removing or renaming it as _

Check warning on line 96 in ai/file_worker.go

View workflow job for this annotation

GitHub Actions / Run tests defined for the project

parameter 'ctx' seems to be unused, consider removing or renaming it as _
return nil
}

func (w *FileWorker) Stop(ctx context.Context, containerName string) error {
return nil
}
29 changes: 20 additions & 9 deletions cmd/devtool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,42 @@

An on-chain workflow testing tool that supports the following:

- Automatically submitting the necessary setup transactions for each node type
- Generating a Bash script with default CLI flags to start each node type
- Automatically submitting the necessary setup transactions for each node type
- Generating a Bash script with default CLI flags to start each node type

## Prerequisites

## Step 1: Set up a private ETH network with Livepeer protocol deployed
- [Docker](https://docs.docker.com/get-docker/)
- [Go](https://golang.org/doc/install)
- [Go-livepeer](https://github.com/livepeer/go-livepeer) build from source (see [the docs](https://docs.livepeer.org/orchestrators/guides/install-go-livepeer#build-from-source)).

```
## Setting Up an On-Chain Development Environment

### Step 1: Set up a private ETH network with Livepeer protocol deployed

```bash
docker pull livepeer/geth-with-livepeer-protocol:confluence
docker run -p 8545:8545 -p 8546:8546 --name geth-with-livepeer-protocol livepeer/geth-with-livepeer-protocol:confluence
```


## Step 2: Set up a broadcaster
### Step 2: Set up a broadcaster

`go run cmd/devtool/devtool.go setup broadcaster`

This command will submit the setup transactions for a broadcaster and generate the Bash script
`run_broadcaster_<ETH_ACCOUNT>.sh` which can be used to start a broadcaster node.

## Step 3: Set up a orchestrator/transcoder
### Step 3: Set up a orchestrator/transcoder

`go run cmd/devtool/devtool.go setup transcoder`

This command will submit the setup transactions for an orchestrator/transcoder and generate the Bash scripts:

* `run_orchestrator_with_transcoder_<ETH_ACCOUNT>.sh` which can be used to start an orchestrator node that contains a transcoder (combined OT)
* `run_orchestrator_standalone_<ETH_ACCOUNT>.sh` and `run_transcoder_<ETH_ACCOUNT>.sh` which can be used to start separate orchestrator and transcoder nodes (split O/T)
- `run_orchestrator_with_transcoder_<ETH_ACCOUNT>.sh` which can be used to start an orchestrator node that contains a transcoder (combined OT)
- `run_orchestrator_standalone_<ETH_ACCOUNT>.sh` and `run_transcoder_<ETH_ACCOUNT>.sh` which can be used to start separate orchestrator and transcoder nodes (split O/T)

## Extra Resources

### Scripts

Some helpful scripts are provided in the `scripts` directory.
Loading

0 comments on commit 58a64dc

Please sign in to comment.