forked from pytorch/ao
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for tiktoken and refactored runner structure (pytorch#435)
* Add support for tiktoken and refactored runner structure Summary: Unified runner and move runner-et/CMakeLists.txt to runner/et.cmake and runner-aoti/CMakeLists.txt to runner/aoti.cmake. Added a root level CMakeLists.txt to build a tokenizer library and link to both targets separately. In CLI we need to specify the target to run: ``` cmake --build ./cmake-out --target et_run/aoti_run ``` Test Plan: Reviewers: Subscribers: Tasks: Tags: * Fix CI Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: * Fix more CI Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: * Further fix CI Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: * Lint` Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: * Update build_android.sh Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: * Rebase Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: * Fix cmake commands in CI job Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags:
- Loading branch information
1 parent
0b4b56a
commit de9c414
Showing
21 changed files
with
788 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[submodule "tokenizer/third-party/abseil-cpp"] | ||
path = tokenizer/third-party/abseil-cpp | ||
url = https://github.com/abseil/abseil-cpp.git | ||
[submodule "tokenizer/third-party/re2"] | ||
path = tokenizer/third-party/re2 | ||
url = https://github.com/google/re2.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
cmake_minimum_required(VERSION 3.24) | ||
set(CMAKE_CXX_STANDARD 17) | ||
IF(DEFINED ENV{TORCHCHAT_ROOT}) | ||
set(TORCHCHAT_ROOT $ENV{TORCHCHAT_ROOT}) | ||
ELSE() | ||
set(TORCHCHAT_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..) | ||
ENDIF() | ||
|
||
project(Torchchat) | ||
|
||
# include tokenizer | ||
add_subdirectory(tokenizer) | ||
|
||
# include et_run executable | ||
include(runner/et.cmake) | ||
if(TARGET et_run) | ||
target_link_libraries(et_run PUBLIC tokenizer) | ||
endif() | ||
|
||
# include aoti_run executable | ||
include(runner/aoti.cmake) | ||
if(TARGET aoti_run) | ||
target_link_libraries(aoti_run tokenizer) | ||
endif() |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
cmake_minimum_required(VERSION 3.24) | ||
set(CMAKE_CXX_STANDARD 17) | ||
IF(DEFINED ENV{TORCHCHAT_ROOT}) | ||
set(TORCHCHAT_ROOT $ENV{TORCHCHAT_ROOT}) | ||
ELSE() | ||
set(TORCHCHAT_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..) | ||
ENDIF() | ||
|
||
find_package(CUDA) | ||
|
||
find_package(Torch) | ||
if(Torch_FOUND) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g ${TORCH_CXX_FLAGS} -fpermissive") | ||
|
||
add_executable(aoti_run runner/run.cpp) | ||
|
||
target_compile_options(aoti_run PUBLIC -D__AOTI_MODEL__) | ||
target_include_directories(aoti_run PRIVATE ${TORCHCHAT_ROOT}/runner) | ||
target_link_libraries(aoti_run "${TORCH_LIBRARIES}" m) | ||
set_property(TARGET aoti_run PROPERTY CXX_STANDARD 17) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
cmake_minimum_required(VERSION 3.24) | ||
set(CMAKE_CXX_STANDARD 17) | ||
|
||
IF(DEFINED ENV{ET_BUILD_DIR}) | ||
set(ET_BUILD_DIR $ENV{ET_BUILD_DIR}) | ||
ELSE() | ||
set(ET_BUILD_DIR "et-build") | ||
ENDIF() | ||
|
||
MESSAGE(STATUS "Using ET BUILD DIR: --[${ET_BUILD_DIR}]--") | ||
|
||
IF(DEFINED ENV{CMAKE_OUT_DIR}) | ||
set(CMAKE_OUT_DIR $ENV{CMAKE_OUT_DIR}) | ||
ELSE() | ||
set(CMAKE_OUT_DIR "cmake-out") | ||
ENDIF() | ||
|
||
MESSAGE(STATUS "Using ET BUILD DIR: --[${ET_BUILD_DIR}]--") | ||
|
||
IF(DEFINED ENV{TORCHCHAT_ROOT}) | ||
set(TORCHCHAT_ROOT $ENV{TORCHCHAT_ROOT}) | ||
ELSE() | ||
set(TORCHCHAT_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..) | ||
ENDIF() | ||
|
||
project(Torchchat) | ||
|
||
include(CMakePrintHelpers) | ||
include(runner/Utils.cmake) | ||
|
||
cmake_print_variables(TORCHCHAT_ROOT) | ||
|
||
MESSAGE(STATUS "Looking for excutorch in ${TORCHCHAT_ROOT}/${ET_BUILD_DIR}/install/lib/cmake/ExecuTorch") | ||
set(executorch_DIR ${TORCHCHAT_ROOT}/${ET_BUILD_DIR}/install/lib/cmake/ExecuTorch) | ||
find_package(executorch CONFIG PATHS ${executorch_DIR}) | ||
if(executorch_FOUND) | ||
set(_common_include_directories ${TORCHCHAT_ROOT}/${ET_BUILD_DIR}/src) | ||
|
||
cmake_print_variables(_common_include_directories) | ||
|
||
target_include_directories(executorch INTERFACE ${_common_include_directories}) # Ideally ExecuTorch installation process would do this | ||
add_executable(et_run runner/run.cpp) | ||
|
||
target_compile_options(et_run PUBLIC -D__ET__MODEL -D_GLIBCXX_USE_CXX11_ABI=1) | ||
|
||
# Link ET runtime + extensions | ||
target_link_libraries( | ||
et_run PRIVATE | ||
executorch | ||
extension_module | ||
${TORCHCHAT_ROOT}/${ET_BUILD_DIR}/src/executorch/${CMAKE_OUT_DIR}/extension/data_loader/libextension_data_loader.a # This one does not get installed by ExecuTorch | ||
optimized_kernels | ||
quantized_kernels | ||
portable_kernels | ||
cpublas | ||
eigen_blas | ||
# The libraries below need to be whole-archived linked | ||
optimized_native_cpu_ops_lib | ||
quantized_ops_lib | ||
xnnpack_backend | ||
XNNPACK | ||
pthreadpool | ||
cpuinfo | ||
) | ||
target_link_options_shared_lib(optimized_native_cpu_ops_lib) | ||
target_link_options_shared_lib(quantized_ops_lib) | ||
target_link_options_shared_lib(xnnpack_backend) | ||
# Not clear why linking executorch as whole-archive outside android/apple is leading | ||
# to double registration. Most likely because of linkage issues. | ||
# Will figure this out later. Until then use this. | ||
if(ANDROID OR APPLE) | ||
target_link_options_shared_lib(executorch) | ||
endif() | ||
|
||
target_link_libraries(et_run PRIVATE | ||
"$<LINK_LIBRARY:WHOLE_ARCHIVE,${TORCHCHAT_ROOT}/${ET_BUILD_DIR}/src/executorch/${CMAKE_OUT_DIR}/examples/models/llama2/custom_ops/libcustom_ops.a>") | ||
|
||
# This one is needed for cpuinfo where it uses android specific log lib | ||
if(ANDROID) | ||
target_link_libraries(et_run PRIVATE log) | ||
endif() | ||
|
||
# Adding target_link_options_shared_lib as commented out below leads to this: | ||
# | ||
# CMake Error at Utils.cmake:22 (target_link_options): | ||
# Cannot specify link options for target | ||
# "/Users/scroy/etorch/torchchat/et-build/src/executorch/${CMAKE_OUT_DIR}/examples/models/llama2/custom_ops/libcustom_ops_lib.a" | ||
# which is not built by this project. | ||
# Call Stack (most recent call first): | ||
# Utils.cmake:30 (macos_kernel_link_options) | ||
# CMakeLists.txt:41 (target_link_options_shared_lib) | ||
# | ||
#target_link_options_shared_lib("${TORCHCHAT_ROOT}/et-build/src/executorch/${CMAKE_OUT_DIR}/examples/models/llama2/custom_ops/libcustom_ops_lib.a") # This one does not get installed by ExecuTorch | ||
|
||
# This works on mac, but appears to run into issues on linux | ||
# It is needed to solve: | ||
# E 00:00:00.055965 executorch:method.cpp:536] Missing operator: [8] llama::sdpa_with_kv_cache.out | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.