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
33 changes: 32 additions & 1 deletion .github/workflows/linux_job_v3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,40 @@ jobs:
# mount; the sync step below pushes it back to S3. Otherwise leave the mount.
- name: Resolve HF cache mode
shell: bash
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
EVENT_HAS_LABEL: ${{ contains(github.event.pull_request.labels.*.name, 'ci-refresh-hf-cache') }}
run: |
set -euo pipefail
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'ci-refresh-hf-cache') }}" == "true" ]]; then

# Reads a GitHub REST path, authenticated if the token can, otherwise
# anonymously. Never fails the step: no answer means no refresh.
gh_get() {
curl -fsSL -H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GH_TOKEN}" "https://api.github.com/$1" 2>/dev/null \
|| curl -fsSL -H "Accept: application/vnd.github+json" \
"https://api.github.com/$1" 2>/dev/null \
|| true
}

REFRESH=0
if [[ "${GITHUB_EVENT_NAME}" == "schedule" || "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
# An unattended refresh, matching pytorch's _linux-test.yml. This is
# what keeps the shared cache seeded: without it the only way to add a
# model is for someone to label a pull request.
REFRESH=1
elif [[ "${EVENT_HAS_LABEL}" == "true" ]]; then
REFRESH=1
elif [[ "${GITHUB_REF_NAME:-}" =~ ^ciflow/[^/]+/([0-9]+)$ ]]; then
# A tag run carries no labels, but a ciflow tag names its pull request,
# as pytorch's filter_test_configs.py also relies on.
case "$(gh_get "repos/${REPO}/issues/${BASH_REMATCH[1]}/labels")" in
*'"ci-refresh-hf-cache"'*) REFRESH=1 ;;
esac
fi

if [[ "${REFRESH}" == "1" ]]; then
{
echo "HF_CACHE_REFRESH=1"
echo "TRANSFORMERS_OFFLINE=0"
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/test_linux_job_v3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ jobs:
script: |
set -x
echo "HF_CACHE_REFRESH=${HF_CACHE_REFRESH:-<unset>} HF_HOME=${HF_HOME:-<unset>}"
# This workflow's own trigger says which branch to expect: a dispatch run
# refreshes unconditionally, a pull request only with the label.
if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
[[ "${HF_CACHE_REFRESH:-}" == "1" ]] || { echo "workflow_dispatch must refresh"; exit 1; }
fi
if [[ "${HF_CACHE_REFRESH:-}" == "1" ]]; then
# Refresh branch: HF must be repointed at writable RUNNER_TEMP and online.
[[ "${HF_HOME}" == "${RUNNER_TEMP}/hf_cache" ]] || { echo "HF_HOME not repointed"; exit 1; }
Expand Down
Loading