Skip to content
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
42 changes: 42 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# The .dockerignore file excludes files from the container build process.
#
# https://docs.docker.com/engine/reference/builder/#dockerignore-file

# Replicate
/checkpoints/
/models/
/safety-cache/
/gradio_cached_examples/
*.mp4
*.pth
*.pt
*.bin
*.ckpt
*.onnx
*.tar
*.tar.gz
*.h5
*.pb
*.caffemodel
*.weights
*.tar
*.jpg
*.jpeg
*.png
*.webp
.vscode

# Exclude Git files
.git
.github
.gitignore

# Exclude Python cache files
__pycache__
.pytest_cache/
.mypy_cache
.pytest_cache
.ruff_cache

# Exclude Python virtual environment
/venv
100 changes: 100 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: replicate-cd

on:
push:
branches:
- main

jobs:
push:
runs-on: ubuntu-latest
env:
BASE_MODEL: 'zsxkib/instant-id-fake-prod-model'
PROD_MODEL: 'zsxkib/instant-id-prod-official'
PROD_DEPLOYMENT: 'zsxkib/instant-id-prod-official'

steps:
- name: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: what changed
id: what-changed
run: |
FILES_CHANGED=$(git diff --name-only --diff-filter=AMR ${{ github.event.before }} ${{ github.event.after }} | xargs)
echo "FILES_CHANGED=$FILES_CHANGED" >> $GITHUB_ENV
if echo "$FILES_CHANGED" | grep -q 'cog.yaml'; then
echo "cog-push=true" >> $GITHUB_OUTPUT
else
echo "cog-push=false" >> $GITHUB_OUTPUT
fi
if ${{ contains(github.event.head_commit.message, '[cog build]') }}; then
echo "cog-push=true" >> $GITHUB_OUTPUT
fi

# if cog.yaml changes - cog build and push. else - yolo build and push!
- name: did-it-tho
env:
COG_PUSH: ${{ steps.what-changed.outputs.cog-push }}
run: |
echo "cog push?: $COG_PUSH"
echo "changed files: $FILES_CHANGED"

- name: setup-cog
if: steps.what-changed.outputs.cog-push == 'true'
uses: replicate/setup-cog@v1.0.3
with:
token: ${{ secrets.REPLICATE_API_TOKEN }}
install-cuda: false

- name: cog-build
if: steps.what-changed.outputs.cog-push == 'true'
run: |
cog build

- name: cog-push
if: steps.what-changed.outputs.cog-push == 'true'
run: |
cog push r8.im/"$PROD_MODEL"

- name: install-yolo
run: |
sudo curl -o /usr/local/bin/yolo -L "https://github.com/replicate/yolo/releases/latest/download/yolo_$(uname -s)_$(uname -m)"
sudo chmod +x /usr/local/bin/yolo

# yolo as hack for pushing environment variables
- name: yolo-push-env
if: steps.what-changed.outputs.cog-push == 'true'
env:
REPLICATE_API_TOKEN: ${{secrets.REPLICATE_API_TOKEN}}
SENTRY_DSN: ${{secrets.SENTRY_DSN}}
run: |
touch meaningless_file.txt
echo "adding environment variables to $PROD_MODEL"
yolo push -e SENTRY_DSN="$SENTRY_DSN" --base $PROD_MODEL --dest $PROD_MODEL meaningless_file.txt

- name: yolo-push
if: steps.what-changed.outputs.cog-push == 'false'
env:
REPLICATE_API_TOKEN: ${{secrets.REPLICATE_API_TOKEN}}
SENTRY_DSN: ${{secrets.SENTRY_DSN}}
run: |
echo "pushing changes from $BASE_MODEL to $PROD_MODEL"
echo "changed files: $FILES_CHANGED"
yolo push -e SENTRY_DSN="$SENTRY_DSN" --base $BASE_MODEL --dest $PROD_MODEL $FILES_CHANGED

- name: update deployment
env:
REPLICATE_API_TOKEN: ${{secrets.REPLICATE_API_TOKEN}}

