From 591533dc47dab82314fdea51ac3aa08a7ab6e9e3 Mon Sep 17 00:00:00 2001 From: lucylq Date: Tue, 22 Jul 2025 12:35:50 -0700 Subject: [PATCH] CI test for lora Add CI test for LoRA: note, not program-data separated yet. Differential Revision: [D78751767](https://our.internmc.facebook.com/intern/diff/D78751767/) [ghstack-poisoned] --- .ci/scripts/test_llama_lora.sh | 95 ++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 .ci/scripts/test_llama_lora.sh diff --git a/.ci/scripts/test_llama_lora.sh b/.ci/scripts/test_llama_lora.sh new file mode 100644 index 00000000000..fa18e5f6ad3 --- /dev/null +++ b/.ci/scripts/test_llama_lora.sh @@ -0,0 +1,95 @@ +#!/bin/bash +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + +set -exu +# shellcheck source=/dev/null +source "$(dirname "${BASH_SOURCE[0]}")/utils.sh" + +cmake_install_executorch_libraries() { + echo "Installing libexecutorch.a, libextension_module.so, libportable_ops_lib.a" + rm -rf cmake-out + retry cmake --preset llm \ + -DCMAKE_INSTALL_PREFIX=cmake-out \ + -DCMAKE_BUILD_TYPE=Release + cmake --build cmake-out -j9 --target install --config Release +} + +cmake_build_llama_runner() { + echo "Building llama runner" + pushd extension/llm/tokenizers + echo "Updating tokenizers submodule" + git submodule update --init + popd + dir="examples/models/llama" + retry cmake \ + -DBUILD_TESTING=OFF \ + -DCMAKE_INSTALL_PREFIX=cmake-out \ + -DCMAKE_BUILD_TYPE=Release \ + -Bcmake-out/${dir} \ + ${dir} + cmake --build cmake-out/${dir} -j9 --config Release +} + +cleanup_files() { + echo "Deleting downloaded and generated files" + rm -rf "${DOWNLOADED_PATH}/" + rm result.txt +} + +# Download model artifacts from HF Hub. +# Hosting in personal repo for now. +HF_MODEL_REPO="lucylq/llama3_1B_lora" +DOWNLOADED_PATH=$( + bash "$(dirname "${BASH_SOURCE[0]}")/download_hf_hub.sh" \ + --model_id "${HF_MODEL_REPO}" \ + --files "adapter_config.json" "adapter_model.pt" "consolidated.00.pth" "params.json" "tokenizer.model" +) + +# Export model. +$PYTHON_EXECUTABLE -m extension.llm.export.export_llm \ + base.checkpoint="${DOWNLOADED_PATH}/consolidated.00.pth" \ + base.params="${DOWNLOADED_PATH}/params.json" \ + base.adapter_checkpoint="${DOWNLOADED_PATH}/adapter_model.pt" \ + base.adapter_config="${DOWNLOADED_PATH}/adapter_config.json" \ + base.tokenizer_path="${DOWNLOADED_PATH}/tokenizer.model" \ + model.use_kv_cache=true \ + model.use_sdpa_with_kv_cache=true \ + model.dtype_override="fp32" \ + backend.xnnpack.enabled=true \ + backend.xnnpack.extended_ops=true \ + export.output_name="llama3_2_1B_lora.pte" + +# Build llama runner. +cmake_install_executorch_libraries +cmake_build_llama_runner + +# Run llama runner +RUNTIME_ARGS="--model_path=${EXPORTED_MODEL_NAME} --tokenizer_path=${DOWNLOADED_PATH}/tokenizer.model --prompt='What happens if you eat watermelon seeds?' --temperature=0 --seq_len=10 --warmup=1" + +NOW=$(date +"%H:%M:%S") +echo "Starting to run llama runner at ${NOW}" +# shellcheck source=/dev/null +cmake-out/examples/models/llama/llama_main ${RUNTIME_ARGS} > result.txt +NOW=$(date +"%H:%M:%S") +echo "Finished at ${NOW}" + +RESULT=$(cat result.txt) +EXPECTED_PREFIX="What happens if you eat watermelon seeds? Eating watermelon seeds can be a bit tricky," + +if [[ "${RESULT}" == "${EXPECTED_PREFIX}"* ]]; then + echo "Expected result prefix: ${EXPECTED_PREFIX}" + echo "Actual result: ${RESULT}" + echo "Success" + cleanup_files +else + echo "Expected result prefix: ${EXPECTED_PREFIX}" + echo "Actual result: ${RESULT}" + echo "Failure; results not the same" + + cleanup_files + exit 1 +fi