Skip to content

Commit 0646517

Browse files
author
Guang Yang
committed
Update CI for HF Optimum models
1 parent adde519 commit 0646517

File tree

1 file changed

+67
-10
lines changed

1 file changed

+67
-10
lines changed

.github/workflows/trunk.yml

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -555,11 +555,11 @@ jobs:
555555
strategy:
556556
matrix:
557557
hf_model_id: [
558-
google/gemma-2-2b,
559-
Qwen/Qwen2.5-0.5B,
558+
google/gemma-3-1b-it,
559+
Qwen/Qwen3-0.6B,
560560
HuggingFaceTB/SmolLM2-135M,
561561
meta-llama/Llama-3.2-1B,
562-
allenai/OLMo-1B-hf
562+
allenai/OLMo-1B-hf,
563563
]
564564
fail-fast: false
565565
with:
@@ -575,38 +575,95 @@ jobs:
575575
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
576576
conda activate "${CONDA_ENV}"
577577
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool cmake
578+
# Build executor_runner with ETdump enabled
579+
PYTHON_EXECUTABLE=python cmake -DPYTHON_EXECUTABLE=python \
580+
-DCMAKE_INSTALL_PREFIX=cmake-out \
581+
-DEXECUTORCH_ENABLE_LOGGING=1 \
582+
-DCMAKE_BUILD_TYPE=Release \
583+
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
584+
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
585+
-DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
586+
-DEXECUTORCH_BUILD_XNNPACK=ON \
587+
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
588+
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
589+
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
590+
-DEXECUTORCH_BUILD_DEVTOOLS=ON \
591+
-DEXECUTORCH_ENABLE_EVENT_TRACER=ON \
592+
-Bcmake-out .
593+
cmake --build cmake-out -j16 --target install --config Release
578594
echo "::endgroup::"
579595
580596
echo "::group::Set up Hugging Face"
581597
pip install -U "huggingface_hub[cli]"
582598
huggingface-cli login --token $SECRET_EXECUTORCH_HF_TOKEN
583599
git clone https://github.com/huggingface/optimum-executorch
584-
cd optimum-executorch
600+
pushd optimum-executorch
585601
# There is no release yet, for CI stability, always test from the same commit on main
586-
git checkout 577a2b19670e4c643a5c6ecb09bf47b9a699e7c6
602+
git checkout da80c9e35b3db5c7eea8731b7d660482fb4870a8
587603
pip install .[tests]
604+
popd
605+
606+
if [ "${{ matrix.hf_model_id }}" == "google/gemma-3-1b-it" ]; then
607+
# Fixes for gemma-3 is not available in the released version
608+
git clone https://github.com/huggingface/transformers.git
609+
pushd transformers
610+
git checkout a57274466f7f72efaa2662d1738cdaf28ae8071f
611+
pip install -e .
612+
popd
613+
fi
588614
pip list
589615
echo "::endgroup::"
590616
591-
echo "::group::Export and Run ${{ matrix.hf_model_id }}"
617+
echo "::group::Export to ExecuTorch"
592618
# Pass matrix variable as environment variable
593619
export MODEL_ID="${{ matrix.hf_model_id }}"
620+
export OUTPUT_DIR="$(pwd)/${MODEL_ID}_custom_sdpa_8da4w"
621+
pushd optimum-executorch
622+
623+
optimum-cli export executorch \
624+
--model ${MODEL_ID} \
625+
--task text-generation \
626+
--recipe xnnpack \
627+
--use_custom_sdpa \
628+
--output_dir ${OUTPUT_DIR} \
629+
--qlinear
630+
631+
ls -FlAGhp ${OUTPUT_DIR}
632+
popd
633+
echo "::endgroup::"
634+
635+
echo "::group::Inference using python API"
636+
pushd optimum-executorch
594637
python -c "
595638
import os
596639
from optimum.executorch import ExecuTorchModelForCausalLM
597640
from transformers import AutoTokenizer
598641
599642
model_id = os.getenv('MODEL_ID')
600-
print(f'Loading model: {model_id}')
601-
model = ExecuTorchModelForCausalLM.from_pretrained(model_id, recipe='xnnpack')
602-
tokenizer = AutoTokenizer.from_pretrained(model_id)
643+
pte_dir = os.getenv('OUTPUT_DIR')
644+
print(f'Loading model {model_id} from {pte_dir}.')
645+
model = ExecuTorchModelForCausalLM.from_pretrained(pte_dir)
603646
generated_text = model.text_generation(
604-
tokenizer=tokenizer,
647+
tokenizer=AutoTokenizer.from_pretrained(model_id),
605648
prompt='Simply put, the theory of relativity states that',
606649
max_seq_len=64
607650
)
608651
print(generated_text)
609652
"
653+
popd
654+
echo "::endgroup::"
655+
656+
echo "::group::Inference using executor_runner with ETDump"
657+
./cmake-out/executor_runner \
658+
--model_path ${OUTPUT_DIR}/model.pte \
659+
--etdump_path ${OUTPUT_DIR}/etdump.etdp
660+
661+
export TSV_PATH=artifacts-to-be-uploaded/${MODEL_ID}_op_prof.tsv
662+
mkdir -p $(dirname "$TSV_PATH")
663+
python3 -m devtools.inspector.inspector_cli \
664+
--etdump_path ${OUTPUT_DIR}/etdump.etdp \
665+
--tsv_path ${TSV_PATH}
666+
610667
echo "::endgroup::"
611668
612669

0 commit comments

Comments
 (0)