This repository has been archived by the owner on Dec 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
156 lines (156 loc) · 6.57 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
name: CI
on:
push: {branches: [main], tags: ['v**']}
pull_request_target: {paths: ['*-*/**']}
schedule: [{cron: '0 11 * * 6'}] # M H d m w (Sat 11:00)
jobs:
setup:
environment: ${{ github.event_name == 'pull_request_target' && ! contains('OWNER,MEMBER,COLLABORATOR', github.event.pull_request.author_association) && 'external' || 'internal' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
ref: ${{ github.event.pull_request.head.sha || github.ref }}
- id: list
name: List modified models
run: |
if test "${{ github.event_name }}" = schedule; then
echo "debug: collecting all models"
MODELS=$(ls -d *-* | sort | jq -Rsc 'split("\n")[:-1]')
else
if [[ "${{ github.event_name }}" == pull_request* ]]; then
git fetch origin --depth=2 "${{ github.base_ref }}"
BASE=FETCH_HEAD
else
BASE=HEAD~1
fi
echo "debug: base: $BASE"
git diff --stat $BASE
echo "debug: collecting changed models"
MODELS=$(
for model in $(ls -d *-*); do
git diff --quiet $BASE -- $model || echo $model
done | sort | jq -Rsc 'split("\n")[:-1]'
)
fi
echo "modified=$MODELS" >> $GITHUB_OUTPUT
echo "debug: collecting binary builds"
echo "modified_aarch64_macos=$(
for model in $(echo "$MODELS" | jq -r .[]); do
test -f $model/build-aarch64-apple-darwin.sh && echo $model || :
done | sort | jq -Rsc 'split("\n")[:-1]'
)" >> $GITHUB_OUTPUT
- name: Launch self-hosted runners
if: steps.list.outputs.modified != '[]'
run: |
curl -sSL -X POST -H "X-Api-Key: $API_KEY" https://api.paperspace.io/machines/$MACHINE/start
while test $(curl -fsSL -X GET -H "X-Api-Key: $API_KEY" https://api.paperspace.io/machines/getMachinePublic?machineId=$MACHINE | jq -r .state) != ready; do
sleep 5
done
IP=$(curl -fsSL -X GET -H "X-Api-Key: $API_KEY" https://api.paperspace.io/machines/getMachinePublic?machineId=$MACHINE | jq -r .publicIpAddress)
echo "$SSH_KEY" > key; chmod 600 key
ssh -o "StrictHostKeyChecking no" -i key paperspace@$IP 'touch "gha-run-${{ github.run_id }}.lock"'
env:
SSH_KEY: ${{ secrets.PAPERSPACE_SSH_KEY }}
API_KEY: ${{ secrets.PAPERSPACE_API_KEY }}
MACHINE: ${{ secrets.PAPERSPACE_MACHINE }}
outputs:
models: ${{ steps.list.outputs.modified }}
models_macos-latest-xlarge: ${{ steps.list.outputs.modified_aarch64_macos }}
docker-build-test-push:
concurrency: # terminate on new commits to PRs
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}-${{ matrix.model }}
cancel-in-progress: true
needs: setup
runs-on: [self-hosted, gpu]
strategy:
fail-fast: false
matrix:
model: ${{ fromJson(needs.setup.outputs.models) }}
# if nothing to do, skip without failing
if: needs.setup.outputs.models != '[]'
env:
VERSION: '1.0.0'
DOCKER_BUILDKIT: 1
DOCKER_CLI_EXPERIMENTAL: enabled
COMPOSE_DOCKER_CLI_BUILD: 1
permissions:
packages: write
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha || github.ref }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- run: ./build.sh ${{ github.event_name == 'push' && '--push' || '--load' }}
working-directory: ${{ matrix.model }}
env:
# can't load cross-CPU-platform
BUILDX_PLATFORM: ${{ github.event_name == 'push' && 'linux/arm64,linux/amd64' || 'linux/amd64' }}
# can't test cross-CPU-platform
TESTS_SKIP_CPU: ${{ github.event_name == 'push' && '1' || '' }}
# avoid OoM errors (TODO: remove when using larger GPU)
TESTS_SKIP_GPU: ${{ contains(fromJSON('["a2t-whisper","cht-dolly-v2","cht-gorilla","cht-llama-v2","cht-mpt","cht-xgen","dfs-dalle","dfs-diffusers"]'), matrix.model) && '1' || '' }}
macos-aarch64-build-release:
concurrency: # terminate on new commits to PRs
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}-${{ matrix.model }}-bin
cancel-in-progress: true
needs: setup
runs-on: macos-latest-xlarge
strategy:
fail-fast: false
matrix:
model: ${{ fromJson(needs.setup.outputs.models_macos-latest-xlarge) }}
# if nothing to do, skip without failing
if: needs.setup.outputs.models_macos-latest-xlarge != '[]'
permissions:
contents: write
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha || github.ref }}
- uses: actions/setup-python@v4
with: {python-version: 3.11}
- id: dist
name: build
run: |
pip install virtualenv
./build-aarch64-apple-darwin.sh $(python -c 'import sys; print(".".join(map(str,sys.version_info[:2])))')
working-directory: ${{ matrix.model }}
- uses: actions/upload-artifact@v3
with: {path: dist/*}
- if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
name: Update release assets
run: |
tag="${GITHUB_REF#refs/tags/}"
gh release upload --clobber "${tag%%.*}" dist/*
env:
GH_TOKEN: ${{ github.token }}
pass: # convenient single job to apply branch protection to
needs: [docker-build-test-push, macos-aarch64-build-release]
runs-on: ubuntu-latest
steps:
- run: echo success
teardown:
environment: ${{ github.event_name == 'pull_request_target' && ! contains('OWNER,MEMBER,COLLABORATOR', github.event.pull_request.author_association) && 'external' || 'internal' }}
needs: docker-build-test-push
if: always()
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Stop self-hosted runners
run: |
IP=$(curl -fsSL -X GET -H "X-Api-Key: $API_KEY" https://api.paperspace.io/machines/getMachinePublic?machineId=$MACHINE | jq -r .publicIpAddress)
echo "$SSH_KEY" > key; chmod 600 key
ssh -o "StrictHostKeyChecking no" -i key paperspace@$IP \
'rm -f "gha-run-${{ github.run_id }}.lock"; sleep 10; ls gha-run-*.lock' || \
curl -sSL -X POST -H "X-Api-Key: $API_KEY" https://api.paperspace.io/machines/$MACHINE/stop
env:
SSH_KEY: ${{ secrets.PAPERSPACE_SSH_KEY }}
API_KEY: ${{ secrets.PAPERSPACE_API_KEY }}
MACHINE: ${{ secrets.PAPERSPACE_MACHINE }}