Skip to content

Commit

Permalink
added github workflows, minor fixes on init/deps
Browse files Browse the repository at this point in the history
  • Loading branch information
realyashnag committed Sep 16, 2024
1 parent 6147aff commit c3ac01a
Show file tree
Hide file tree
Showing 8 changed files with 236 additions and 8 deletions.
16 changes: 16 additions & 0 deletions .github/tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"hardwareConfig": {
"endpointConfig": {
"gpuIds": "AMPERE_16",
"name": "16GB GPU"
}
},
"input": {
"audio": "https://github.com/runpod-workers/sample-inputs/raw/main/audio/gettysburg.wav",
"model_name": "tiny",
"language": null,
"batch_size": 16
}
}
]
35 changes: 35 additions & 0 deletions .github/workflows/CD-docker_dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Docker Image

on:
push:
branches:
- "main"

jobs:
docker:
runs-on: DO
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v4
with:
push: true
tags: ${{ vars.DOCKERHUB_REPO }}/${{ vars.DOCKERHUB_IMG }}:dev
- uses: actions/checkout@v3
- name: Run Tests
uses: direlines/[email protected]
with:
image-tag: ${{ vars.DOCKERHUB_REPO }}/${{ vars.DOCKERHUB_IMG }}:dev
runpod-api-key: ${{ secrets.RUNPOD_API_KEY }}
request-timeout: 600
27 changes: 27 additions & 0 deletions .github/workflows/CD-docker_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Docker Image

on:
release:
types: [published]

jobs:
docker:
runs-on: DO
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v4
with:
push: true
tags: ${{ secrets.DOCKERHUB_REPO }}/${{ secrets.DOCKERHUB_IMG }}:${{ github.event.release.tag_name }}
52 changes: 52 additions & 0 deletions .github/workflows/CI-runpod_dep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: CI | Update runpod package version

on:
repository_dispatch:
types: [python-package-release]

push:
branches:
- "main"
- "master"

workflow_dispatch:

jobs:
check_dep:
runs-on: ubuntu-latest
name: Check python requirements file and update
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Check for new package version and update
run: |
# Get current version
current_version=$(grep -oP 'runpod==\K[^"]+' ./builder/requirements.txt)
# Get new version
new_version=$(curl -s https://pypi.org/pypi/runpod/json | jq -r .info.version)
echo "NEW_VERSION_ENV=$new_version" >> $GITHUB_ENV
if [ -z "$new_version" ]; then
echo "Failed to fetch the new version."
exit 1
fi
# Check if the version is already up-to-date
if [ "$current_version" = "$new_version" ]; then
echo "The package version is already up-to-date."
exit 0
fi
# Update requirements.txt
sed -i "s/runpod==.*/runpod==$new_version/" ./builder/requirements.txt
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Update package version
title: Update runpod package version
body: The package version has been updated to ${{ env.NEW_VERSION_ENV }}
branch: runpod-package-update
85 changes: 85 additions & 0 deletions .github/workflows/CI-test_handler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: CI | Test Worker

on:
push:
branches:
- main

pull_request:
branches:
- main

workflow_dispatch:

jobs:
initialize_worker:
runs-on: ubuntu-latest
outputs:
id: ${{ steps.extract_id.outputs.runpod_job_id }}

steps:
- name: Deploy Worker
id: deploy
uses: fjogeleit/http-request-action@v1
with:
url: "https://api.runpod.ai/v2/${{ secrets.RUNPOD_ENDPOINT }}/run"
method: "POST"
customHeaders: '{"Content-Type": "application/json"}'
bearerToken: ${{ secrets.RUNPOD_API_KEY }}
data: '{"input":{"github_pat": "${{ secrets.GH_PAT }}", "github_org":"${{ secrets.GH_ORG }}"}}'

- name: Extract Job ID
id: extract_id
run: |
ID=$(echo '${{ steps.deploy.outputs.response }}' | jq -r '.id')
echo "::set-output name=runpod_job_id::$ID"
run_tests:
needs: initialize_worker
runs-on: runpod

steps:
- uses: actions/checkout@v3

- name: Set up environment
run: |
rm -f /etc/apt/sources.list.d/*.list
apt-get update -y
apt-get upgrade -y
apt-get install --yes --no-install-recommends sudo ca-certificates git wget curl bash libgl1 libx11-6 software-properties-common ffmpeg build-essential -y
apt-get autoremove -y
apt-get clean -y
rm -rf /var/lib/apt/lists/*
- name: Set up Python 3.10 & install dependencies
uses: actions/setup-python@v4
with:
python-version: "3.10.12"

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r builder/requirements.txt
- name: Fetch and run models
run: |
python builder/fetch_models.py
- name: Execute Tests
run: |
python src/rp_handler.py --test_input='{"input": {"audio": "https://github.com/runpod-workers/sample-inputs/raw/main/audio/gettysburg.wav"}}'
terminate_worker:
if: ${{ always() && !success() }}
needs: initialize_worker
runs-on: ubuntu-latest

steps:
- name: Shutdown Worker
uses: fjogeleit/http-request-action@v1
with:
url: "https://api.runpod.ai/v2/${{ secrets.RUNPOD_ENDPOINT }}/cancel/${{ needs.initialize_worker.outputs.id }}"
method: "POST"
customHeaders: '{"Content-Type": "application/json"}'
bearerToken: ${{ secrets.RUNPOD_API_KEY }}
6 changes: 3 additions & 3 deletions builder/fetch_models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from concurrent.futures import ThreadPoolExecutor
import whisperx
from faster_whisper import WhisperModel

model_names = ["tiny"] # "base", "small", "medium", "large-v1", "large-v2", "large-v3"
model_names = ["tiny", "large-v2"] # ["tiny", "base", "small", "medium", "large-v1", "large-v2", "large-v3"]


def load_model(selected_model):
Expand All @@ -11,7 +11,7 @@ def load_model(selected_model):
for _attempt in range(5):
while True:
try:
loaded_model = whisperx.load_model(
loaded_model = WhisperModel(
selected_model, device="cpu", compute_type="int8")
except (AttributeError, OSError):
continue
Expand Down
11 changes: 8 additions & 3 deletions builder/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
runpod==1.6.2
torch==2.0.0
torchaudio==2.0.1 --index-url https://download.pytorch.org/whl/cu118
faster-whisper==3.1.1
torch>=2
torchaudio>=2
faster-whisper==1.0.0
transformers
pandas
setuptools>=65
nltk
whisperx
12 changes: 10 additions & 2 deletions src/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Predictor:
"""

models: Dict[str, FasterWhisperPipeline] = {}
model_dir: str = "/tmp"

@property
def device(self):
Expand All @@ -40,7 +41,14 @@ def load_model(self, model_name) -> Tuple[str, FasterWhisperPipeline]:
loaded_model = load_model(
model_name,
device=self.device,
compute_type=self.compute_type)
compute_type=self.compute_type,
download_root=self.model_dir,
asr_options = {
"max_new_tokens": None,
"clip_timestamps": None,
"hallucination_silence_threshold": None,
}
)

return model_name, loaded_model

Expand All @@ -49,7 +57,7 @@ def setup(self):
Load the model into memory to make running multiple predictions efficient
"""

model_names = ["tiny", "base", "small", "medium", "large-v1", "large-v2", "large-v3"]
model_names = ["tiny", "large-v2"] # ["tiny", "base", "small", "medium", "large-v1", "large-v2", "large-v3"]
with ThreadPoolExecutor() as executor:
for model_name, model in executor.map(self.load_model, model_names):
if model_name is not None:
Expand Down

0 comments on commit c3ac01a

Please sign in to comment.