hf_text-generation-inference/.github/workflows/build.yaml

182 lines
7.4 KiB
YAML
Raw Normal View History

2023-01-31 12:14:05 -07:00
name: Build and push docker image to internal registry
on:
2024-06-07 07:25:43 -06:00
workflow_call:
2024-06-07 04:03:22 -06:00
inputs:
hardware:
2024-06-07 07:49:31 -06:00
type: string
2024-06-07 04:03:22 -06:00
description: Hardware
2024-06-07 07:49:31 -06:00
# options:
# - cuda
# - rocm
# - intel
2024-06-07 04:03:22 -06:00
required: true
2023-01-31 12:14:05 -07:00
jobs:
2024-06-07 11:52:14 -06:00
build-and-push:
2024-06-07 07:36:13 -06:00
outputs:
docker_image: ${{ steps.final.outputs.docker_image }}
docker_devices: ${{ steps.final.outputs.docker_devices }}
2024-06-07 08:01:59 -06:00
runs_on: ${{ steps.final.outputs.runs_on }}
2024-06-07 14:58:28 -06:00
label: ${{ steps.final.outputs.label }}
2024-06-06 11:07:48 -06:00
concurrency:
2024-06-07 08:05:11 -06:00
group: ${{ github.workflow }}-build-and-push-image-${{ inputs.hardware }}-${{ github.head_ref || github.run_id }}
2024-06-06 11:07:48 -06:00
cancel-in-progress: true
2024-06-07 23:53:21 -06:00
# TODO see with @Glegendre to get CPU runner here instead
runs-on: [self-hosted, nvidia-gpu , multi-gpu, 4-a10, ci]
2024-06-07 04:03:22 -06:00
permissions:
contents: write
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
security-events: write
2024-06-06 11:07:48 -06:00
steps:
2024-06-06 22:38:13 -06:00
- name: Checkout repository
2024-06-07 15:22:48 -06:00
uses: actions/checkout@v4
2024-06-07 04:03:22 -06:00
- name: Initialize Docker Buildx
2024-06-07 15:22:48 -06:00
uses: docker/setup-buildx-action@v3
2024-06-06 11:07:48 -06:00
with:
2024-06-07 04:03:22 -06:00
install: true
2024-06-07 01:10:38 -06:00
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4.4.1
2024-06-07 04:03:22 -06:00
- name: Construct harware variables
2024-06-07 14:38:06 -06:00
shell: bash
2024-06-06 11:07:48 -06:00
run: |
2024-06-07 04:03:22 -06:00
case ${{ inputs.hardware }} in
cuda)
2024-06-07 12:18:57 -06:00
export dockerfile="Dockerfile"
export label_extension=""
export docker_devices=""
2024-06-07 23:40:08 -06:00
export runs_on="nvidia-gpu"
2024-06-07 04:03:22 -06:00
;;
rocm)
2024-06-07 12:18:57 -06:00
export dockerfile="Dockerfile_amd"
export label_extension="-rocm"
export docker_devices="/dev/kfd,/dev/dri"
2024-06-08 14:16:37 -06:00
# TODO Re-enable when they pass.
# export runs_on="amd-gpu-tgi"
export runs_on="ubuntu-latest"
2024-06-07 04:03:22 -06:00
;;
2024-06-07 14:45:57 -06:00
intel)
2024-06-07 12:18:57 -06:00
export dockerfile="Dockerfile_intel"
export label_extension="-intel"
export docker_devices=""
export runs_on="ubuntu-latest"
2024-06-07 04:03:22 -06:00
;;
2024-06-07 08:14:24 -06:00
esac
2024-06-07 12:18:57 -06:00
echo $dockerfile
2024-06-07 14:38:06 -06:00
echo "Dockerfile=${dockerfile}"
2024-06-07 12:18:57 -06:00
echo $label_extension
2024-06-07 14:38:06 -06:00
echo $docker_devices
echo $runs_on
2024-06-07 08:14:24 -06:00
echo "DOCKERFILE=${dockerfile}" >> $GITHUB_ENV
echo "LABEL=${label_extension}" >> $GITHUB_ENV
echo "DOCKER_DEVICES=${docker_devices}" >> $GITHUB_ENV
2024-06-07 11:58:56 -06:00
echo "RUNS_ON=${runs_on}" >> $GITHUB_ENV
2024-06-07 04:03:22 -06:00
- name: Tailscale
uses: huggingface/tailscale-action@main
with:
authkey: ${{ secrets.TAILSCALE_AUTHKEY }}
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
2024-06-07 23:40:08 -06:00
uses: docker/login-action@v3
2024-06-07 04:03:22 -06:00
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to internal Container Registry
2024-06-07 23:40:08 -06:00
uses: docker/login-action@v3
2024-06-07 04:03:22 -06:00
with:
username: ${{ secrets.TAILSCALE_DOCKER_USERNAME }}
password: ${{ secrets.TAILSCALE_DOCKER_PASSWORD }}
registry: registry.internal.huggingface.tech
- name: Login to Azure Container Registry
if: github.event_name != 'pull_request'
2024-06-07 23:40:08 -06:00
uses: docker/login-action@v3
2024-06-07 04:03:22 -06:00
with:
username: ${{ secrets.AZURE_DOCKER_USERNAME }}
password: ${{ secrets.AZURE_DOCKER_PASSWORD }}
registry: db4c2190dd824d1f950f5d1555fbadf0.azurecr.io
# If pull request
- name: Extract metadata (tags, labels) for Docker
if: ${{ github.event_name == 'pull_request' }}
id: meta-pr
2024-06-07 15:22:48 -06:00
uses: docker/metadata-action@v5
2024-06-07 04:03:22 -06:00
with:
images: |
registry.internal.huggingface.tech/api-inference/community/text-generation-inference
tags: |
type=raw,value=sha-${{ env.GITHUB_SHA_SHORT }}${{ env.LABEL }}
# If main, release or tag
- name: Extract metadata (tags, labels) for Docker
if: ${{ github.event_name != 'pull_request' }}
id: meta
uses: docker/metadata-action@v4.3.0
with:
flavor: |
latest=auto
images: |
registry.internal.huggingface.tech/api-inference/community/text-generation-inference
ghcr.io/huggingface/text-generation-inference
db4c2190dd824d1f950f5d1555fbadf0.azurecr.io/text-generation-inference
tags: |
type=semver,pattern={{version}}${{ env.LABEL }}
type=semver,pattern={{major}}.{{minor}}${{ env.LABEL }}
type=raw,value=latest${{ env.LABEL }},enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
type=raw,value=sha-${{ env.GITHUB_SHA_SHORT }}${{ env.LABEL }}
2024-06-07 23:53:21 -06:00
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v4
with:
context: .
file: ${{ env.DOCKERFILE }}
push: true
platforms: 'linux/amd64'
build-args: |
GIT_SHA=${{ env.GITHUB_SHA }}
DOCKER_LABEL=sha-${{ env.GITHUB_SHA_SHORT }}${{ env.LABEL }}
tags: ${{ steps.meta.outputs.tags || steps.meta-pr.outputs.tags }}
labels: ${{ steps.meta.outputs.labels || steps.meta-pr.outputs.labels }}
cache-from: type=registry,ref=registry.internal.huggingface.tech/api-inference/community/text-generation-inference:cache${{ env.LABEL }},mode=min
cache-to: type=registry,ref=registry.internal.huggingface.tech/api-inference/community/text-generation-inference:cache${{ env.LABEL }},mode=min
2024-06-07 04:03:22 -06:00
- name: Final
id: final
2024-06-06 11:07:48 -06:00
run: |
2024-06-07 09:12:17 -06:00
echo "docker_image=registry.internal.huggingface.tech/api-inference/community/text-generation-inference:sha-${{ env.GITHUB_SHA_SHORT}}${{ env.LABEL }}" >> "$GITHUB_OUTPUT"
2024-06-07 04:03:22 -06:00
echo "docker_devices=${{ env.DOCKER_DEVICES }}" >> "$GITHUB_OUTPUT"
2024-06-07 07:56:52 -06:00
echo "runs_on=${{ env.RUNS_ON }}" >> "$GITHUB_OUTPUT"
2024-06-08 00:58:05 -06:00
echo "label=${{ env.LABEL }}" >> "$GITHUB_OUTPUT"
2024-06-07 11:52:14 -06:00
integration_tests:
concurrency:
2024-06-07 15:00:27 -06:00
group: ${{ github.workflow }}-${{ github.job }}-${{ needs.build-and-push.outputs.label }}-${{ github.head_ref || github.run_id }}
2024-06-07 11:52:14 -06:00
cancel-in-progress: true
needs: build-and-push
2024-06-07 23:53:21 -06:00
runs-on: ["self-hosted", "${{ needs.build-and-push.outputs.runs_on }}", "multi-gpu"]
2024-06-07 23:40:08 -06:00
if: needs.build-and-push.outputs.runs_on != 'ubuntu-latest'
2024-06-07 11:52:14 -06:00
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4.4.1
- name: Set up Python
uses: actions/setup-python@v4
with:
2024-06-07 12:11:17 -06:00
python-version: "3.10"
2024-06-07 11:52:14 -06:00
- name: Install
run: |
make install-integration-tests
2024-06-08 00:46:55 -06:00
- name: Tailscale
uses: huggingface/tailscale-action@main
2024-06-08 13:55:27 -06:00
if: needs.build-and-push.outputs.runs_on != 'amd-gpu-tgi'
2024-06-08 00:46:55 -06:00
with:
authkey: ${{ secrets.TAILSCALE_AUTHKEY }}
2024-06-07 11:52:14 -06:00
- name: Run tests
run: |
export DOCKER_VOLUME=/mnt/cache
export DOCKER_IMAGE=${{ needs.build-and-push.outputs.docker_image }}
export DOCKER_DEVICES=${{ needs.build-and-push.outputs.docker_devices }}
export HUGGING_FACE_HUB_TOKEN=${{ secrets.HUGGING_FACE_HUB_TOKEN }}
2024-06-08 00:41:40 -06:00
echo $DOCKER_IMAGE
2024-06-07 11:52:14 -06:00
pytest -s -vv integration-tests