Skip to content

Commit f71a8b9

Browse files
metascroymalfet
authored andcommitted
bring back runner-et test (#266)
* bring back runner-et test * mac * return state to before for sanity check * change to using Util functions for x-platform support. Add mac/linux runners * mac
1 parent cc0eba3 commit f71a8b9

File tree

4 files changed

+101
-8
lines changed

4 files changed

+101
-8
lines changed

.github/workflows/pull.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,3 +679,54 @@ jobs:
679679
680680
echo "tests complete"
681681
echo "******************************************"
682+
runner-et:
683+
strategy:
684+
matrix:
685+
runner: [macos-14-xlarge]
686+
runs-on: ${{matrix.runner}}
687+
steps:
688+
- name: Checkout repo
689+
uses: actions/checkout@v2
690+
- name: Setup Python
691+
uses: actions/setup-python@v2
692+
with:
693+
python-version: 3.11
694+
- name: Print machine info
695+
run: |
696+
uname -a
697+
if [ $(uname -s) == Darwin ]; then
698+
sysctl machdep.cpu.brand_string
699+
sysctl machdep.cpu.core_count
700+
fi
701+
- name: Install requirements
702+
run: |
703+
echo "Intalling pip packages"
704+
pip install -r requirements.txt
705+
706+
export TORCHCHAT_ROOT=${PWD}
707+
export ENABLE_ET_PYBIND=false
708+
./scripts/install_et.sh $ENABLE_ET_PYBIND
709+
cmake -S ./runner-et -B et-build/cmake-out -G Ninja
710+
cmake --build ./et-build/cmake-out
711+
- name: Download checkpoints
712+
run: |
713+
mkdir -p checkpoints/stories15M
714+
pushd checkpoints/stories15M
715+
wget https://huggingface.co/karpathy/tinyllamas/resolve/main/stories15M.pt
716+
wget https://github.com/karpathy/llama2.c/raw/master/tokenizer.model
717+
wget https://github.com/karpathy/llama2.c/raw/master/tokenizer.bin
718+
popd
719+
- name: Run inference
720+
run: |
721+
export MODEL_DIR=${PWD}/checkpoints/stories15M
722+
export PROMPT="Once upon a time in a land far away"
723+
724+
python torchchat.py generate --checkpoint-path ${MODEL_DIR}/stories15M.pt --temperature 0 --prompt "${PROMPT}" > ${PWD}/output_eager
725+
cat ${PWD}/output_eager
726+
727+
python torchchat.py export --checkpoint-path ${MODEL_DIR}/stories15M.pt --output-pte-path ${PWD}/stories15M.pte
728+
729+
./et-build/cmake-out/runner_et ${PWD}/stories15M.pte -z ${MODEL_DIR}/tokenizer.bin -i "${PROMPT}" > ${PWD}/output_et
730+
cat ${PWD}/output_et
731+
732+
echo "Tests complete."

requirements.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@ numpy
2121
gguf
2222
lm-eval
2323
blobfile
24+
25+
# Build tools
26+
wheel
27+
cmake
28+
ninja
29+
zstd

runner-et/CMakeLists.txt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set(CMAKE_CXX_STANDARD 17)
44
project(Torchchat)
55

66
include(CMakePrintHelpers)
7+
include(Utils.cmake)
78
set(TORCHCHAT_ROOT $ENV{TORCHCHAT_ROOT})
89
cmake_print_variables(TORCHCHAT_ROOT)
910

@@ -24,13 +25,15 @@ target_link_libraries(
2425
portable_kernels
2526
cpublas
2627
eigen_blas
28+
# The libraries below need to be whole-archived linked
2729
optimized_native_cpu_ops_lib
30+
xnnpack_backend
31+
XNNPACK
32+
pthreadpool
33+
cpuinfo
2834
)
29-
target_link_options(
30-
optimized_native_cpu_ops_lib INTERFACE "SHELL:LINKER:--whole-archive \
31-
$<TARGET_FILE:optimized_native_cpu_ops_lib> \
32-
LINKER:--no-whole-archive")
33-
target_link_libraries(runner_et PRIVATE "$<LINK_LIBRARY:WHOLE_ARCHIVE,xnnpack_backend">)
34-
target_link_libraries(runner_et PRIVATE "$<LINK_LIBRARY:WHOLE_ARCHIVE,XNNPACK">)
35-
target_link_libraries(runner_et PRIVATE "$<LINK_LIBRARY:WHOLE_ARCHIVE,pthreadpool">)
36-
target_link_libraries(runner_et PRIVATE "$<LINK_LIBRARY:WHOLE_ARCHIVE,cpuinfo">)
35+
target_link_options_shared_lib(optimized_native_cpu_ops_lib)
36+
target_link_options_shared_lib(xnnpack_backend)
37+
target_link_options_shared_lib(XNNPACK)
38+
target_link_options_shared_lib(pthreadpool)
39+
target_link_options_shared_lib(cpuinfo)

runner-et/Utils.cmake

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# This is the funtion to use -Wl, --whole-archive to link static library NB:
8+
# target_link_options is broken for this case, it only append the interface link
9+
# options of the first library.
10+
function(kernel_link_options target_name)
11+
# target_link_options(${target_name} INTERFACE
12+
# "$<LINK_LIBRARY:WHOLE_ARCHIVE,target_name>")
13+
target_link_options(
14+
${target_name} INTERFACE "SHELL:LINKER:--whole-archive \
15+
$<TARGET_FILE:${target_name}> \
16+
LINKER:--no-whole-archive")
17+
endfunction()
18+
19+
# Same as kernel_link_options but it's for MacOS linker
20+
function(macos_kernel_link_options target_name)
21+
target_link_options(${target_name} INTERFACE
22+
"SHELL:LINKER:-force_load,$<TARGET_FILE:${target_name}>")
23+
endfunction()
24+
25+
# Ensure that the load-time constructor functions run. By default, the linker
26+
# would remove them since there are no other references to them.
27+
function(target_link_options_shared_lib target_name)
28+
if(APPLE)
29+
macos_kernel_link_options(${target_name})
30+
else()
31+
kernel_link_options(${target_name})
32+
endif()
33+
endfunction()

0 commit comments

Comments
 (0)