Skip to content

Commit 4689c91

Browse files
authored
Swap --gc-sections to -dead_strip for clang compilation
Differential Revision: D61799233 Pull Request resolved: #4888
1 parent 2c7b7e8 commit 4689c91

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

.ci/scripts/test_llava.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@
88
set -exu
99
# shellcheck source=/dev/null
1010

11+
BUILD_TYPE=${1:-Debug}
12+
13+
echo "Building with BUILD_TYPE: $BUILD_TYPE"
14+
1115
if [[ -z "${PYTHON_EXECUTABLE:-}" ]]; then
1216
PYTHON_EXECUTABLE=python3
1317
fi
1418

1519
cmake_install_executorch_libraries() {
1620
cmake \
1721
-DCMAKE_INSTALL_PREFIX=cmake-out \
18-
-DCMAKE_BUILD_TYPE=Debug \
22+
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
1923
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
2024
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
2125
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
@@ -27,7 +31,7 @@ cmake_install_executorch_libraries() {
2731
-Bcmake-out .
2832

2933

30-
cmake --build cmake-out -j9 --target install --config Debug
34+
cmake --build cmake-out -j9 --target install --config ${BUILD_TYPE}
3135
}
3236

3337
cmake_build_llava_runner() {
@@ -36,7 +40,7 @@ cmake_build_llava_runner() {
3640

3741
cmake \
3842
-DCMAKE_INSTALL_PREFIX=cmake-out \
39-
-DCMAKE_BUILD_TYPE=Debug \
43+
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
4044
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
4145
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
4246
-DEXECUTORCH_BUILD_XNNPACK=ON \
@@ -45,7 +49,7 @@ cmake_build_llava_runner() {
4549
${dir}
4650

4751

48-
cmake --build cmake-out/${dir} -j9 --config Debug
52+
cmake --build cmake-out/${dir} -j9 --config ${BUILD_TYPE}
4953
}
5054

5155
# only export the one without custom op for now since it's

.github/workflows/trunk.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,34 @@ jobs:
270270
# Test llama2
271271
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash .ci/scripts/test_llama.sh stories110M "${BUILD_TOOL}" "${DTYPE}" "${MODE}"
272272
273+
test-llava-runner-macos:
274+
name: test-llava-runner-macos
275+
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
276+
strategy:
277+
fail-fast: false
278+
with:
279+
runner: macos-m1-stable
280+
python-version: '3.11'
281+
submodules: 'true'
282+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
283+
timeout: 900
284+
script: |
285+
# The generic Linux job chooses to use base env, not the one setup by the image
286+
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
287+
conda activate "${CONDA_ENV}"
288+
289+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-macos.sh "cmake"
290+
291+
# install Llava requirements
292+
bash examples/models/llama2/install_requirements.sh
293+
bash examples/models/llava/install_requirements.sh
294+
295+
# run python unittest
296+
python -m unittest examples.models.llava.test.test_llava
297+
298+
# run e2e (export, tokenizer and runner)
299+
PYTHON_EXECUTABLE=python bash .ci/scripts/test_llava.sh Release
300+
273301
test-qnn-model:
274302
name: test-qnn-model
275303
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main

CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,8 +786,12 @@ if(EXECUTORCH_BUILD_EXECUTOR_RUNNER)
786786
endif()
787787

788788
add_executable(executor_runner ${_executor_runner__srcs})
789-
if(CMAKE_BUILD_TYPE STREQUAL "Release" AND NOT APPLE)
790-
target_link_options(executor_runner PRIVATE "LINKER:--gc-sections")
789+
if(CMAKE_BUILD_TYPE STREQUAL "Release")
790+
if(APPLE)
791+
target_link_options(executor_runner PRIVATE "LINKER:-dead_strip")
792+
else()
793+
target_link_options(executor_runner PRIVATE "LINKER:--gc-sections")
794+
endif()
791795
endif()
792796
target_link_libraries(executor_runner ${_executor_runner_libs})
793797
target_compile_options(executor_runner PUBLIC ${_common_compile_options})

examples/models/llava/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,11 @@ endif()
203203

204204
add_executable(llava_main ${_srcs})
205205
if(CMAKE_BUILD_TYPE STREQUAL "Release")
206-
target_link_options(llava_main PRIVATE "LINKER:--gc-sections,-s")
206+
if(APPLE)
207+
target_link_options(llava_main PRIVATE "LINKER:-dead_strip,-s")
208+
else()
209+
target_link_options(llava_main PRIVATE "LINKER:--gc-sections,-s")
210+
endif()
207211
endif()
208212

209213
target_include_directories(llava_main PUBLIC ${_common_include_directories})

0 commit comments

Comments
 (0)