Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into merge-from-upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
jjassonn committed Sep 18, 2024
2 parents ffed42e + a319902 commit a6d233c
Show file tree
Hide file tree
Showing 49 changed files with 3,510 additions and 1,524 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[flake8]
max-line-length = 88
extend-ignore = E203,E701
per-file-ignores =
__init__.py: F401
101 changes: 101 additions & 0 deletions .github/workflows/ai-runner-pipelines-docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Build ai-runner pipeline Docker images

on:
pull_request:
paths:
- "runner/**"
- "!runner/.devcontainer/**"
push:
branches:
- main
tags:
- '*'
paths:
- "runner/**"
- "!runner/.devcontainer/**"
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
sam2-docker:
name: SAM2 Docker image generation
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'workflow_dispatch'
permissions:
packages: write
contents: read
runs-on: ubuntu-20.04
steps:
- name: Check out code
uses: actions/[email protected]
with:
fetch-depth: 0
# Check https://github.com/livepeer/go-livepeer/pull/1891
# for ref value discussion
ref: ${{ github.event.pull_request.head.sha }}

- name: Cleanup hosted runner
run: |
sudo apt purge -yqq dotnet-* mono-* llvm-* libllvm* powershell* openjdk-* \
temurin-* mongodb-* firefox mysql-* \
hhvm google-chrome-stable \
libgl1-mesa-dri microsoft-edge-stable azure-cli || true
sudo apt autoremove -y
sudo rm -rf /usr/share/dotnet /usr/local/lib/android
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.CI_DOCKERHUB_USERNAME }}
password: ${{ secrets.CI_DOCKERHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
livepeer/ai-runner
tags: |
type=raw,value=sam2
type=raw,value=segment-anything-2
type=sha,prefix=sam2-
type=ref,event=pr,prefix=sam2-
type=ref,event=tag,prefix=sam2-
type=sha,format=long,prefix=sam2-
type=ref,event=branch,prefix=sam2-
type=semver,pattern={{version}},prefix=sam2-
type=semver,pattern={{major}}.{{minor}},prefix=sam2-
type=semver,pattern={{version}},prefix=sam2-v
type=semver,pattern={{major}}.{{minor}},prefix=sam2-v
type=raw,value=latest,enable={{is_default_branch}},prefix=sam2-
type=raw,value=${{ github.event.pull_request.head.ref }},enable=${{ github.event_name == 'pull_request' }},prefix=sam2-
type=raw,value=stable,enable=${{ startsWith(github.event.ref, 'refs/tags/v') }},prefix=sam2-
- name: Build and push runner docker image
uses: docker/build-push-action@v5
with:
context: "{{defaultContext}}:runner"
platforms: linux/amd64
push: true
tags: ${{ steps.meta.outputs.tags }}
file: "Dockerfile"
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=livepeerci/build:cache
cache-to: type=registry,ref=livepeerci/build:cache,mode=max

- name: Build and push runner docker image
uses: docker/build-push-action@v5
with:
context: "{{defaultContext}}:runner"
platforms: linux/amd64
push: true
tags: ${{ steps.meta.outputs.tags }}
file: "docker/Dockerfile.segment_anything_2"
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=livepeerci/build:cache
cache-to: type=registry,ref=livepeerci/build:cache,mode=max
4 changes: 3 additions & 1 deletion .github/workflows/docker-create-ai-runner.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build Docker image for ai-runner
name: Build ai-runner base Docker image

on:
check_run:
Expand All @@ -22,6 +22,7 @@ concurrency:
jobs:
docker:
name: Docker image generation
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'workflow_dispatch'
permissions:
packages: write
contents: read
Expand Down Expand Up @@ -61,6 +62,7 @@ jobs:
type=semver,pattern={{version}},prefix=v
type=semver,pattern={{major}}.{{minor}},prefix=v
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=base,enable={{is_default_branch}}
type=raw,value=${{ github.event.pull_request.head.ref }}
type=raw,value=stable,enable=${{ startsWith(github.event.ref, 'refs/tags/v') }}
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/validate-openapi-on-push.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
name: Check OpenAPI spec and Golang bindings

on:
check_run:
push:
branches:
- main
pull_request:

jobs:
check-openapi-and-bindings:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Python
uses: actions/setup-python@v5
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ codegen:
go run github.com/deepmap/oapi-codegen/v2/cmd/[email protected] \
-package worker \
-generate types,client,chi-server,spec \
runner/openapi.json \
runner/openapi.yaml \
| awk '!/WARNING/' > worker/runner.gen.go
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# ai-worker

> [!NOTE]
> This branch will explore adding AI inference to realtime video streams. Majority of the commits here will likely change significantly and not intended for production purposes.
> [!WARNING]
> This is a prototype repository undergoing rapid changes. It's not intended for production use yet.
> 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.

Expand Down
2 changes: 1 addition & 1 deletion cmd/examples/image-to-image/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func main() {
imageFile := types.File{}
imageFile.InitFromBytes(imageBytes, imagePath)

req := worker.ImageToImageMultipartRequestBody{
req := worker.GenImageToImageMultipartRequestBody{
Image: imageFile,
ModelId: &modelID,
Prompt: prompt,
Expand Down
2 changes: 1 addition & 1 deletion cmd/examples/image-to-video/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func main() {
imageFile := types.File{}
imageFile.InitFromBytes(imageBytes, imagePath)

req := worker.ImageToVideoMultipartRequestBody{
req := worker.GenImageToVideoMultipartRequestBody{
Image: imageFile,
ModelId: &modelID,
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/examples/text-to-image/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func main() {

prompt := args[1]

req := worker.TextToImageJSONRequestBody{
req := worker.GenTextToImageJSONRequestBody{
ModelId: &modelID,
Prompt: prompt,
}
Expand Down
16 changes: 5 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,11 @@ require (
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect
go.opentelemetry.io/otel v1.28.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/otel/sdk v1.28.0 // indirect
go.opentelemetry.io/otel/trace v1.28.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/tools v0.21.0 // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/tools v0.24.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.5.1 // indirect
)
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -120,25 +120,25 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
Expand All @@ -149,8 +149,8 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.21.0 h1:qc0xYgIbsSDt9EyWz05J5wfa7LOVW0YTLOXrqdLAWIw=
golang.org/x/tools v0.21.0/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24=
golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
4 changes: 2 additions & 2 deletions runner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ The AI Runner container's runner app uses [HuggingFace](https://huggingface.co/)
3. **Download AI Models**: Use the [ld_checkpoints.sh](https://github.com/livepeer/ai-worker/blob/main/runner/dl_checkpoints.sh) script to download models from `aiModels.json` to `~/.lpData/models`. Run the following command in the `.lpData` directory:

```bash
curl -s https://raw.githubusercontent.com/livepeer/ai-worker/main/runner/dl_checkpoints.sh | bash -s -- --alpha
curl -s https://raw.githubusercontent.com/livepeer/ai-worker/main/runner/dl_checkpoints.sh | bash -s -- --beta
```

> [!NOTE]
> The `--alpha` flag downloads only models supported by the Livepeer.inc Gateway node on the _AI Subnet_. Remove this flag to download all models.
> The `--beta` flag downloads only models supported by the Livepeer.inc Gateway node on the _AI Subnet_. Remove this flag to download all models.
> [!TIP]
> If you want to download individual models you can checkout the `dl-checkpoints.sh` script to see how to download model checkpoints to the local `models` directory.
Expand Down
10 changes: 8 additions & 2 deletions runner/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ async def lifespan(app: FastAPI):
app.pipeline = load_pipeline(pipeline, model_id)
app.include_router(load_route(pipeline))

use_route_names_as_operation_ids(app)

logger.info(f"Started up with pipeline {app.pipeline}")
yield
logger.info("Shutting down")
Expand Down Expand Up @@ -56,6 +54,10 @@ def load_pipeline(pipeline: str, model_id: str) -> any:
from app.pipelines.upscale import UpscalePipeline

return UpscalePipeline(model_id)
case "segment-anything-2":
from app.pipelines.segment_anything_2 import SegmentAnything2Pipeline

return SegmentAnything2Pipeline(model_id)
case _:
raise EnvironmentError(
f"{pipeline} is not a valid pipeline for model {model_id}"
Expand Down Expand Up @@ -88,6 +90,10 @@ def load_route(pipeline: str) -> any:
from app.routes import upscale

return upscale.router
case "segment-anything-2":
from app.routes import segment_anything_2

return segment_anything_2.router
case _:
raise EnvironmentError(f"{pipeline} is not a valid pipeline")

Expand Down
10 changes: 7 additions & 3 deletions runner/app/pipelines/audio_to_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,16 @@ def __init__(self, model_id: str):
kwargs["torch_dtype"] = torch.bfloat16

model = AutoModelForSpeechSeq2Seq.from_pretrained(
model_id, low_cpu_mem_usage=True, use_safetensors=True, cache_dir=get_model_dir(), **kwargs
model_id,
low_cpu_mem_usage=True,
use_safetensors=True,
cache_dir=get_model_dir(),
**kwargs,
).to(torch_device)

processor = AutoProcessor.from_pretrained(model_id, cache_dir=get_model_dir())

self.ldm = pipeline(
self.tm = pipeline(
"automatic-speech-recognition",
model=model,
tokenizer=processor.tokenizer,
Expand All @@ -72,7 +76,7 @@ def __call__(self, audio: UploadFile, **kwargs) -> List[File]:
converted_bytes = audio_converter.convert(audio, "mp3")
audio_converter.write_bytes_to_file(converted_bytes, audio)

return self.ldm(audio.file.read(), **kwargs)
return self.tm(audio.file.read(), **kwargs)

def __str__(self) -> str:
return f"AudioToTextPipeline model_id={self.model_id}"
Loading

0 comments on commit a6d233c

Please sign in to comment.