From 9f49f540b6ec3416fedf011c4be4d2a24598a0f8 Mon Sep 17 00:00:00 2001 From: Kevin Turner <83819+keturn@users.noreply.github.com> Date: Thu, 24 Nov 2022 18:38:08 -0800 Subject: [PATCH] CI: use huggingface cache for test-invoke-pip --- .github/workflows/test-invoke-conda.yml | 5 +- .github/workflows/test-invoke-pip.yml | 61 +++++++++++++------------ 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/.github/workflows/test-invoke-conda.yml b/.github/workflows/test-invoke-conda.yml index a61e648a36f..fb625759fc6 100644 --- a/.github/workflows/test-invoke-conda.yml +++ b/.github/workflows/test-invoke-conda.yml @@ -61,7 +61,7 @@ jobs: id: cache-sd-model uses: actions/cache@v3 env: - cache-name: huggingface-${{ matrix.stable-diffusion-model-switch }} + cache-name: huggingface-${{ matrix.stable-diffusion-model }} with: path: ~/.cache/huggingface key: ${{ env.cache-name }} @@ -105,12 +105,13 @@ jobs: echo -n '${{ secrets.HUGGINGFACE_TOKEN }}' > ~/.huggingface/token fi python scripts/configure_invokeai.py \ - --no-interactive \ + --no-interactive --yes \ --full-precision # can't use fp16 weights without a GPU - name: Run the tests id: run-tests env: + # Set offline mode to make sure configure preloaded successfully. HF_HUB_OFFLINE: 1 HF_DATASETS_OFFLINE: 1 TRANSFORMERS_OFFLINE: 1 diff --git a/.github/workflows/test-invoke-pip.yml b/.github/workflows/test-invoke-pip.yml index 69fc7c9ce97..a101e7d99cb 100644 --- a/.github/workflows/test-invoke-pip.yml +++ b/.github/workflows/test-invoke-pip.yml @@ -1,16 +1,16 @@ name: Test invoke.py pip -on: - push: - branches: - - 'main' - - 'development' - pull_request: - branches: - - 'main' - - 'development' +on: [push, pull_request] jobs: matrix: + # Run on: + # - pull requests + # - pushes to forks (will run in the forked project with that fork's secrets) + # - pushes to branches that are *not* pull requests + if: | + github.event_name == 'pull_request' + || github.repository != 'invoke-ai/InvokeAI' + || github.ref_protected strategy: fail-fast: false matrix: @@ -44,6 +44,8 @@ jobs: shell: ${{ matrix.default-shell }} env: INVOKEAI_ROOT: '${{ github.workspace }}/invokeai' + PYTHONUNBUFFERED: 1 + HAVE_SECRETS: ${{ secrets.HUGGINGFACE_TOKEN != '' }} steps: - name: Checkout sources id: checkout-sources @@ -54,6 +56,19 @@ jobs: mkdir -p ${{ env.INVOKEAI_ROOT }}/configs cp configs/models.yaml.example ${{ env.INVOKEAI_ROOT }}/configs/models.yaml + - name: Use Cached Stable Diffusion Model + id: cache-sd-model + uses: actions/cache@v3 + env: + cache-name: cache-${{ matrix.stable-diffusion-model }} + with: + path: ${{ matrix.stable-diffusion-model-dl-path }} + key: ${{ env.cache-name }} + + - name: Check model availability + if: steps.cache-sd-model.outputs.cache-hit != true && env.HAVE_SECRETS != 'true' + run: echo -e '\a ⛔ GitHub model cache not found, and no HUGGINGFACE_TOKEN is available. Will not be able to load Stable Diffusion.' ; exit 1 + - name: set test prompt to main branch validation if: ${{ github.ref == 'refs/heads/main' }} run: echo "TEST_PROMPTS=tests/preflight_prompts.txt" >> $GITHUB_ENV @@ -84,32 +99,20 @@ jobs: ${{ env.pythonLocation }}/bin/pip install --upgrade -r '${{ matrix.requirements-file }}' ${{ env.pythonLocation }}/bin/pip install -e . - - name: Use Cached Stable Diffusion Model - id: cache-sd-model - uses: actions/cache@v3 - env: - cache-name: cache-${{ matrix.stable-diffusion-model }} - with: - path: ${{ matrix.stable-diffusion-model-dl-path }} - key: ${{ env.cache-name }} - - - name: Download ${{ matrix.stable-diffusion-model }} - id: download-stable-diffusion-model - if: ${{ steps.cache-sd-model.outputs.cache-hit != 'true' }} - run: | - mkdir -p "${{ env.INVOKEAI_ROOT }}/${{ matrix.stable-diffusion-model-dl-path }}" - curl \ - -H "Authorization: Bearer ${{ secrets.HUGGINGFACE_TOKEN }}" \ - -o "${{ env.INVOKEAI_ROOT }}/${{ matrix.stable-diffusion-model-dl-path }}/${{ matrix.stable-diffusion-model-dl-name }}" \ - -L ${{ matrix.stable-diffusion-model-url }} - - name: run configure_invokeai.py id: run-preload-models run: | - ${{ env.pythonLocation }}/bin/python scripts/configure_invokeai.py --no-interactive --yes + ${{ env.pythonLocation }}/bin/python scripts/configure_invokeai.py \ + --no-interactive --yes \ + --full-precision # can't use fp16 weights without a GPU - name: Run the tests id: run-tests + env: + # Set offline mode to make sure configure preloaded successfully. + HF_HUB_OFFLINE: 1 + HF_DATASETS_OFFLINE: 1 + TRANSFORMERS_OFFLINE: 1 run: | time ${{ env.pythonLocation }}/bin/python scripts/invoke.py \ --model ${{ matrix.stable-diffusion-model }} \