run: |
sudo apt-get install jq
export LATEST_VERSION=$(curl -s -H "Authorization: Token $REPLICATE_API_TOKEN" \
https://api.replicate.com/v1/models/$PROD_MODEL/versions | jq -r '.results[0].id')
curl -s \
-X PATCH \
-H "Authorization: Token $REPLICATE_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{"version": "'$LATEST_VERSION'" }' \
https://api.replicate.com/v1/deployments/$PROD_DEPLOYMENT
117 changes: 117 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: replicate-ci

on:
pull_request:
branches:
- main

jobs:
push:
runs-on: ubuntu-latest
env:
BASE_MODEL: 'zsxkib/instant-id-fake-prod-model'
STAGING_MODEL: 'zsxkib/instant-id-staging'
STAGING_DEPLOYMENT: 'zsxkib/instant-id-staging'

steps:
- name: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: what changed
id: what-changed
run: |
FILES_CHANGED=$(git diff --name-only --diff-filter=AMR ${{ github.event.before }} ${{ github.event.after }} | xargs)
echo "FILES_CHANGED=$FILES_CHANGED" >> $GITHUB_ENV
if echo "$FILES_CHANGED" | grep -q 'cog.yaml'; then
echo "cog-push=true" >> $GITHUB_OUTPUT
else
echo "cog-push=false" >> $GITHUB_OUTPUT
fi
if ${{ contains(github.event.head_commit.message, '[cog build]') }}; then
echo "cog-push=true" >> $GITHUB_OUTPUT
fi

# if cog.yaml changes - cog build and push. else - yolo build and push!
- name: did-it-tho
env:
COG_PUSH: ${{ steps.what-changed.outputs.cog-push }}
run: |
echo "cog push?: $COG_PUSH"
echo "changed files: $FILES_CHANGED"

- name: setup-cog
if: steps.what-changed.outputs.cog-push == 'true'
uses: replicate/setup-cog@v1.0.3
with:
token: ${{ secrets.REPLICATE_API_TOKEN }}
install-cuda: false

- name: cog-build
if: steps.what-changed.outputs.cog-push == 'true'
run: |
cog build

- name: cog-push
if: steps.what-changed.outputs.cog-push == 'true'
run: |
cog push r8.im/"$STAGING_MODEL"

- name: install-yolo
run: |
sudo curl -o /usr/local/bin/yolo -L "https://github.com/replicate/yolo/releases/latest/download/yolo_$(uname -s)_$(uname -m)"
sudo chmod +x /usr/local/bin/yolo

# TODO: once you confirm sentry works, remove from staging.
# yolo as hack for pushing environment variables
- name: yolo-push-env
if: steps.what-changed.outputs.cog-push == 'true'
env:
REPLICATE_API_TOKEN: ${{secrets.REPLICATE_API_TOKEN}}
SENTRY_DSN: ${{secrets.SENTRY_DSN}}
run: |
touch meaningless_file.txt
echo "adding environment variables to $STAGING_MODEL"
yolo push -e SENTRY_DSN="$SENTRY_DSN" --base $STAGING_MODEL --dest $STAGING_MODEL meaningless_file.txt

- name: yolo-push
if: steps.what-changed.outputs.cog-push == 'false'
env:
REPLICATE_API_TOKEN: ${{secrets.REPLICATE_API_TOKEN}}
SENTRY_DSN: ${{secrets.SENTRY_DSN}}
run: |
echo "pushing changes from $BASE_MODEL to $STAGING_MODEL"
echo "changed files: $FILES_CHANGED"
yolo push -e SENTRY_DSN="$SENTRY_DSN" --base $BASE_MODEL --dest $STAGING_MODEL $FILES_CHANGED

- uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: install python test deps
run: |
pip install -r requirements_test.txt

- name: test model
env:
REPLICATE_API_TOKEN: ${{secrets.REPLICATE_API_TOKEN}}
TEST_ENV: 'staging'
run: |
./tests/run_tests.sh

- name: update deployment
env:
REPLICATE_API_TOKEN: ${{secrets.REPLICATE_API_TOKEN}}

run: |
sudo apt-get install jq
export LATEST_VERSION=$(curl -s -H "Authorization: Token $REPLICATE_API_TOKEN" \
https://api.replicate.com/v1/models/$STAGING_MODEL/versions | jq -r '.results[0].id')
curl -s \
-X PATCH \
-H "Authorization: Token $REPLICATE_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{"version": "'$LATEST_VERSION'" }' \
https://api.replicate.com/v1/deployments/$STAGING_DEPLOYMENT

28 changes: 25 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,28 @@ checkpoints/
models/

# Cog
.cog

gradio_cached_examples
/.cog/
/checkpoints/
/models/
/safety-cache/
*.tar
.vscode
gradio_cached_examples
cog/test_batchsize.py
input.png
output_*.png
output.*.png
output_image_*.png
output_image.*.png
output_*.webp
output.*.webp
output_image_*.webp
output_image.*.webp
output_*.jpg
output.*.jpg
output_image_*.jpg
output_image.*.jpg
output_*.jpeg
output.*.jpeg
output_image_*.jpeg
output_image.*.jpeg
11 changes: 10 additions & 1 deletion cog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
build:
# set to true if your model requires a GPU
gpu: true
# cuda: "12.1"
cuda: "12.1"

# a list of ubuntu apt packages to install
system_packages:
Expand All @@ -22,6 +22,15 @@ build:
- "insightface==0.7.3"
- "diffusers==0.25.1"
- "onnxruntime==1.16.3"
- "omegaconf==2.3.0"
- "gradio==3.50.2"
- "peft==0.8.2"
- "transformers==4.37.0"
- "controlnet-aux==0.0.7"

# fix for pydantic issues in cog
# https://github.com/replicate/cog/issues/1623
- albumentations==1.4.3

# commands run after the environment is setup
run:
Expand Down
Loading