Repository navigation
ci : store ccache on HF buckets (test with cuda-ubuntu for now) #27699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fb4aa1c
add ccache-buckets action
CISC a4a3e81
use ccache-buckets
CISC 3eb7b61
only save on master
CISC 0b656b4
install python3-venv for hip
CISC f9a9e0b
add jq and python3 for cuda
CISC b80336c
only delete caches older than 5 minutes
CISC File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| name: "ccache-buckets" | ||
| description: "Save/restore latest GitHub Actions ccache matching a key prefix to/from HF buckets" | ||
| inputs: | ||
| key: | ||
| description: "Cache key prefix to match and load" | ||
| required: true | ||
| folder: | ||
| description: "Bucket folder containing ccache files" | ||
| required: true | ||
| evict-old-files: | ||
| description: "Corresponds to the ccache --evict-older-than AGE option, where AGE is the number of seconds or days followed by the 's' or 'd' suffix respectively." | ||
| default: '' | ||
| save: | ||
| description: "Save ccache" | ||
| required: false | ||
| default: false | ||
| type: boolean | ||
| hf_bucket: | ||
| description: 'Hugging Face buckets path' | ||
| required: true | ||
|
|
||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - name: Install Hugging Face Hub CLI | ||
| shell: bash | ||
| run: | | ||
| python3 -m venv .venv-hf | ||
| .venv-hf/bin/pip install -U huggingface_hub==1.28.0 | ||
|
|
||
| - name: Restore ccache from buckets | ||
| if: ${{ inputs.save != 'true' }} | ||
| shell: bash | ||
| run: | | ||
| set +e -uo pipefail | ||
| source .venv-hf/bin/activate | ||
| CCACHE_DIR=$(ccache -k cache_dir) | ||
| if [[ -d "$CCACHE_DIR" ]]; then | ||
| CACHE_PATH=$(hf buckets list "hf://buckets/${{ inputs.hf_bucket }}/${{ inputs.folder }}" --json | jq -r '[.[] | select(.type == "file") | select(.path | startswith("${{ inputs.folder }}/${{ inputs.key }}") and endswith(".tar.gz"))] | sort_by(.path) | last | .path // ""') | ||
| if [[ -n "$CACHE_PATH" ]]; then | ||
| echo "Restoring ccache from '$CACHE_PATH'." | ||
| hf buckets cp "hf://buckets/${{ inputs.hf_bucket }}/$CACHE_PATH" ccache_bucket.tar.gz | ||
| mkdir -p ccache_bucket | ||
| if tar -xzf ccache_bucket.tar.gz -C ccache_bucket; then | ||
| rm -rf "$CCACHE_DIR" | ||
| mv ccache_bucket "$CCACHE_DIR" | ||
| ccache -z | ||
| fi | ||
| rm ccache_bucket.tar.gz | ||
| else | ||
| echo "No ccache found." | ||
| fi | ||
| else | ||
| echo "'$CCACHE_DIR' not found." | ||
| fi | ||
|
|
||
| - name: Save ccache to buckets | ||
| if: ${{ inputs.save == 'true' }} | ||
| shell: bash | ||
| run: | | ||
| set +e -uo pipefail | ||
| source .venv-hf/bin/activate | ||
| CCACHE_DIR=$(ccache -k cache_dir) | ||
| if [[ -d "$CCACHE_DIR" ]]; then | ||
| ccache -s | ||
| if [[ -n "${{ inputs.evict-old-files }}" ]]; then | ||
| ccache --evict-older-than "${{ inputs.evict-old-files }}" | ||
| fi | ||
| DATESTAMP=$(date -u +'%Y-%m-%dT%H:%M:%SZ') | ||
| CACHEFILE="${{ inputs.key }}-$DATESTAMP.tar.gz" | ||
| if tar -czf ccache_bucket.tar.gz -C "$CCACHE_DIR" .; then | ||
| hf buckets cp ccache_bucket.tar.gz "hf://buckets/${{ inputs.hf_bucket }}/${{ inputs.folder }}/$CACHEFILE" | ||
| fi | ||
| rm ccache_bucket.tar.gz | ||
| else | ||
| echo "'$CCACHE_DIR' not found." | ||
| fi | ||
|
|
||
| - name: Remove old ccache files from buckets | ||
| if: ${{ inputs.save == 'true' }} | ||
| shell: bash | ||
| run: | | ||
| set +e -uo pipefail | ||
| source .venv-hf/bin/activate | ||
| CACHE_FILES=$(hf buckets list "hf://buckets/${{ inputs.hf_bucket }}/${{ inputs.folder }}" --json | jq -r '[.[] | select(.type == "file") | select((.uploaded_at | .[:19]+"Z" | fromdateiso8601) < (now - 5 * 60)) | select(.path | startswith("${{ inputs.folder }}/${{ inputs.key }}") and endswith(".tar.gz"))] | sort_by(.path)[:-1] | .[] | [.path // ""] | @tsv') | ||
| if [[ -n "$CACHE_FILES" ]]; then | ||
| echo "Removing old ccache files..." | ||
| while IFS=$'\t' read -r CACHE_PATH; do | ||
| hf buckets rm "hf://buckets/${{ inputs.hf_bucket }}/$CACHE_PATH" -y | ||
| done <<< "$CACHE_FILES" | ||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.