Skip to content

Commit ab8d34f

Browse files
Guang YangGithub Executorch
authored andcommitted
Add compatible HuggingFace models to benchmark workflow
1 parent 66dcd40 commit ab8d34f

File tree

3 files changed

+112
-3
lines changed

3 files changed

+112
-3
lines changed

.ci/scripts/download_hf_hub.sh

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/bin/bash
2+
3+
# Function to download files from the Hugging Face Hub
4+
# Arguments:
5+
# 1. model_id: The Hugging Face repository ID (e.g., "organization/model_name")
6+
# 2. subdir: The optional subdirectory in the repo to look for files (pass "" if not used)
7+
# 3. file_names: An array of filenames to be downloaded
8+
# Returns:
9+
# The directory containing the downloaded files
10+
function download_hf_files() {
11+
local model_id="$1"
12+
local subdir="$2"
13+
local -n file_names=$3 # Pass the array by name
14+
15+
local download_dir
16+
17+
# Use the first file to determine the download directory
18+
download_dir=$(python3 -c "
19+
from huggingface_hub import hf_hub_download
20+
# Download the first file and get its directory
21+
path = hf_hub_download(
22+
repo_id='${model_id}',
23+
filename='${subdir:+${subdir}/}${file_names[0]}'
24+
)
25+
import os
26+
print(os.path.dirname(path))")
27+
28+
if [ $? -ne 0 ]; then
29+
echo "Error: Failed to determine download directory from ${file_names[0]}" >&2
30+
return 1
31+
fi
32+
33+
# Download remaining files into the same directory
34+
for file_name in "${file_names[@]:1}"; do
35+
python3 -c "
36+
from huggingface_hub import hf_hub_download
37+
# Download the file
38+
hf_hub_download(
39+
repo_id='${model_id}',
40+
filename='${subdir:+${subdir}/}${file_name}'
41+
)"
42+
43+
if [ $? -ne 0 ]; then
44+
echo "Error: Failed to download ${file_name} from ${model_id}" >&2
45+
return 1
46+
fi
47+
done
48+
49+
# Return the directory containing the downloaded files
50+
echo "$download_dir"
51+
}
52+
53+
# Check if script is called directly
54+
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
55+
# Parse arguments from CLI
56+
while [[ $# -gt 0 ]]; do
57+
case $1 in
58+
--model_id)
59+
MODEL_ID="$2"
60+
shift 2
61+
;;
62+
--subdir)
63+
SUBDIR="$2"
64+
shift 2
65+
;;
66+
--files)
67+
shift
68+
FILES_TO_DOWNLOAD=()
69+
while [[ $# -gt 0 && $1 != --* ]]; do
70+
FILES_TO_DOWNLOAD+=("$1")
71+
shift
72+
done
73+
;;
74+
*)
75+
echo "Unknown option: $1" >&2
76+
exit 1
77+
;;
78+
esac
79+
done
80+
81+
# Validate required arguments
82+
if [ -z "$MODEL_ID" ] || [ -z "$FILES_TO_DOWNLOAD" ]; then
83+
echo "Usage: $0 --model_id <model_id> --subdir <subdir> --files <file1> [<file2> ...]" >&2
84+
exit 1
85+
fi
86+
87+
# Call the function
88+
DOWNLOAD_DIR=$(download_hf_files "$MODEL_ID" "$SUBDIR" FILES_TO_DOWNLOAD)
89+
if [ $? -eq 0 ]; then
90+
echo "$DOWNLOAD_DIR"
91+
else
92+
exit 1
93+
fi
94+
fi

.github/workflows/android-perf.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ jobs:
108108
declare -A DEVICE_POOL_ARNS
109109
DEVICE_POOL_ARNS[samsung_galaxy_s22]="arn:aws:devicefarm:us-west-2:308535385114:devicepool:02a2cf0f-6d9b-45ee-ba1a-a086587469e6/e59f866a-30aa-4aa1-87b7-4510e5820dfa"
110110
DEVICE_POOL_ARNS[samsung_galaxy_s24]="arn:aws:devicefarm:us-west-2:308535385114:devicepool:02a2cf0f-6d9b-45ee-ba1a-a086587469e6/98f8788c-2e25-4a3c-8bb2-0d1e8897c0db"
111+
DEVICE_POOL_ARNS[google_pixel_8_pro]="arn:aws:devicefarm:us-west-2:308535385114:devicepool:02a2cf0f-6d9b-45ee-ba1a-a086587469e6/d65096ab-900b-4521-be8b-a3619b69236a"
111112
112113
# Resolve device names with their corresponding ARNs
113114
if [[ ! $(echo "$DEVICES" | jq empty 2>/dev/null) ]]; then
@@ -168,18 +169,20 @@ jobs:
168169
name: export-models
169170
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
170171
needs: set-parameters
172+
secrets: inherit
171173
strategy:
172174
matrix:
173175
model: ${{ fromJson(needs.set-parameters.outputs.models) }}
174176
delegate: ${{ fromJson(needs.set-parameters.outputs.delegates) }}
175177
fail-fast: false
176178
with:
177-
runner: linux.4xlarge
179+
runner: linux.4xlarge.memory
178180
docker-image: executorch-ubuntu-22.04-qnn-sdk
179181
submodules: 'true'
180182
timeout: 60
181183
upload-artifact: android-models
182184
upload-artifact-to-s3: true
185+
secrets-env: EXECUTORCH_HF_TOKEN
183186
script: |
184187
# The generic Linux job chooses to use base env, not the one setup by the image
185188
echo "::group::Setting up dev environment"
@@ -197,7 +200,19 @@ jobs:
197200
BUILD_MODE="cmake"
198201
DTYPE="fp32"
199202
200-
if [[ ${{ matrix.model }} =~ ^stories* ]]; then
203+
if [[ ${{ matrix.model }} =~ ^[^/]+/[^/]+$ ]] && [[ ${{ matrix.delegate }} == "xnnpack" ]]; then
204+
pip install -U "huggingface_hub[cli]"
205+
huggingface-cli login --token $SECRET_EXECUTORCH_HF_TOKEN
206+
pip install accelerate sentencepiece
207+
# HuggingFace model. Assume the pattern is always like "<org>/<repo>"
208+
HF_MODEL_REPO=${{ matrix.model }}
209+
DOWNLOADED_PATH=$(bash .ci/scripts/download_hf_hub.sh --model_id "${HF_MODEL_REPO}" --subdir "original" --files "tokenizer.model")
210+
OUT_ET_MODEL_NAME="$(echo "$HF_MODEL_REPO" | awk -F'/' '{print $2}' | sed 's/_/-/g')_xnnpack"
211+
python -m extension.export_util.export_hf_model -hfm="$HF_MODEL_REPO" -o "$OUT_ET_MODEL_NAME" -d "float32"
212+
zip -j model.zip "${OUT_ET_MODEL_NAME}.pte" "${DOWNLOADED_PATH}/tokenizer.model"
213+
mkdir -p "${ARTIFACTS_DIR_NAME}"
214+
mv model.zip "${ARTIFACTS_DIR_NAME}"
215+
elif [[ ${{ matrix.model }} =~ ^stories* ]]; then
201216
# Install requirements for export_llama
202217
PYTHON_EXECUTABLE=python bash examples/models/llama/install_requirements.sh
203218
# Test llama2

.github/workflows/trunk.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ jobs:
362362
fail-fast: false
363363
with:
364364
secrets-env: EXECUTORCH_HF_TOKEN
365-
runner: linux.12xlarge
365+
runner: linux.4xlarge.memory
366366
docker-image: executorch-ubuntu-22.04-clang12
367367
submodules: 'true'
368368
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}

0 commit comments

Comments
 (0)