@@ -351,3 +351,93 @@ jobs:
351
351
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash .ci/scripts/test_model.sh "${MODEL_NAME}" "${BUILD_TOOL}" "${BACKEND}"
352
352
echo "::endgroup::"
353
353
done
354
+
355
+ test-huggingface-transformers :
356
+ name : test-huggingface-transformers
357
+ uses : pytorch/test-infra/.github/workflows/linux_job.yml@main
358
+ secrets : inherit
359
+ strategy :
360
+ matrix :
361
+ hf_model_repo : [google/gemma-2b]
362
+ fail-fast : false
363
+ with :
364
+ secrets-env : EXECUTORCH_HF_TOKEN
365
+ runner : linux.12xlarge
366
+ docker-image : executorch-ubuntu-22.04-clang12
367
+ submodules : ' true'
368
+ ref : ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
369
+ timeout : 90
370
+ script : |
371
+ echo "::group::Set up ExecuTorch"
372
+ # The generic Linux job chooses to use base env, not the one setup by the image
373
+ CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
374
+ conda activate "${CONDA_ENV}"
375
+ PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh cmake
376
+
377
+ echo "Installing libexecutorch.a, libextension_module.so, libportable_ops_lib.a"
378
+ rm -rf cmake-out
379
+ cmake \
380
+ -DCMAKE_INSTALL_PREFIX=cmake-out \
381
+ -DCMAKE_BUILD_TYPE=Release \
382
+ -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
383
+ -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
384
+ -DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
385
+ -DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
386
+ -DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
387
+ -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
388
+ -DEXECUTORCH_BUILD_XNNPACK=ON \
389
+ -DPYTHON_EXECUTABLE=python \
390
+ -Bcmake-out .
391
+ cmake --build cmake-out -j9 --target install --config Release
392
+
393
+ echo "Build llama runner"
394
+ dir="examples/models/llama2"
395
+ cmake \
396
+ -DCMAKE_INSTALL_PREFIX=cmake-out \
397
+ -DCMAKE_BUILD_TYPE=Release \
398
+ -DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
399
+ -DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
400
+ -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
401
+ -DEXECUTORCH_BUILD_XNNPACK=ON \
402
+ -DPYTHON_EXECUTABLE=python \
403
+ -Bcmake-out/${dir} \
404
+ ${dir}
405
+ cmake --build cmake-out/${dir} -j9 --config Release
406
+ echo "::endgroup::"
407
+
408
+ echo "::group::Set up HuggingFace Dependencies"
409
+ pip install -U "huggingface_hub[cli]"
410
+ huggingface-cli login --token $SECRET_EXECUTORCH_HF_TOKEN
411
+ pip install accelerate sentencepiece
412
+ # TODO(guangyang): Switch to use released transformers library after all required patches are included
413
+ pip install "git+https://github.com/huggingface/transformers.git@6cc4dfe3f1e8d421c6d6351388e06e9b123cbfe1"
414
+ pip list
415
+ echo "::endgroup::"
416
+
417
+ echo "::group::Export to ExecuTorch"
418
+ TOKENIZER_FILE=tokenizer.model
419
+ TOKENIZER_BIN_FILE=tokenizer.bin
420
+ ET_MODEL_NAME=et_model
421
+ # Fetch the file using a Python one-liner
422
+ DOWNLOADED_TOKENIZER_FILE_PATH=$(python -c "
423
+ from huggingface_hub import hf_hub_download
424
+ # Download the file from the Hugging Face Hub
425
+ downloaded_path = hf_hub_download(
426
+ repo_id='${{ matrix.hf_model_repo }}',
427
+ filename='${TOKENIZER_FILE}'
428
+ )
429
+ print(downloaded_path)
430
+ ")
431
+ if [ -f "$DOWNLOADED_TOKENIZER_FILE_PATH" ]; then
432
+ echo "${TOKENIZER_FILE} downloaded successfully at: $DOWNLOADED_TOKENIZER_FILE_PATH"
433
+ python -m extension.llm.tokenizer.tokenizer -t $DOWNLOADED_TOKENIZER_FILE_PATH -o ./${TOKENIZER_BIN_FILE}
434
+ ls ./tokenizer.bin
435
+ else
436
+ echo "Failed to download ${TOKENIZER_FILE} from ${{ matrix.hf_model_repo }}."
437
+ exit 1
438
+ fi
439
+
440
+ python -m extension.export_util.export_hf_model -hfm=${{ matrix.hf_model_repo }} -o ${ET_MODEL_NAME}
441
+
442
+ cmake-out/examples/models/llama2/llama_main --model_path=${ET_MODEL_NAME}.pte --tokenizer_path=${TOKENIZER_BIN_FILE} --prompt="My name is"
443
+ echo "::endgroup::"
0 commit comments