Skip to content

Commit

Permalink
[CINN] Use Flag to open cinn in llama (PaddlePaddle#64074)
Browse files Browse the repository at this point in the history
* update

* update

* update
  • Loading branch information
chen2016013 authored May 9, 2024
1 parent 9750105 commit 3cae93f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 26 deletions.
5 changes: 5 additions & 0 deletions python/paddle/base/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import numpy as np

from paddle import pir
from paddle.base.framework import in_cinn_mode
from paddle.base.libpaddle.pir import apply_cinn_pass

from ..pir import (
Program as PirProgram,
Expand Down Expand Up @@ -1072,6 +1074,9 @@ def _get_program_and_executor(self, cached_data):
pir_program, param_mapping, new_program._grad_var_to_var
)

if in_cinn_mode():
apply_cinn_pass(pir_program)

type_to_program = {"default": pir_program}

else:
Expand Down
31 changes: 18 additions & 13 deletions test/cpp/inference/test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,24 @@ function(inference_download_and_uncompress_without_verify INSTALL_DIR URL
string(REGEX MATCH "[^/\\]+$" DOWNLOAD_NAME ${FILENAME})
set(EXTERNAL_PROJECT_NAME "extern_download_${FILENAME_EX}")
set(UNPACK_DIR "${INSTALL_DIR}/src/${EXTERNAL_PROJECT_NAME}")
ExternalProject_Add(
${EXTERNAL_PROJECT_NAME}
${EXTERNAL_PROJECT_LOG_ARGS}
PREFIX ${INSTALL_DIR}
URL ${URL}/${FILENAME}
DOWNLOAD_DIR ${INSTALL_DIR}
DOWNLOAD_NO_EXTRACT 1
DOWNLOAD_NO_PROGRESS 1
CONFIGURE_COMMAND ""
BUILD_COMMAND ${CMAKE_COMMAND} -E chdir ${INSTALL_DIR} ${CMAKE_COMMAND} -E
tar xzf ${DOWNLOAD_NAME}
UPDATE_COMMAND ""
INSTALL_COMMAND "")

get_property(TARGET_EXIST GLOBAL PROPERTY ${EXTERNAL_PROJECT_NAME})
if(NOT "${TARGET_EXIST}" STREQUAL EXIST)
ExternalProject_Add(
${EXTERNAL_PROJECT_NAME}
${EXTERNAL_PROJECT_LOG_ARGS}
PREFIX ${INSTALL_DIR}
URL ${URL}/${FILENAME}
DOWNLOAD_DIR ${INSTALL_DIR}
DOWNLOAD_NO_EXTRACT 1
DOWNLOAD_NO_PROGRESS 1
CONFIGURE_COMMAND ""
BUILD_COMMAND ${CMAKE_COMMAND} -E chdir ${INSTALL_DIR} ${CMAKE_COMMAND} -E
tar xzf ${DOWNLOAD_NAME}
UPDATE_COMMAND ""
INSTALL_COMMAND "")
set_property(GLOBAL PROPERTY ${EXTERNAL_PROJECT_NAME} "EXIST")
endif()
endfunction()

function(inference_base_test_build TARGET)
Expand Down
1 change: 1 addition & 0 deletions test/deprecated/cpp/inference/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ if(WITH_TESTING AND WITH_INFERENCE_API_TEST)

# resnet50
set(RESNET50_MODEL_DIR "${INFERENCE_DEMO_INSTALL_DIR}/resnet50")
download_data_without_verify(${RESNET50_MODEL_DIR} "resnet50_model.tar.gz")
inference_analysis_api_test_with_fake_data_run(
test_analyzer_resnet50 ${IMG_CLASS_TEST_APP} ${RESNET50_MODEL_DIR} true)
if(WIN32)
Expand Down
35 changes: 22 additions & 13 deletions test/deprecated/cpp/inference/test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,23 @@ function(inference_download_and_uncompress_without_verify INSTALL_DIR URL
string(REGEX MATCH "[^/\\]+$" DOWNLOAD_NAME ${FILENAME})
set(EXTERNAL_PROJECT_NAME "extern_download_${FILENAME_EX}")
set(UNPACK_DIR "${INSTALL_DIR}/src/${EXTERNAL_PROJECT_NAME}")
ExternalProject_Add(
${EXTERNAL_PROJECT_NAME}
${EXTERNAL_PROJECT_LOG_ARGS}
PREFIX ${INSTALL_DIR}
URL ${URL}/${FILENAME}
DOWNLOAD_DIR ${INSTALL_DIR}
DOWNLOAD_NO_EXTRACT 1
DOWNLOAD_NO_PROGRESS 1
CONFIGURE_COMMAND ""
BUILD_COMMAND ${CMAKE_COMMAND} -E chdir ${INSTALL_DIR} ${CMAKE_COMMAND} -E
tar xzf ${DOWNLOAD_NAME}
UPDATE_COMMAND ""
INSTALL_COMMAND "")
get_property(TARGET_EXIST GLOBAL PROPERTY ${EXTERNAL_PROJECT_NAME})
if(NOT "${TARGET_EXIST}" STREQUAL EXIST)
ExternalProject_Add(
${EXTERNAL_PROJECT_NAME}
${EXTERNAL_PROJECT_LOG_ARGS}
PREFIX ${INSTALL_DIR}
URL ${URL}/${FILENAME}
DOWNLOAD_DIR ${INSTALL_DIR}
DOWNLOAD_NO_EXTRACT 1
DOWNLOAD_NO_PROGRESS 1
CONFIGURE_COMMAND ""
BUILD_COMMAND ${CMAKE_COMMAND} -E chdir ${INSTALL_DIR} ${CMAKE_COMMAND} -E
tar xzf ${DOWNLOAD_NAME}
UPDATE_COMMAND ""
INSTALL_COMMAND "")
set_property(GLOBAL PROPERTY ${EXTERNAL_PROJECT_NAME} "EXIST")
endif()
endfunction()

function(inference_base_test_build TARGET)
Expand Down Expand Up @@ -164,6 +168,11 @@ endfunction()
set(WORD2VEC_INSTALL_DIR "${INFERENCE_DEMO_INSTALL_DIR}/word2vec")
set(WORD2VEC_MODEL_DIR "${WORD2VEC_INSTALL_DIR}/word2vec.inference.model")

if(NOT EXISTS ${WORD2VEC_INSTALL_DIR}/word2vec.inference.model.tar.gz)
inference_download_and_uncompress_without_verify(
${WORD2VEC_INSTALL_DIR} ${INFERENCE_URL} "word2vec.inference.model.tar.gz")
endif()

set(IMG_CLS_RESNET_INSTALL_DIR
"${INFERENCE_DEMO_INSTALL_DIR}/image_classification_resnet")
set(IMG_CLS_RESNET_MODEL_DIR
Expand Down

0 comments on commit 3cae93f

Please sign in to comment.